2015-07-08 03:34:58 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-05-23 21:01:33 -04:00
|
|
|
# The PHP version to use
|
|
|
|
PHP_BINARY=${PHP_BINARY:=/usr/bin/php}
|
|
|
|
|
2016-12-14 23:03:42 -05:00
|
|
|
# Dependencies
|
2020-02-21 00:06:49 -05:00
|
|
|
deps=('composer' 'grep' 'npm' 'php' 'sed')
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2016-12-14 23:03:42 -05:00
|
|
|
# Default settings
|
2020-01-07 20:59:13 -05:00
|
|
|
no_db=0
|
2016-12-14 23:03:42 -05:00
|
|
|
|
|
|
|
# Initialize variables
|
2016-10-12 21:24:14 -04:00
|
|
|
artisan_down=0
|
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
# Colour scheme
|
|
|
|
[[ -t 1 ]] && {
|
|
|
|
c_d=$'\e[1;30m' # DARK GREY
|
|
|
|
c_w=$'\e[1;37m' # WHITE
|
|
|
|
c_b=$'\e[1;34m' # BLUE
|
|
|
|
c_g=$'\e[1;32m' # GREEN
|
|
|
|
c_m=$'\e[1;35m' # MAGENTA
|
|
|
|
c_r=$'\e[1;31m' # RED
|
|
|
|
c_t=$'\e[1;36m' # TEAL
|
|
|
|
c_y=$'\e[1;33m' # YELLOW
|
|
|
|
c_c=$'\e[0m' # CLEAR
|
|
|
|
}
|
|
|
|
|
|
|
|
# Display a formatted message
|
|
|
|
function msg {
|
|
|
|
printf '%s %s\n' "$c_b==>" "$c_w$1$c_c"
|
|
|
|
}
|
|
|
|
|
|
|
|
function error {
|
|
|
|
printf '%s\n' "${c_r}ERROR${c_w}: $1$c_c" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check for missing dependencies
|
|
|
|
declare -a missing_deps=()
|
2018-01-17 16:30:57 -05:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
for dep in "${deps[@]}"; do
|
|
|
|
type -P "$dep" >/dev/null \
|
2018-04-09 23:04:09 -04:00
|
|
|
|| missing_deps=( "${missing_deps[@]}" "$dep" )
|
2015-07-08 03:34:58 -04:00
|
|
|
done
|
2018-01-17 16:30:57 -05:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
[[ -n "${missing_deps[*]}" ]] && {
|
|
|
|
error "${c_w}missing dependencies ($(
|
|
|
|
for (( x=0; x < ${#missing_deps[@]}; x++ )); do
|
|
|
|
printf '%s' "$c_m${missing_deps[$x]}$c_c"
|
|
|
|
(( (( x + 1 )) < ${#missing_deps[@]} )) && printf '%s' ', '
|
|
|
|
done
|
|
|
|
)$c_w)"
|
|
|
|
}
|
|
|
|
|
2018-01-17 16:30:57 -05:00
|
|
|
# Exit with an error if the .env file does not exist
|
2019-11-15 14:21:23 -05:00
|
|
|
[[ -f '.env' ]] || error 'The .env file does not exist'
|
2018-01-17 16:30:57 -05:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
# Exit with an error on ctrl-c
|
|
|
|
trap 'error "script killed"' SIGINT SIGQUIT
|
|
|
|
|
2020-01-07 20:59:13 -05:00
|
|
|
# Check for the --no-db argument and set a flag that prevents database operations if present
|
|
|
|
[[ -n "$1" && "$1" = '--no-db' ]] && no_db=1
|
2016-10-12 21:24:14 -04:00
|
|
|
|
2020-01-07 20:59:13 -05:00
|
|
|
[[ -d vendor ]] && {
|
2016-03-03 22:18:17 -05:00
|
|
|
artisan_down=1
|
|
|
|
msg "Running: ${c_m}php artisan down"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan down
|
2016-03-03 22:18:17 -05:00
|
|
|
}
|
2015-10-20 23:05:43 -04:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
msg "Running: ${c_m}composer installl --no-dev"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY "$(type -P composer)" install --no-interaction --no-dev || error "${c_m}composer install --no-interaction --no-dev$c_w exited with an error status"
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2019-11-15 14:21:23 -05:00
|
|
|
while read -r; do
|
|
|
|
[[ "$REPLY" =~ ^APP_KEY=(.*)$ && -z "${BASH_REMATCH[1]}" ]] && {
|
|
|
|
msg 'Generating Encryption Key' 'php artisan key:generate'
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan key:generate
|
2020-01-07 20:59:13 -05:00
|
|
|
break
|
2019-11-15 14:21:23 -05:00
|
|
|
}
|
|
|
|
done < .env
|
2018-01-10 11:20:49 -05:00
|
|
|
|
2022-03-30 16:35:39 -04:00
|
|
|
msg "Running: ${c_m}php artisan route:clear"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan cache:clear
|
2022-03-30 16:35:39 -04:00
|
|
|
|
2017-01-26 20:07:54 -05:00
|
|
|
msg "Running: ${c_m}php artisan route:clear"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan route:clear
|
2017-01-26 20:07:54 -05:00
|
|
|
|
|
|
|
msg "Running: ${c_m}php artisan view:clear"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan view:clear
|
2017-01-26 20:07:54 -05:00
|
|
|
|
2020-01-07 20:59:13 -05:00
|
|
|
(( ! no_db )) && {
|
2018-08-13 19:28:56 -04:00
|
|
|
msg "Running: ${c_m}php artisan migrate --force"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan migrate --force || error "${c_m}php artisan migrate --force$c_w exited with an error status"
|
2016-10-12 21:24:14 -04:00
|
|
|
}
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2019-12-26 16:10:26 -05:00
|
|
|
[[ -d node_modules ]] && {
|
|
|
|
msg "Running: ${c_m}npm prune --production"
|
|
|
|
npm prune --production || error "${c_m}npm prune --production$c_w exited with an error status"
|
|
|
|
}
|
|
|
|
|
|
|
|
msg "Running: ${c_m}npm install --production"
|
|
|
|
npm install --production || error "${c_m}npm install --production$c_w exited with an error status"
|
2015-07-08 03:34:58 -04:00
|
|
|
|
|
|
|
msg "Running: ${c_m}gulp --production"
|
2022-02-23 14:12:44 -05:00
|
|
|
NODE_ENV=production "$(npm bin)/gulp" --production || error "${c_m}gulp --production$c_w exited with an error status"
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2020-04-24 23:47:30 -04:00
|
|
|
if (( artisan_down )); then
|
2016-03-03 22:18:17 -05:00
|
|
|
msg "Running: ${c_m}php artisan up"
|
2022-05-23 21:01:33 -04:00
|
|
|
$PHP_BINARY artisan up
|
2020-04-24 23:47:30 -04:00
|
|
|
fi
|