[gh] Update Script Test Workflow (#2599)

* Update Workflow

* Update Workflow
This commit is contained in:
Michel Roegl-Brunner 2025-02-24 15:54:51 +02:00 committed by GitHub
parent 6827056a1d
commit 40469c5de5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 115 additions and 115 deletions

View File

@ -13,7 +13,7 @@ jobs:
run-install-script: run-install-script:
runs-on: pvenode runs-on: pvenode
steps: steps:
- name: Checkout PR branch (supports forks) - name: Checkout PR branch
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.ref }} ref: ${{ github.event.pull_request.head.ref }}
@ -37,7 +37,8 @@ jobs:
echo "Changed files: $CHANGED_FILES" echo "Changed files: $CHANGED_FILES"
echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get scripts - name: Get scripts
id: check-install-script id: check-install-script
@ -68,11 +69,11 @@ jobs:
echo "Running Test for: $STRIPPED_NAME" echo "Running Test for: $STRIPPED_NAME"
if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
CT_SCRIPT="ct/$STRIPPED_NAME.sh" CT_SCRIPT="ct/$STRIPPED_NAME.sh"
echo $CT_SCRIPT
if [[ ! -f $CT_SCRIPT ]]; then if [[ ! -f $CT_SCRIPT ]]; then
echo "No CT script found for $STRIPPED_NAME" echo "No CT script found for $STRIPPED_NAME"
ERROR_MSG="No CT script found for $FILE" ERROR_MSG="No CT script found for $FILE"
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log RUN=false
continue
fi fi
echo "Found CT script for $STRIPPED_NAME" echo "Found CT script for $STRIPPED_NAME"
chmod +x "$CT_SCRIPT" chmod +x "$CT_SCRIPT"
@ -82,32 +83,19 @@ jobs:
if [[ ! -f $INSTALL_SCRIPT ]]; then if [[ ! -f $INSTALL_SCRIPT ]]; then
echo "No install script found for $STRIPPED_NAME" echo "No install script found for $STRIPPED_NAME"
ERROR_MSG="No install script found for $FILE" ERROR_MSG="No install script found for $FILE"
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log RUN=false
continue
fi fi
echo "Found install script for $STRIPPED_NAME" echo "Found install script for $STRIPPED_NAME"
chmod +x "$INSTALL_SCRIPT" chmod +x "$INSTALL_SCRIPT"
RUNNING_FILE=$FILE RUNNING_FILE=$FILE
fi fi
git remote add community-scripts https://github.com/community-scripts/ProxmoxVE.git if [[ $RUN != "false" ]]; then
git fetch community-scripts chmod +x $RUNNING_FILE
rm -f .github/workflows/scripts/app-test/pr-build.func || true sed -i 's|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-build.func)|g' "$RUNNING_FILE"
rm -f .github/workflows/scripts/app-test/pr-install.func || true echo "Executing $RUNNING_FILE"
rm -f .github/workflows/scripts/app-test/pr-alpine-install.func || true ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
rm -f .github/workflows/scripts/app-test/pr-create-lxc.sh || true echo "Finished running $FILE"
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-build.func fi
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-install.func
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-alpine-install.func
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-create-lxc.sh
chmod +x $RUNNING_FILE
chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
chmod +x .github/workflows/scripts/app-test/pr-install.func
chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
chmod +x .github/workflows/scripts/app-test/pr-build.func
sed -i 's|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source .github/workflows/scripts/app-test/pr-build.func|g' "$RUNNING_FILE"
echo "Executing $RUNNING_FILE"
ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
echo "Finished running $FILE"
if [ -n "$ERROR_MSG" ]; then if [ -n "$ERROR_MSG" ]; then
echo "ERROR in $STRIPPED_NAME: $ERROR_MSG" echo "ERROR in $STRIPPED_NAME: $ERROR_MSG"
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
@ -125,12 +113,13 @@ jobs:
pct stop $container_id pct stop $container_id
pct destroy $container_id pct destroy $container_id
fi fi
done done
- name: Post error comments - name: Post error comments
run: | run: |
ERROR="false" ERROR="false"
SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 253:" SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 255"
for FILE in ${{ env.ALL_FILES }}; do for FILE in ${{ env.ALL_FILES }}; do
STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//') STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
if [[ ! -f result_$STRIPPED_NAME.log ]]; then if [[ ! -f result_$STRIPPED_NAME.log ]]; then
@ -145,8 +134,6 @@ jobs:
gh pr comment ${{ github.event.pull_request.number }} \ gh pr comment ${{ github.event.pull_request.number }} \
--repo ${{ github.repository }} \ --repo ${{ github.repository }} \
--body ":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>" --body ":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>"
ERROR="true" ERROR="true"
fi fi
done done
@ -157,3 +144,5 @@ jobs:
- name: Fail if error - name: Fail if error
if: ${{ env.ERROR == 'true' }} if: ${{ env.ERROR == 'true' }}
run: exit 1 run: exit 1

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: michelroegl-brunner # Author: Michel Roegl-Brunner (michelroegl-brunner)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
color() { color() {
@ -11,7 +11,7 @@ catch_errors() {
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
} }
# This function handles errors
error_handler() { error_handler() {
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
@ -21,8 +21,8 @@ error_handler() {
exit 0 exit 0
} }
verb_ip6() { verb_ip6() {
STD="" STD=""
return return
} }
msg_info() { msg_info() {
@ -30,13 +30,13 @@ msg_info() {
echo -ne "${msg}\n" echo -ne "${msg}\n"
} }
msg_ok() { msg_ok() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
msg_error() { msg_error() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
@ -71,7 +71,7 @@ network_check() {
} }
update_os() { update_os() {
msg_info "Updating Container OS" msg_info "Updating Container OS"
apk update apk update
apk upgrade apk upgrade
msg_ok "Updated Container OS" msg_ok "Updated Container OS"
@ -82,7 +82,5 @@ motd_ssh() {
} }
customize() { customize() {
return return
} }

View File

@ -6,12 +6,13 @@
variables() { variables() {
NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces. NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces.
var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP. var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP.
} }
NEXTID=$(pvesh get /cluster/nextid) NEXTID=$(pvesh get /cluster/nextid)
timezone=$(cat /etc/timezone) timezone=$(cat /etc/timezone)
header_info(){ header_info() {
return return
} }
base_settings() { base_settings() {
@ -20,10 +21,10 @@ base_settings() {
DISK_SIZE="4" DISK_SIZE="4"
CORE_COUNT="1" CORE_COUNT="1"
RAM_SIZE="1024" RAM_SIZE="1024"
VERBOSE="${1:-no}" VERBOSE="no"
PW="" PW=""
CT_ID=$NEXTID CT_ID=$NEXTID
HN="Testing" HN=$NSAPP
BRG="vmbr0" BRG="vmbr0"
NET="dhcp" NET="dhcp"
GATE="" GATE=""
@ -106,7 +107,7 @@ catch_errors() {
} }
# This function handles errors # This function handles errors
error_handler() { error_handler() {
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
SCRIPT_NAME=$(basename "$0") SCRIPT_NAME=$(basename "$0")
@ -120,17 +121,17 @@ msg_info() {
echo -ne "${msg}\n" echo -ne "${msg}\n"
} }
msg_ok() { msg_ok() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
msg_error() { msg_error() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
start(){ start() {
base_settings base_settings
return return
} }
@ -146,9 +147,9 @@ build_container() {
TEMP_DIR=$(mktemp -d) TEMP_DIR=$(mktemp -d)
pushd $TEMP_DIR >/dev/null pushd $TEMP_DIR >/dev/null
if [ "$var_os" == "alpine" ]; then if [ "$var_os" == "alpine" ]; then
export FUNCTIONS_FILE_PATH="$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-alpine-install.func)" export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-alpine-install.func)"
else else
export FUNCTIONS_FILE_PATH="$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-install.func)" export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-install.func)"
fi fi
export CACHER="$APT_CACHER" export CACHER="$APT_CACHER"
@ -182,9 +183,8 @@ build_container() {
" "
echo "Container ID: $CTID" echo "Container ID: $CTID"
# This executes create_lxc.sh and creates the container and .conf file # This executes create_lxc.sh and creates the container and .conf file
bash /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-create-lxc.sh bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-create-lxc.sh)"
LXC_CONFIG=/etc/pve/lxc/${CTID}.conf LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
if [ "$CT_TYPE" == "0" ]; then if [ "$CT_TYPE" == "0" ]; then
@ -233,6 +233,7 @@ EOF
fi fi
fi fi
fi fi
# This starts the container and executes <app>-install.sh # This starts the container and executes <app>-install.sh
msg_info "Starting LXC Container" msg_info "Starting LXC Container"
pct start "$CTID" pct start "$CTID"
@ -242,7 +243,7 @@ EOF
msg_error "No install script found for $APP" msg_error "No install script found for $APP"
exit 1 exit 1
fi fi
if [ "$var_os" == "alpine" ]; then if [ "$var_os" == "alpine" ]; then
sleep 3 sleep 3
pct exec "$CTID" -- /bin/sh -c 'cat <<EOF >/etc/apk/repositories pct exec "$CTID" -- /bin/sh -c 'cat <<EOF >/etc/apk/repositories
http://dl-cdn.alpinelinux.org/alpine/latest-stable/main http://dl-cdn.alpinelinux.org/alpine/latest-stable/main
@ -250,11 +251,10 @@ http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
EOF' EOF'
pct exec "$CTID" -- ash -c "apk add bash >/dev/null" pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
fi fi
lxc-attach -n "$CTID" -- bash -c "$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)" $var_install.sh lxc-attach -n "$CTID" -- bash -c "$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)"
} }
description(){ description() {
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1) IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
return }
}

View File

@ -11,8 +11,9 @@ catch_errors() {
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
} }
# This function handles errors
error_handler() { error_handler() {
local exit_code="$?" local exit_code="$?"
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
local error_message="Failure in line $line_number: exit code $exit_code: while executing command $command" local error_message="Failure in line $line_number: exit code $exit_code: while executing command $command"
@ -20,7 +21,7 @@ error_handler() {
exit 100 exit 100
} }
verb_ip6() { verb_ip6() {
return return
} }
msg_info() { msg_info() {
@ -28,18 +29,17 @@ msg_info() {
echo -ne "${msg}\n" echo -ne "${msg}\n"
} }
msg_ok() { msg_ok() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
msg_error() { msg_error() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
VALIDCT=$(pvesm status -content rootdir | awk 'NR>1') VALIDCT=$(pvesm status -content rootdir | awk 'NR>1')
if [ -z "$VALIDCT" ]; then if [ -z "$VALIDCT" ]; then
msg_error "Unable to detect a valid Container Storage location." msg_error "Unable to detect a valid Container Storage location."
@ -64,9 +64,12 @@ function select_storage() {
CONTENT='vztmpl' CONTENT='vztmpl'
CONTENT_LABEL='Container template' CONTENT_LABEL='Container template'
;; ;;
*) false || { msg_error "Invalid storage class."; exit 201; };; *) false || {
msg_error "Invalid storage class."
exit 201
} ;;
esac esac
# This Queries all storage locations # This Queries all storage locations
local -a MENU local -a MENU
while read -r line; do while read -r line; do
@ -80,23 +83,32 @@ function select_storage() {
fi fi
MENU+=("$TAG" "$ITEM" "OFF") MENU+=("$TAG" "$ITEM" "OFF")
done < <(pvesm status -content $CONTENT | awk 'NR>1') done < <(pvesm status -content $CONTENT | awk 'NR>1')
# Select storage location # Select storage location
if [ $((${#MENU[@]}/3)) -eq 1 ]; then if [ $((${#MENU[@]} / 3)) -eq 1 ]; then
printf ${MENU[0]} printf ${MENU[0]}
else else
msg_error "STORAGE ISSUES!" msg_error "STORAGE ISSUES!"
exit 202 exit 202
fi fi
} }
[[ "${CTID:-}" ]] || {
msg_error "You need to set 'CTID' variable."
exit 203
}
[[ "${PCT_OSTYPE:-}" ]] || {
msg_error "You need to set 'PCT_OSTYPE' variable."
exit 204
}
# Test if ID is valid
[ "$CTID" -ge "100" ] || {
msg_error "ID cannot be less than 100."
exit 205
}
[[ "${CTID:-}" ]] || { msg_error "You need to set 'CTID' variable."; exit 203; } # Test if ID is in use
[[ "${PCT_OSTYPE:-}" ]] || { msg_error "You need to set 'PCT_OSTYPE' variable."; exit 204; }
[ "$CTID" -ge "100" ] || { msg_error "ID cannot be less than 100."; exit 205; }
if pct status $CTID &>/dev/null; then if pct status $CTID &>/dev/null; then
echo -e "ID '$CTID' is already in use." echo -e "ID '$CTID' is already in use."
unset CTID unset CTID
@ -110,10 +122,12 @@ CONTAINER_STORAGE=$(select_storage container) || exit
pveam update >/dev/null pveam update >/dev/null
TEMPLATE_SEARCH=${PCT_OSTYPE}-${PCT_OSVERSION:-} TEMPLATE_SEARCH=${PCT_OSTYPE}-${PCT_OSVERSION:-}
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V) mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V)
[ ${#TEMPLATES[@]} -gt 0 ] || { msg_error "Unable to find a template when searching for '$TEMPLATE_SEARCH'."; exit 207; } [ ${#TEMPLATES[@]} -gt 0 ] || {
msg_error "Unable to find a template when searching for '$TEMPLATE_SEARCH'."
exit 207
}
TEMPLATE="${TEMPLATES[-1]}" TEMPLATE="${TEMPLATES[-1]}"
TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE" TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
@ -121,28 +135,29 @@ TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then
[[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH" [[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH"
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null || pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null ||
{ msg_error "A problem occurred while downloading the LXC template."; exit 208; } {
msg_error "A problem occurred while downloading the LXC template."
exit 208
}
fi fi
grep -q "root:100000:65536" /etc/subuid || echo "root:100000:65536" >>/etc/subuid
grep -q "root:100000:65536" /etc/subuid || echo "root:100000:65536" >> /etc/subuid grep -q "root:100000:65536" /etc/subgid || echo "root:100000:65536" >>/etc/subgid
grep -q "root:100000:65536" /etc/subgid || echo "root:100000:65536" >> /etc/subgid
PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}}) PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}})
[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs "$CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}") [[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs "$CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}")
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then
[[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH"
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null ||
{
msg_error "A problem occurred while re-downloading the LXC template."
exit 208
}
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then
[[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH" msg_error "A problem occurred while trying to create container after re-downloading template."
exit 200
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null ||
{ msg_error "A problem occurred while re-downloading the LXC template."; exit 208; }
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then
msg_error "A problem occurred while trying to create container after re-downloading template."
exit 200
fi
fi fi
fi

View File

@ -1,31 +1,31 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright (c) 2021-2025 community-scripts ORG # Copyright (c) 2021-2025 community-scripts ORG
# Author: michelroegl-brunner # Author: Michel Roegl-Brunner (michelroegl-brunner)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE # License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
color() { color() {
return return
} }
SCRIPT_NAME="${BASH_SOURCE[0]:-unknown_script}"
catch_errors() { catch_errors() {
set -Euoe pipefail set -Euo pipefail
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
} }
error_handler() { error_handler() {
local line_number="$1" local line_number="$1"
local command="$2" local command="$2"
local error_message="$SCRIPT_NAME: Failure in line $line_number while executing command '$command'" local error_message="Failure in line $line_number while executing command '$command'"
echo -e "\n$error_message" echo -e "\n$error_message\n" >&2
exit 300 exit 1
} }
verb_ip6() { verb_ip6() {
STD="silent" STD="silent"
silent() { silent() {
"$@" >/dev/null 2>&1 || error_handler "${BASH_LINENO[0]}" "$*" "$@" >/dev/null 2>&1 || error_handler "${BASH_LINENO[0]}" "$*"
} }
return
} }
msg_info() { msg_info() {
@ -33,19 +33,21 @@ msg_info() {
echo -ne "${msg}\n" echo -ne "${msg}\n"
} }
msg_ok() { msg_ok() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
msg_error() { msg_error() {
local msg="$1" local msg="$1"
echo -e "${msg}\n" echo -e "${msg}\n"
} }
RETRY_NUM=10
RETRY_EVERY=3 RETRY_NUM=10
RETRY_EVERY=3
setting_up_container() { setting_up_container() {
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
locale_line=$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print $1}' | head -n 1) locale_line=$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print $1}' | head -n 1)
echo "LANG=${locale_line}" >/etc/default/locale echo "LANG=${locale_line}" >/etc/default/locale
@ -53,12 +55,11 @@ setting_up_container() {
export LANG=${locale_line} export LANG=${locale_line}
echo $tz >/etc/timezone echo $tz >/etc/timezone
ln -sf /usr/share/zoneinfo/$tz /etc/localtime ln -sf /usr/share/zoneinfo/$tz /etc/localtime
for ((i = RETRY_NUM; i > 0; i--)); do for ((i = RETRY_NUM; i > 0; i--)); do
if [ "$(hostname -I)" != "" ]; then if [ "$(hostname -I)" != "" ]; then
break break
fi fi
echo 1>&2 -en "No Network! "
sleep $RETRY_EVERY sleep $RETRY_EVERY
done done
if [ "$(hostname -I)" = "" ]; then if [ "$(hostname -I)" = "" ]; then
@ -68,8 +69,6 @@ setting_up_container() {
fi fi
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
systemctl disable -q --now systemd-networkd-wait-online.service systemctl disable -q --now systemd-networkd-wait-online.service
msg_ok "Set up Container OS"
msg_ok "Network Connected: $(hostname -I)"
} }
network_check() { network_check() {
@ -79,11 +78,10 @@ network_check() {
} }
update_os() { update_os() {
msg_info "Updating Container OS" export DEBIAN_FRONTEND=noninteractive
apt-get update apt-get update >/dev/null 2>&1
apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade >/dev/null
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
msg_ok "Updated Container OS"
} }
motd_ssh() { motd_ssh() {
@ -91,5 +89,5 @@ motd_ssh() {
} }
customize() { customize() {
return return
} }