diff --git a/dist/openrc/tiny-cloud b/dist/openrc/tiny-cloud index a4beae1..0fff2f9 100755 --- a/dist/openrc/tiny-cloud +++ b/dist/openrc/tiny-cloud @@ -1,5 +1,6 @@ #!/sbin/openrc-run # vim:set ts=8 noet ft=sh: +# shellcheck shell=sh description="Tiny Cloud Bootstrap - main phase" extra_commands="complete incomplete" diff --git a/dist/openrc/tiny-cloud-early b/dist/openrc/tiny-cloud-early index 88c9c7e..20a20db 100755 --- a/dist/openrc/tiny-cloud-early +++ b/dist/openrc/tiny-cloud-early @@ -1,5 +1,6 @@ #!/sbin/openrc-run # vim:set ts=8 noet ft=sh: +# shellcheck shell=sh description="Tiny Cloud Bootstrap - early phase" diff --git a/dist/openrc/tiny-cloud-final b/dist/openrc/tiny-cloud-final index 269fe0f..5169fc2 100755 --- a/dist/openrc/tiny-cloud-final +++ b/dist/openrc/tiny-cloud-final @@ -1,5 +1,6 @@ #!/sbin/openrc-run # vim:set ts=8 noet ft=sh: +# shellcheck shell=sh description="Tiny Cloud Bootstrap - final phase" diff --git a/dist/openrc/tiny-cloud-net b/dist/openrc/tiny-cloud-net index 5614312..d6659df 100755 --- a/dist/openrc/tiny-cloud-net +++ b/dist/openrc/tiny-cloud-net @@ -1,5 +1,6 @@ #!/sbin/openrc-run # vim:set ts=8 noet ft=sh: +# shellcheck shell=sh description="Tiny Cloud Bootstrap - net phase" depend() { diff --git a/lib/tiny-cloud/cloud/alpine/init b/lib/tiny-cloud/cloud/alpine/init index 75441b8..6081ba0 100644 --- a/lib/tiny-cloud/cloud/alpine/init +++ b/lib/tiny-cloud/cloud/alpine/init @@ -1,5 +1,6 @@ # Tiny Cloud - Init Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh INIT_ACTIONS_EARLY="$(replace_word set_default_interfaces set_network_interfaces $INIT_ACTIONS_EARLY)" diff --git a/lib/tiny-cloud/cloud/aws/imds b/lib/tiny-cloud/cloud/aws/imds index a115768..94442d8 100644 --- a/lib/tiny-cloud/cloud/aws/imds +++ b/lib/tiny-cloud/cloud/aws/imds @@ -1,5 +1,6 @@ # AWS Instance MetaData Service variables and functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh IMDS_HEADER="X-aws-ec2-metadata-token" IMDS_TOKEN_TTL_HEADER="X-aws-ec2-metadata-token-ttl-seconds" diff --git a/lib/tiny-cloud/cloud/aws/mdev b/lib/tiny-cloud/cloud/aws/mdev index b577a43..b1f6218 100644 --- a/lib/tiny-cloud/cloud/aws/mdev +++ b/lib/tiny-cloud/cloud/aws/mdev @@ -1,5 +1,6 @@ # AWS mdev Hotplug Modules # vim:set ts=4 et ft=sh: +# shellcheck shell=sh # makes symlinks for NVMe devices that correlate to AWS EBS sd/xvd devices mod__nvme_ebs_links() { diff --git a/lib/tiny-cloud/cloud/azure/imds b/lib/tiny-cloud/cloud/azure/imds index 8ec6662..ebedefd 100644 --- a/lib/tiny-cloud/cloud/azure/imds +++ b/lib/tiny-cloud/cloud/azure/imds @@ -1,5 +1,6 @@ # Azure Instance MetaData Service variables and functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh IMDS_HEADER="Metadata" IMDS_QUERY="?format=text&api-version=2021-05-01" diff --git a/lib/tiny-cloud/cloud/gcp/imds b/lib/tiny-cloud/cloud/gcp/imds index 5e3b363..7598b63 100644 --- a/lib/tiny-cloud/cloud/gcp/imds +++ b/lib/tiny-cloud/cloud/gcp/imds @@ -1,5 +1,6 @@ # Google Cloud Instance MetaData Service variables and functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh IMDS_HEADER="Metadata-Flavor" IMDS_URI="computeMetadata/v1" diff --git a/lib/tiny-cloud/cloud/nocloud/imds b/lib/tiny-cloud/cloud/nocloud/imds index f3378c4..4db1aef 100644 --- a/lib/tiny-cloud/cloud/nocloud/imds +++ b/lib/tiny-cloud/cloud/nocloud/imds @@ -1,5 +1,6 @@ # NoCloud Instance Metadata # vim: ts=4 et ft=sh: +# shellcheck shell=sh NOCLOUD_FILES="meta-data user-data vendor-data network-config" diff --git a/lib/tiny-cloud/cloud/oci/imds b/lib/tiny-cloud/cloud/oci/imds index 3cf12f0..4d17c31 100644 --- a/lib/tiny-cloud/cloud/oci/imds +++ b/lib/tiny-cloud/cloud/oci/imds @@ -1,5 +1,6 @@ # OCI Instance MetaData Service variables and functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh IMDS_HEADER="Authorization" IMDS_URI="opc/v2" diff --git a/lib/tiny-cloud/common b/lib/tiny-cloud/common index 51256af..fea28f3 100644 --- a/lib/tiny-cloud/common +++ b/lib/tiny-cloud/common @@ -1,5 +1,6 @@ # Tiny Cloud - common script functions # vim: ts=4 et ft=sh: +# shellcheck shell=sh # set defaults [ -f "$ROOT/etc/tiny-cloud.conf" ] && . "$ROOT/etc/tiny-cloud.conf" @@ -26,7 +27,7 @@ log() { shift [ -n "$init" ] && echo "$@" >&2 - logger $stderr -p "$facility.$level" -t "$tag[$$]" "$@" + logger $stderr -p "$facility.$level" -t "${tag}[$$]" "$@" case "$level" in crit|alert|emerg) exit 1 ;; esac diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 6e8d2fa..51cb541 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -1,5 +1,6 @@ # Tiny Cloud - Init Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh # set defaults : "${LIBDIR:=$PREFIX/lib}" diff --git a/lib/tiny-cloud/mdev b/lib/tiny-cloud/mdev index 5b05839..fa8dc31 100644 --- a/lib/tiny-cloud/mdev +++ b/lib/tiny-cloud/mdev @@ -1,5 +1,6 @@ # Tiny Cloud - mdev hotplug functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh # generic helper function to install mdev rules install_before() { diff --git a/lib/tiny-cloud/user-data/alpine-config b/lib/tiny-cloud/user-data/alpine-config index c04d86e..ec9f9ea 100644 --- a/lib/tiny-cloud/user-data/alpine-config +++ b/lib/tiny-cloud/user-data/alpine-config @@ -1,5 +1,6 @@ # Script UserData Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh INIT_ACTIONS_MAIN="$(insert_after set_hostname \ "userdata_bootcmd userdata_ntp userdata_apk_cache userdata_apk_repositories userdata_packages" \ diff --git a/lib/tiny-cloud/user-data/cloud-config b/lib/tiny-cloud/user-data/cloud-config index 6c8adbe..67afcaf 100644 --- a/lib/tiny-cloud/user-data/cloud-config +++ b/lib/tiny-cloud/user-data/cloud-config @@ -1,4 +1,5 @@ # CloudConfig UserData Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh # TODO diff --git a/lib/tiny-cloud/user-data/missing b/lib/tiny-cloud/user-data/missing index cbb9c2c..6eb4ab7 100644 --- a/lib/tiny-cloud/user-data/missing +++ b/lib/tiny-cloud/user-data/missing @@ -1,5 +1,6 @@ # Missing UserData Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh init__missing_userdata() { log -i -t "$phase" notice "$ACTION: no user-data found" diff --git a/lib/tiny-cloud/user-data/script b/lib/tiny-cloud/user-data/script index f545384..b967582 100644 --- a/lib/tiny-cloud/user-data/script +++ b/lib/tiny-cloud/user-data/script @@ -1,12 +1,13 @@ # Script UserData Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh init__run_userdata() { local log="$TINY_CLOUD_LOGS/user-data.log" local exit="$TINY_CLOUD_LOGS/user-data.exit" local userdata="$TINY_CLOUD_VAR/user-data" - chmod +x "$userdata" + chmod u+x "$userdata" { "$userdata" 2>& 1; echo $? > "$exit"; } | tee "$log" return $(cat "$exit") diff --git a/lib/tiny-cloud/user-data/unknown b/lib/tiny-cloud/user-data/unknown index 14ed827..3bf4c9b 100644 --- a/lib/tiny-cloud/user-data/unknown +++ b/lib/tiny-cloud/user-data/unknown @@ -1,5 +1,6 @@ # Unknown UserData Functions # vim:set ts=4 et ft=sh: +# shellcheck shell=sh init__unknown_userdata() { local type="$(userdata_type)" diff --git a/sbin/tiny-cloud b/sbin/tiny-cloud index 1938d8c..3b5c7df 100755 --- a/sbin/tiny-cloud +++ b/sbin/tiny-cloud @@ -10,16 +10,19 @@ set -e usage() { cat <&2; exit 1; } if [ $# -eq 0 ]; then @@ -33,11 +36,12 @@ while true; do -b|--bootstrap) shift case "$1" in complete) # indicate bootstrap is done - init__bootstrap_complete + bootstrap_complete log -i notice 'bootstrap marked complete';; incomplete) # indicate bootstrap isn't done bootstrap_incomplete log -i warn 'bootstrap marked incomplete';; + status) is_bootstrap_complete && echo 'complete' || echo 'incomplete' ;; *) usage >&2; exit 1;; esac exit 0;; @@ -65,7 +69,7 @@ case "$phase" in esac # is initial bootstrap already done? -if [ -f "$TINY_CLOUD_VAR/.bootstrap-complete" ]; then +if is_bootstrap_complete; then log -i -t "$phase" info "already bootstrapped" exit 0; fi @@ -85,6 +89,9 @@ skip_action() { } # mandatory final action... +init__bootstrap_complete() { + bootstrap_complete +} INIT_ACTIONS_FINAL="${INIT_ACTIONS_FINAL} bootstrap_complete" ### let's do stuff! @@ -97,14 +104,15 @@ case "$phase" in *) usage >&2; exit 1 esac +printf '\n' >&2 for ACTION in $INIT_ACTIONS; do if skip_action "$ACTION"; then - printf '\n -- ' >&2 + printf ' -- ' >&2 log -i -t "$phase" notice "$ACTION: skipped" continue fi - printf '\n ++ ' >&2 - log -i -t "$phase" info "$ACTION" + printf ' ++ ' >&2 + log -i -t "$phase" info "$ACTION: starting" RESULT="unknown" LEVEL="err" if type "init__$ACTION" | grep -q -w "function"; then @@ -118,4 +126,3 @@ for ACTION in $INIT_ACTIONS; do printf ' ++ ' >&2 log -i -t "$phase" "$LEVEL" "$ACTION: $RESULT" done -echo >&2 diff --git a/tests/assemble-interfaces.test b/tests/assemble-interfaces.test index 6fbf123..e916374 100755 --- a/tests/assemble-interfaces.test +++ b/tests/assemble-interfaces.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/fake-wget.test b/tests/fake-wget.test index 1e7af27..053739b 100755 --- a/tests/fake-wget.test +++ b/tests/fake-wget.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh init_tests \ @@ -17,13 +18,13 @@ init_tests \ fake_wget_usage_body() { atf_check -s exit:0 \ - -o match:"^usage: $@" \ + -o match:"^usage: $*" \ -e empty \ wget -h atf_check -s exit:1 \ -o empty \ - -e match:"^usage: $@" \ + -e match:"^usage: $*" \ wget -INVALID } @@ -109,4 +110,3 @@ fake_wget_content_from_path_body() { -o match:"^value$" \ wget --quiet -O - https://example.com/foo/key } - diff --git a/tests/imds.test b/tests/imds.test index 120bb00..c99d13a 100755 --- a/tests/imds.test +++ b/tests/imds.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/init-early.test b/tests/init-early.test index 43c0fe5..f1e4410 100755 --- a/tests/init-early.test +++ b/tests/init-early.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/init-final.test b/tests/init-final.test index 8b8a514..312a0a2 100755 --- a/tests/init-final.test +++ b/tests/init-final.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/init-main.test b/tests/init-main.test index ed5c012..ce0842c 100755 --- a/tests/init-main.test +++ b/tests/init-main.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/tiny-cloud-alpine.test b/tests/tiny-cloud-alpine.test index 0ef1437..0d1e82d 100755 --- a/tests/tiny-cloud-alpine.test +++ b/tests/tiny-cloud-alpine.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh diff --git a/tests/tiny-cloud.test b/tests/tiny-cloud.test index f48e2af..01c9019 100755 --- a/tests/tiny-cloud.test +++ b/tests/tiny-cloud.test @@ -1,4 +1,5 @@ #!/usr/bin/env atf-sh +# shellcheck shell=sh . $(atf_get_srcdir)/test_env.sh