|
1 | | -#!/usr/bin/env sh |
| 1 | +#!/usr/bin/env bash |
2 | 2 |
|
3 | | -# Support bash to support `source` with fallback on $0 if this does not run with bash |
4 | | -# https://stackoverflow.com/a/35006505/6512 |
5 | | -selfArg="$BASH_SOURCE" |
6 | | -if [ -z "$selfArg" ]; then |
7 | | - selfArg="$0" |
| 3 | +UNAMEOUT="$(uname -s)" |
| 4 | + |
| 5 | +WHITE='\033[1;37m' |
| 6 | +NC='\033[0m' |
| 7 | + |
| 8 | +# Verify operating system is supported... |
| 9 | +case "${UNAMEOUT}" in |
| 10 | + Linux*) MACHINE=linux;; |
| 11 | + Darwin*) MACHINE=mac;; |
| 12 | + *) MACHINE="UNKNOWN" |
| 13 | +esac |
| 14 | + |
| 15 | +if [ "$MACHINE" == "UNKNOWN" ]; then |
| 16 | + echo "Unsupported operating system [$(uname -s)]. Evo Salo supports macOS, Linux, and Windows (WSL2)." >&2 |
| 17 | + |
| 18 | + exit 1 |
8 | 19 | fi |
9 | 20 |
|
10 | | -self=$(realpath $selfArg 2> /dev/null) |
11 | | -if [ -z "$self" ]; then |
12 | | - self="$selfArg" |
| 21 | +# Define environment variables... |
| 22 | +export APP_PORT=${APP_PORT:-80} |
| 23 | +export APP_SERVICE=${APP_SERVICE:-"evo.test"} |
| 24 | +export DB_PORT=${DB_PORT:-3306} |
| 25 | +export WWWUSER=${WWWUSER:-$UID} |
| 26 | +export WWWGROUP=${WWWGROUP:-$(id -g)} |
| 27 | + |
| 28 | +export SALO_SHARE_DASHBOARD=${SALO_SHARE_DASHBOARD:-4040} |
| 29 | +export SALO_SHARE_SERVER_HOST=${SALO_SHARE_SERVER_HOST:-"evo-salo.site"} |
| 30 | +export SALO_SHARE_SERVER_PORT=${SALO_SHARE_SERVER_PORT:-8080} |
| 31 | + |
| 32 | +# Ensure that Docker is running... |
| 33 | +if ! docker info > /dev/null 2>&1; then |
| 34 | + echo -e "${WHITE}Docker is not running.${NC}" >&2 |
| 35 | + |
| 36 | + exit 1 |
13 | 37 | fi |
14 | 38 |
|
15 | | -dir=$(cd "${self%[/\\]*}" > /dev/null; cd '../evolutioncms/salo2/bin' && pwd) |
| 39 | +# Determine if Salo is currently up... |
| 40 | +PSRESULT="$(docker-compose ps -q)" |
16 | 41 |
|
17 | | -if [ -d /proc/cygdrive ]; then |
18 | | - case $(which php) in |
19 | | - $(readlink -n /proc/cygdrive)/*) |
20 | | - # We are in Cygwin using Windows php, so the path must be translated |
21 | | - dir=$(cygpath -m "$dir"); |
22 | | - ;; |
23 | | - esac |
| 42 | +if docker-compose ps | grep $APP_SERVICE | grep 'Exit'; then |
| 43 | + echo -e "${WHITE}Shutting down old Salo processes...${NC}" >&2 |
| 44 | + |
| 45 | + docker-compose down > /dev/null 2>&1 |
| 46 | + |
| 47 | + EXEC="no" |
| 48 | +elif [ -n "$PSRESULT" ]; then |
| 49 | + EXEC="yes" |
| 50 | +else |
| 51 | + EXEC="no" |
24 | 52 | fi |
25 | 53 |
|
26 | | -export COMPOSER_RUNTIME_BIN_DIR="$(cd "${self%[/\\]*}" > /dev/null; pwd)" |
| 54 | +# Function that outputs Salo is not running... |
| 55 | +function salo_is_not_running { |
| 56 | + echo -e "${WHITE}Salo is not running.${NC}" >&2 |
| 57 | + echo "" >&2 |
| 58 | + echo -e "${WHITE}You may Salo using the following commands:${NC} './vendor/bin/salo up' or './vendor/bin/salo up -d'" >&2 |
| 59 | + |
| 60 | + exit 1 |
| 61 | +} |
27 | 62 |
|
28 | | -# If bash is sourcing this file, we have to source the target as well |
29 | | -bashSource="$BASH_SOURCE" |
30 | | -if [ -n "$bashSource" ]; then |
31 | | - if [ "$bashSource" != "$0" ]; then |
32 | | - source "${dir}/salo" "$@" |
33 | | - return |
| 63 | +if [ $# -gt 0 ]; then |
| 64 | + # Source the ".env" file so Laravel's environment variables are available... |
| 65 | + if [ -f ./.env ]; then |
| 66 | + source ./.env |
34 | 67 | fi |
35 | | -fi |
36 | 68 |
|
37 | | -"${dir}/salo" "$@" |
| 69 | + # Proxy PHP commands to the "php" binary on the application container... |
| 70 | + if [ "$1" == "php" ]; then |
| 71 | + shift 1 |
| 72 | + |
| 73 | + if [ "$EXEC" == "yes" ]; then |
| 74 | + docker-compose exec \ |
| 75 | + -u salo \ |
| 76 | + "$APP_SERVICE" \ |
| 77 | + php "$@" |
| 78 | + else |
| 79 | + salo_is_not_running |
| 80 | + fi |
| 81 | + |
| 82 | + # Proxy vendor binary commands on the application container... |
| 83 | + elif [ "$1" == "bin" ]; then |
| 84 | + shift 1 |
| 85 | + |
| 86 | + if [ "$EXEC" == "yes" ]; then |
| 87 | + docker-compose exec \ |
| 88 | + -u salo \ |
| 89 | + "$APP_SERVICE" \ |
| 90 | + ./vendor/bin/"$@" |
| 91 | + else |
| 92 | + salo_is_not_running |
| 93 | + fi |
| 94 | + |
| 95 | + # Proxy Composer commands to the "composer" binary on the application container... |
| 96 | + elif [ "$1" == "composer" ]; then |
| 97 | + shift 1 |
| 98 | + |
| 99 | + if [ "$EXEC" == "yes" ]; then |
| 100 | + docker-compose exec \ |
| 101 | + -u salo \ |
| 102 | + "$APP_SERVICE" \ |
| 103 | + composer "$@" |
| 104 | + else |
| 105 | + salo_is_not_running |
| 106 | + fi |
| 107 | + |
| 108 | + # Proxy Artisan commands to the "artisan" binary on the application container... |
| 109 | + elif [ "$1" == "artisan" ] || [ "$1" == "art" ]; then |
| 110 | + shift 1 |
| 111 | + |
| 112 | + if [ "$EXEC" == "yes" ]; then |
| 113 | + docker-compose exec \ |
| 114 | + -u salo \ |
| 115 | + "$APP_SERVICE" \ |
| 116 | + php core/artisan "$@" |
| 117 | + else |
| 118 | + salo_is_not_running |
| 119 | + fi |
| 120 | + |
| 121 | + # Proxy the "test" command to the "php artisan test" Artisan command... |
| 122 | + elif [ "$1" == "test" ]; then |
| 123 | + shift 1 |
| 124 | + |
| 125 | + if [ "$EXEC" == "yes" ]; then |
| 126 | + docker-compose exec \ |
| 127 | + -u salo \ |
| 128 | + "$APP_SERVICE" \ |
| 129 | + php core/artisan test "$@" |
| 130 | + else |
| 131 | + salo_is_not_running |
| 132 | + fi |
| 133 | + |
| 134 | + # Proxy the "dusk" command to the "php artisan dusk" Artisan command... |
| 135 | + elif [ "$1" == "dusk" ]; then |
| 136 | + shift 1 |
| 137 | + |
| 138 | + if [ "$EXEC" == "yes" ]; then |
| 139 | + docker-compose exec \ |
| 140 | + -u salo \ |
| 141 | + -e "APP_URL=http://evo.test" \ |
| 142 | + -e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \ |
| 143 | + "$APP_SERVICE" \ |
| 144 | + php core/artisan dusk "$@" |
| 145 | + else |
| 146 | + salo_is_not_running |
| 147 | + fi |
| 148 | + |
| 149 | + # Proxy the "dusk:fails" command to the "php artisan dusk:fails" Artisan command... |
| 150 | + elif [ "$1" == "dusk:fails" ]; then |
| 151 | + shift 1 |
| 152 | + |
| 153 | + if [ "$EXEC" == "yes" ]; then |
| 154 | + docker-compose exec \ |
| 155 | + -u salo \ |
| 156 | + -e "APP_URL=http://evo.test" \ |
| 157 | + -e "DUSK_DRIVER_URL=http://selenium:4444/wd/hub" \ |
| 158 | + "$APP_SERVICE" \ |
| 159 | + php core/artisan dusk:fails "$@" |
| 160 | + else |
| 161 | + salo_is_not_running |
| 162 | + fi |
| 163 | + |
| 164 | + # Initiate a Laravel Tinker session within the application container... |
| 165 | + elif [ "$1" == "tinker" ] ; then |
| 166 | + shift 1 |
| 167 | + |
| 168 | + if [ "$EXEC" == "yes" ]; then |
| 169 | + docker-compose exec \ |
| 170 | + -u salo \ |
| 171 | + "$APP_SERVICE" \ |
| 172 | + php core/artisan tinker |
| 173 | + else |
| 174 | + salo_is_not_running |
| 175 | + fi |
| 176 | + |
| 177 | + # Proxy Node commands to the "node" binary on the application container... |
| 178 | + elif [ "$1" == "node" ]; then |
| 179 | + shift 1 |
| 180 | + |
| 181 | + if [ "$EXEC" == "yes" ]; then |
| 182 | + docker-compose exec \ |
| 183 | + -u salo \ |
| 184 | + "$APP_SERVICE" \ |
| 185 | + node "$@" |
| 186 | + else |
| 187 | + salo_is_not_running |
| 188 | + fi |
| 189 | + |
| 190 | + # Proxy NPM commands to the "npm" binary on the application container... |
| 191 | + elif [ "$1" == "npm" ]; then |
| 192 | + shift 1 |
| 193 | + |
| 194 | + if [ "$EXEC" == "yes" ]; then |
| 195 | + docker-compose exec \ |
| 196 | + -u salo \ |
| 197 | + "$APP_SERVICE" \ |
| 198 | + npm "$@" |
| 199 | + else |
| 200 | + salo_is_not_running |
| 201 | + fi |
| 202 | + |
| 203 | + # Proxy NPX commands to the "npx" binary on the application container... |
| 204 | + elif [ "$1" == "npx" ]; then |
| 205 | + shift 1 |
| 206 | + |
| 207 | + if [ "$EXEC" == "yes" ]; then |
| 208 | + docker-compose exec \ |
| 209 | + -u salo \ |
| 210 | + "$APP_SERVICE" \ |
| 211 | + npx "$@" |
| 212 | + else |
| 213 | + salo_is_not_running |
| 214 | + fi |
| 215 | + |
| 216 | + # Proxy YARN commands to the "yarn" binary on the application container... |
| 217 | + elif [ "$1" == "yarn" ]; then |
| 218 | + shift 1 |
| 219 | + |
| 220 | + if [ "$EXEC" == "yes" ]; then |
| 221 | + docker-compose exec \ |
| 222 | + -u salo \ |
| 223 | + "$APP_SERVICE" \ |
| 224 | + yarn "$@" |
| 225 | + else |
| 226 | + salo_is_not_running |
| 227 | + fi |
| 228 | + |
| 229 | + # Initiate a MySQL CLI terminal session within the "mysql" container... |
| 230 | + elif [ "$1" == "mysql" ]; then |
| 231 | + shift 1 |
| 232 | + |
| 233 | + if [ "$EXEC" == "yes" ]; then |
| 234 | + docker-compose exec \ |
| 235 | + mysql \ |
| 236 | + bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}' |
| 237 | + else |
| 238 | + salo_is_not_running |
| 239 | + fi |
| 240 | + |
| 241 | + # Initiate a MySQL CLI terminal session within the "mariadb" container... |
| 242 | + elif [ "$1" == "mariadb" ]; then |
| 243 | + shift 1 |
| 244 | + |
| 245 | + if [ "$EXEC" == "yes" ]; then |
| 246 | + docker-compose exec \ |
| 247 | + mariadb \ |
| 248 | + bash -c 'MYSQL_PWD=${MYSQL_PASSWORD} mysql -u ${MYSQL_USER} ${MYSQL_DATABASE}' |
| 249 | + else |
| 250 | + salo_is_not_running |
| 251 | + fi |
| 252 | + |
| 253 | + # Initiate a PostgreSQL CLI terminal session within the "pgsql" container... |
| 254 | + elif [ "$1" == "psql" ]; then |
| 255 | + shift 1 |
| 256 | + |
| 257 | + if [ "$EXEC" == "yes" ]; then |
| 258 | + docker-compose exec \ |
| 259 | + pgsql \ |
| 260 | + bash -c 'PGPASSWORD=${PGPASSWORD} psql -U ${POSTGRES_USER} ${POSTGRES_DB}' |
| 261 | + else |
| 262 | + salo_is_not_running |
| 263 | + fi |
| 264 | + |
| 265 | + # Initiate a Bash shell within the application container... |
| 266 | + elif [ "$1" == "shell" ] || [ "$1" == "bash" ]; then |
| 267 | + shift 1 |
| 268 | + |
| 269 | + if [ "$EXEC" == "yes" ]; then |
| 270 | + docker-compose exec \ |
| 271 | + -u salo \ |
| 272 | + "$APP_SERVICE" \ |
| 273 | + bash |
| 274 | + else |
| 275 | + salo_is_not_running |
| 276 | + fi |
| 277 | + |
| 278 | + # Initiate a root user Bash shell within the application container... |
| 279 | + elif [ "$1" == "root-shell" ] ; then |
| 280 | + shift 1 |
| 281 | + |
| 282 | + if [ "$EXEC" == "yes" ]; then |
| 283 | + docker-compose exec \ |
| 284 | + "$APP_SERVICE" \ |
| 285 | + bash |
| 286 | + else |
| 287 | + salo_is_not_running |
| 288 | + fi |
| 289 | + |
| 290 | + # Initiate a Redis CLI terminal session within the "redis" container... |
| 291 | + elif [ "$1" == "redis" ] ; then |
| 292 | + shift 1 |
| 293 | + |
| 294 | + if [ "$EXEC" == "yes" ]; then |
| 295 | + docker-compose exec \ |
| 296 | + redis \ |
| 297 | + redis-cli |
| 298 | + else |
| 299 | + salo_is_not_running |
| 300 | + fi |
| 301 | + |
| 302 | + # Share the site... |
| 303 | + elif [ "$1" == "share" ]; then |
| 304 | + shift 1 |
| 305 | + |
| 306 | + if [ "$EXEC" == "yes" ]; then |
| 307 | + docker run --init --rm -p $SALO_SHARE_DASHBOARD:4040 -t beyondcodegmbh/expose-server:latest share http://host.docker.internal:"$APP_PORT" \ |
| 308 | + --server-host="$SALO_SHARE_SERVER_HOST" \ |
| 309 | + --server-port="$SALO_SHARE_SERVER_PORT" \ |
| 310 | + --auth="$SALO_SHARE_TOKEN" \ |
| 311 | + --subdomain="" \ |
| 312 | + "$@" |
| 313 | + else |
| 314 | + salo_is_not_running |
| 315 | + fi |
| 316 | + |
| 317 | + # Pass unknown commands to the "docker-compose" binary... |
| 318 | + else |
| 319 | + docker-compose "$@" |
| 320 | + fi |
| 321 | +else |
| 322 | + docker-compose ps |
| 323 | +fi |
0 commit comments