1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-16 03:42:44 +03:00

Fix UserData Script chmod, etc.

This commit is contained in:
Jake Buchholz Göktürk 2023-05-15 01:33:57 +00:00
parent e650415799
commit badf0f65d1
28 changed files with 46 additions and 13 deletions

View File

@ -1,5 +1,6 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# vim:set ts=8 noet ft=sh: # vim:set ts=8 noet ft=sh:
# shellcheck shell=sh
description="Tiny Cloud Bootstrap - main phase" description="Tiny Cloud Bootstrap - main phase"
extra_commands="complete incomplete" extra_commands="complete incomplete"

View File

@ -1,5 +1,6 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# vim:set ts=8 noet ft=sh: # vim:set ts=8 noet ft=sh:
# shellcheck shell=sh
description="Tiny Cloud Bootstrap - early phase" description="Tiny Cloud Bootstrap - early phase"

View File

@ -1,5 +1,6 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# vim:set ts=8 noet ft=sh: # vim:set ts=8 noet ft=sh:
# shellcheck shell=sh
description="Tiny Cloud Bootstrap - final phase" description="Tiny Cloud Bootstrap - final phase"

View File

@ -1,5 +1,6 @@
#!/sbin/openrc-run #!/sbin/openrc-run
# vim:set ts=8 noet ft=sh: # vim:set ts=8 noet ft=sh:
# shellcheck shell=sh
description="Tiny Cloud Bootstrap - net phase" description="Tiny Cloud Bootstrap - net phase"
depend() { depend() {

View File

@ -1,5 +1,6 @@
# Tiny Cloud - Init Functions # Tiny Cloud - Init Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
INIT_ACTIONS_EARLY="$(replace_word set_default_interfaces set_network_interfaces $INIT_ACTIONS_EARLY)" INIT_ACTIONS_EARLY="$(replace_word set_default_interfaces set_network_interfaces $INIT_ACTIONS_EARLY)"

View File

@ -1,5 +1,6 @@
# AWS Instance MetaData Service variables and functions # AWS Instance MetaData Service variables and functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
IMDS_HEADER="X-aws-ec2-metadata-token" IMDS_HEADER="X-aws-ec2-metadata-token"
IMDS_TOKEN_TTL_HEADER="X-aws-ec2-metadata-token-ttl-seconds" IMDS_TOKEN_TTL_HEADER="X-aws-ec2-metadata-token-ttl-seconds"

View File

@ -1,5 +1,6 @@
# AWS mdev Hotplug Modules # AWS mdev Hotplug Modules
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
# makes symlinks for NVMe devices that correlate to AWS EBS sd/xvd devices # makes symlinks for NVMe devices that correlate to AWS EBS sd/xvd devices
mod__nvme_ebs_links() { mod__nvme_ebs_links() {

View File

@ -1,5 +1,6 @@
# Azure Instance MetaData Service variables and functions # Azure Instance MetaData Service variables and functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
IMDS_HEADER="Metadata" IMDS_HEADER="Metadata"
IMDS_QUERY="?format=text&api-version=2021-05-01" IMDS_QUERY="?format=text&api-version=2021-05-01"

View File

@ -1,5 +1,6 @@
# Google Cloud Instance MetaData Service variables and functions # Google Cloud Instance MetaData Service variables and functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
IMDS_HEADER="Metadata-Flavor" IMDS_HEADER="Metadata-Flavor"
IMDS_URI="computeMetadata/v1" IMDS_URI="computeMetadata/v1"

View File

@ -1,5 +1,6 @@
# NoCloud Instance Metadata # NoCloud Instance Metadata
# vim: ts=4 et ft=sh: # vim: ts=4 et ft=sh:
# shellcheck shell=sh
NOCLOUD_FILES="meta-data user-data vendor-data network-config" NOCLOUD_FILES="meta-data user-data vendor-data network-config"

View File

@ -1,5 +1,6 @@
# OCI Instance MetaData Service variables and functions # OCI Instance MetaData Service variables and functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
IMDS_HEADER="Authorization" IMDS_HEADER="Authorization"
IMDS_URI="opc/v2" IMDS_URI="opc/v2"

View File

@ -1,5 +1,6 @@
# Tiny Cloud - common script functions # Tiny Cloud - common script functions
# vim: ts=4 et ft=sh: # vim: ts=4 et ft=sh:
# shellcheck shell=sh
# set defaults # set defaults
[ -f "$ROOT/etc/tiny-cloud.conf" ] && . "$ROOT/etc/tiny-cloud.conf" [ -f "$ROOT/etc/tiny-cloud.conf" ] && . "$ROOT/etc/tiny-cloud.conf"
@ -26,7 +27,7 @@ log() {
shift shift
[ -n "$init" ] && echo "$@" >&2 [ -n "$init" ] && echo "$@" >&2
logger $stderr -p "$facility.$level" -t "$tag[$$]" "$@" logger $stderr -p "$facility.$level" -t "${tag}[$$]" "$@"
case "$level" in case "$level" in
crit|alert|emerg) exit 1 ;; crit|alert|emerg) exit 1 ;;
esac esac

View File

@ -1,5 +1,6 @@
# Tiny Cloud - Init Functions # Tiny Cloud - Init Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
# set defaults # set defaults
: "${LIBDIR:=$PREFIX/lib}" : "${LIBDIR:=$PREFIX/lib}"

View File

@ -1,5 +1,6 @@
# Tiny Cloud - mdev hotplug functions # Tiny Cloud - mdev hotplug functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
# generic helper function to install mdev rules # generic helper function to install mdev rules
install_before() { install_before() {

View File

@ -1,5 +1,6 @@
# Script UserData Functions # Script UserData Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
INIT_ACTIONS_MAIN="$(insert_after set_hostname \ INIT_ACTIONS_MAIN="$(insert_after set_hostname \
"userdata_bootcmd userdata_ntp userdata_apk_cache userdata_apk_repositories userdata_packages" \ "userdata_bootcmd userdata_ntp userdata_apk_cache userdata_apk_repositories userdata_packages" \

View File

@ -1,4 +1,5 @@
# CloudConfig UserData Functions # CloudConfig UserData Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
# TODO # TODO

View File

@ -1,5 +1,6 @@
# Missing UserData Functions # Missing UserData Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
init__missing_userdata() { init__missing_userdata() {
log -i -t "$phase" notice "$ACTION: no user-data found" log -i -t "$phase" notice "$ACTION: no user-data found"

View File

@ -1,12 +1,13 @@
# Script UserData Functions # Script UserData Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
init__run_userdata() { init__run_userdata() {
local log="$TINY_CLOUD_LOGS/user-data.log" local log="$TINY_CLOUD_LOGS/user-data.log"
local exit="$TINY_CLOUD_LOGS/user-data.exit" local exit="$TINY_CLOUD_LOGS/user-data.exit"
local userdata="$TINY_CLOUD_VAR/user-data" local userdata="$TINY_CLOUD_VAR/user-data"
chmod +x "$userdata" chmod u+x "$userdata"
{ "$userdata" 2>& 1; echo $? > "$exit"; } | tee "$log" { "$userdata" 2>& 1; echo $? > "$exit"; } | tee "$log"
return $(cat "$exit") return $(cat "$exit")

View File

@ -1,5 +1,6 @@
# Unknown UserData Functions # Unknown UserData Functions
# vim:set ts=4 et ft=sh: # vim:set ts=4 et ft=sh:
# shellcheck shell=sh
init__unknown_userdata() { init__unknown_userdata() {
local type="$(userdata_type)" local type="$(userdata_type)"

View File

@ -10,16 +10,19 @@ set -e
usage() { usage() {
cat <<EOF cat <<EOF
Usage: ${0##*/} [-h | --help] { early | net | main | final | --bootstrap {complete|incomplete} | --setup } Usage: ${0##*/} [-h | --help] { early | net | main | final | --bootstrap [complete|incomplete|status] | --setup }
EOF EOF
} }
init__bootstrap_complete() { bootstrap_complete() {
touch "$TINY_CLOUD_VAR/.bootstrap-complete" touch "$TINY_CLOUD_VAR/.bootstrap-complete"
} }
bootstrap_incomplete() { bootstrap_incomplete() {
rm -f "$TINY_CLOUD_VAR/.bootstrap-complete" rm -f "$TINY_CLOUD_VAR/.bootstrap-complete"
} }
is_bootstrap_complete() {
[ -f "$TINY_CLOUD_VAR/.bootstrap-complete" ]
}
args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@") || { usage >&2; exit 1; } args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@") || { usage >&2; exit 1; }
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
@ -33,11 +36,12 @@ while true; do
-b|--bootstrap) shift -b|--bootstrap) shift
case "$1" in case "$1" in
complete) # indicate bootstrap is done complete) # indicate bootstrap is done
init__bootstrap_complete bootstrap_complete
log -i notice 'bootstrap marked complete';; log -i notice 'bootstrap marked complete';;
incomplete) # indicate bootstrap isn't done incomplete) # indicate bootstrap isn't done
bootstrap_incomplete bootstrap_incomplete
log -i warn 'bootstrap marked incomplete';; log -i warn 'bootstrap marked incomplete';;
status) is_bootstrap_complete && echo 'complete' || echo 'incomplete' ;;
*) usage >&2; exit 1;; *) usage >&2; exit 1;;
esac esac
exit 0;; exit 0;;
@ -65,7 +69,7 @@ case "$phase" in
esac esac
# is initial bootstrap already done? # 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" log -i -t "$phase" info "already bootstrapped"
exit 0; exit 0;
fi fi
@ -85,6 +89,9 @@ skip_action() {
} }
# mandatory final action... # mandatory final action...
init__bootstrap_complete() {
bootstrap_complete
}
INIT_ACTIONS_FINAL="${INIT_ACTIONS_FINAL} bootstrap_complete" INIT_ACTIONS_FINAL="${INIT_ACTIONS_FINAL} bootstrap_complete"
### let's do stuff! ### let's do stuff!
@ -97,14 +104,15 @@ case "$phase" in
*) usage >&2; exit 1 *) usage >&2; exit 1
esac esac
printf '\n' >&2
for ACTION in $INIT_ACTIONS; do for ACTION in $INIT_ACTIONS; do
if skip_action "$ACTION"; then if skip_action "$ACTION"; then
printf '\n -- ' >&2 printf ' -- ' >&2
log -i -t "$phase" notice "$ACTION: skipped" log -i -t "$phase" notice "$ACTION: skipped"
continue continue
fi fi
printf '\n ++ ' >&2 printf ' ++ ' >&2
log -i -t "$phase" info "$ACTION" log -i -t "$phase" info "$ACTION: starting"
RESULT="unknown" RESULT="unknown"
LEVEL="err" LEVEL="err"
if type "init__$ACTION" | grep -q -w "function"; then if type "init__$ACTION" | grep -q -w "function"; then
@ -118,4 +126,3 @@ for ACTION in $INIT_ACTIONS; do
printf ' ++ ' >&2 printf ' ++ ' >&2
log -i -t "$phase" "$LEVEL" "$ACTION: $RESULT" log -i -t "$phase" "$LEVEL" "$ACTION: $RESULT"
done done
echo >&2

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh
init_tests \ init_tests \
@ -17,13 +18,13 @@ init_tests \
fake_wget_usage_body() { fake_wget_usage_body() {
atf_check -s exit:0 \ atf_check -s exit:0 \
-o match:"^usage: $@" \ -o match:"^usage: $*" \
-e empty \ -e empty \
wget -h wget -h
atf_check -s exit:1 \ atf_check -s exit:1 \
-o empty \ -o empty \
-e match:"^usage: $@" \ -e match:"^usage: $*" \
wget -INVALID wget -INVALID
} }
@ -109,4 +110,3 @@ fake_wget_content_from_path_body() {
-o match:"^value$" \ -o match:"^value$" \
wget --quiet -O - https://example.com/foo/key wget --quiet -O - https://example.com/foo/key
} }

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh

View File

@ -1,4 +1,5 @@
#!/usr/bin/env atf-sh #!/usr/bin/env atf-sh
# shellcheck shell=sh
. $(atf_get_srcdir)/test_env.sh . $(atf_get_srcdir)/test_env.sh