diff --git a/cli.sh b/cli.sh index 022c01f..e542659 100755 --- a/cli.sh +++ b/cli.sh @@ -26,7 +26,7 @@ lokl_log() { timestamp="$(date '+%H:%M:%S')" echo "$timestamp: $1" >> /tmp/lokldebuglog -} +} set_docker_tag() { # shellcheck disable=SC2154 @@ -131,6 +131,20 @@ test_docker_available() { fi } +test_multi_arch_available() { + if + ( ( ! uname -m | grep -q 'arm64 \|x86_64 \|aarch64_be \|aarch64 \|arm8b \|arm8l') ) || + ( ( ! docker buildx ls | grep -q 'arm64 \|amd64' ) ) + then + echo "\033[0;33m" # color change + echo "â„šī¸ You're system might not support this docker image architecture." + echo "\033[0;32m" # color change + echo "Try again with lokl/lokl:latest as your lokl version." + echo "--> See 🔗 https://github.com/leonstafford/lokl#container-parameters." + echo "\033[0m" # revert color changes + fi +} + create_site_choose_php_version() { # TODO: skip choice is version has been defined in a Lokl site template @@ -191,7 +205,7 @@ create_site_choose_name() { if [ "$LOKL_TEST_MODE" ]; then lokl_log "Empty or invalid site name entered" # early exit when testing for easier assertion - exit 1 + exit 1 fi # re-ask for name entry if input was invalid @@ -298,12 +312,18 @@ choose_lokl_site_template() { PARSE_VOLUMES="1" fi + lokl_log "Concatenated volumes to mount:" + lokl_log "$VOLUMES_TO_MOUNT" + + # set Lokl PHP version variable + # set mount paths + done < "$TEMPLATE_FILE" lokl_log "Concatenated volumes to mount:" lokl_log "$VOLUMES_TO_MOUNT" - - # set Lokl PHP version variable + + # set Lokl PHP version variable # set mount paths break @@ -358,9 +378,9 @@ create_wordpress_docker_container() { if [ "$LOKL_NONINTERACTIVE_MODE" ]; then lokl_log "Site successfully launched non-interactively" - exit 0 + exit 0 fi - + clear echo "Your new Lokl WordPress site, $LOKL_NAME, is ready at:" @@ -372,7 +392,7 @@ create_wordpress_docker_container() { # return for assertion while testing if [ "$LOKL_TEST_MODE" ]; then lokl_log "Returning early for assertion under test runner" - exit 0 + exit 0 fi read -r "" @@ -390,12 +410,13 @@ wait_for_site_reachable() { max_attempts="$(set_curl_timeout_max_attempts "$LOKL_TEST_MODE")" site_poll_sleep_duration="$(set_site_poll_sleep_duration "$LOKL_TEST_MODE")" - lokl_log "Waiting for: $max_attempts curl timeout attempts" + lokl_log "Waiting for: $max_attempts curl timeout attempts" until curl --output /dev/null --silent --head --fail "http://localhost:$lokl_port"; do if [ ${attempt_counter} -eq "${max_attempts}" ]; then echo "Timed out waiting for site to come online..." + test_multi_arch_available exit 1 fi @@ -416,7 +437,7 @@ manage_sites_menu() { echo "" LOKL_CONTAINERS="$(get_lokl_container_ids)" - + # handle no container if [ -z "$LOKL_CONTAINERS" ]; then echo "" @@ -449,7 +470,7 @@ manage_sites_menu() { if [ ! -f "/tmp/lokl_containers_cache/$site_to_manage_choice" ]; then echo "Requested site not found, try again" manage_sites_menu - else + else manage_single_site fi } @@ -512,7 +533,7 @@ manage_single_site() { clear # load lokl container info from cache file - CONTAINER_INFO=$(cat "/tmp/lokl_containers_cache/$site_to_manage_choice") + CONTAINER_INFO=$(cat "/tmp/lokl_containers_cache/$site_to_manage_choice") CONTAINER_ID=$(echo "$CONTAINER_INFO" | cut -f1 -d,) CONTAINER_NAME=$(echo "$CONTAINER_INFO" | cut -f2 -d,) CONTAINER_PORT=$(echo "$CONTAINER_INFO" | cut -f3 -d,) @@ -582,7 +603,7 @@ take_site_backup() { if [ ! -f "/tmp/${CONTAINER_NAME}_SITE_BACKUP.tar.gz" ]; then echo "Failed to save backup, try again" exit 1 - else + else echo "Backup complete" echo "" exit 0 @@ -721,7 +742,7 @@ generate_site_list() { # print choices for user echo "$SITE_COUNTER) $CONTAINER_NAME" - # append choices in cache file named for site counter (brittle internal ID) + # append choices in cache file named for site counter (brittle internal ID) echo "$CONTAINER_ID,$CONTAINER_NAME,$CONTAINER_PORT,$CONTAINER_STATE" >> /tmp/lokl_containers_cache/$SITE_COUNTER SITE_COUNTER=$((SITE_COUNTER+1)) diff --git a/spec/cli_spec.sh b/spec/cli_spec.sh index 42ed91e..41244f7 100644 --- a/spec/cli_spec.sh +++ b/spec/cli_spec.sh @@ -180,7 +180,7 @@ Describe "cli.sh" It "returns random port between 4000 and 5000" # shellcheck disable=SC2154 acceptable_port_number() { - [ "$acceptable_port_number" -ge 3999 ] && [ "$acceptable_port_number" -le 5001 ] + [ "$acceptable_port_number" -ge 3999 ] && [ "$acceptable_port_number" -le 5001 ] } When call get_random_port @@ -315,7 +315,7 @@ f089aa00ac98 Describe "set_site_name()" It "remains empty if $lokl_site_name not set" When call set_site_name - The output should equal '' + The output should equal '' The status should be success End @@ -423,7 +423,7 @@ f089aa00ac98 Describe "create_site_choose_name()" It "sets LOKL_NAME to site name when proper name is given" - # mock test_core_capabilities as not core to this test + # mock test_core_capabilities as not core to this test test_core_capabilities() { return 0 } @@ -488,7 +488,7 @@ f089aa00ac98 } When run wait_for_site_reachable "mywptestsitename" "4070" - The lines of stdout should equal 5 + The lines of stdout should equal 11 The stdout should include 'Timed out waiting for site to come online..' The status should be failure End