Allow updating stopped containers and check the download of the install script needed to assess build resource requirements
This commit is contained in:
parent
6c507a0f90
commit
ae2c84500a
@ -38,8 +38,10 @@ while read -r container; do
|
|||||||
container_name=$(echo $container | awk '{print $2}')
|
container_name=$(echo $container | awk '{print $2}')
|
||||||
container_status=$(echo $container | awk '{print $3}')
|
container_status=$(echo $container | awk '{print $3}')
|
||||||
formatted_line=$(printf "$FORMAT" "$container_name" "$container_status")
|
formatted_line=$(printf "$FORMAT" "$container_name" "$container_status")
|
||||||
IS_HELPERSCRIPT_LXC=$(pct exec $container_id -- [ -e /usr/bin/update ] && echo true || echo false)
|
#IS_HELPERSCRIPT_LXC=$(pct exec $container_id -- [ -e /usr/bin/update ] && echo true || echo false)
|
||||||
if [ "$IS_HELPERSCRIPT_LXC" = true ]; then
|
#if [ "$IS_HELPERSCRIPT_LXC" = true ]; then
|
||||||
|
detect_service $container
|
||||||
|
if [ -n "${service}" ]; then
|
||||||
menu_items+=("$container_id" "$formatted_line" "OFF")
|
menu_items+=("$container_id" "$formatted_line" "OFF")
|
||||||
fi
|
fi
|
||||||
done <<< "$containers"
|
done <<< "$containers"
|
||||||
@ -99,6 +101,13 @@ function backup_container(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function detect_service(){
|
||||||
|
pushd $(mktemp -d) >/dev/null
|
||||||
|
pct pull "$1" /usr/bin/update update 2>/dev/null
|
||||||
|
service=$(cat update | sed 's|.*/ct/||g' | sed 's|\.sh).*||g')
|
||||||
|
popd >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
UPDATE_CMD="update;"
|
UPDATE_CMD="update;"
|
||||||
if [ "$UNATTENDED_UPDATE" == "yes" ];then
|
if [ "$UNATTENDED_UPDATE" == "yes" ];then
|
||||||
UPDATE_CMD="export PHS_SILENT=1;update;"
|
UPDATE_CMD="export PHS_SILENT=1;update;"
|
||||||
@ -113,10 +122,7 @@ for container in $CHOICE; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#1) Detect service using the service name in the update command
|
#1) Detect service using the service name in the update command
|
||||||
pushd $(mktemp -d) >/dev/null
|
detect_service $container
|
||||||
pct pull "$container" /usr/bin/update update 2>/dev/null
|
|
||||||
service=$(cat update | sed 's|.*/ct/||g' | sed 's|\.sh).*||g')
|
|
||||||
popd >/dev/null
|
|
||||||
|
|
||||||
#1.1) If update script not detected, return
|
#1.1) If update script not detected, return
|
||||||
if [ -z "${service}" ]; then
|
if [ -z "${service}" ]; then
|
||||||
@ -127,7 +133,14 @@ for container in $CHOICE; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#2) Extract service build/update resource requirements from config/installation file
|
#2) Extract service build/update resource requirements from config/installation file
|
||||||
script=$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/ct/${service}.sh)
|
script=$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${service}.sh)
|
||||||
|
|
||||||
|
#2.1) Check if the script downloaded successfully
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "${RD}[ERROR]${CL} Issue while downloading install script."
|
||||||
|
echo -e "${YW}[WARN]${CL} Unable to assess build resource requirements. Proceeding with current resources."
|
||||||
|
fi
|
||||||
|
|
||||||
config=$(pct config "$container")
|
config=$(pct config "$container")
|
||||||
build_cpu=$(echo "$script" | { grep -m 1 "var_cpu" || test $? = 1; } | sed 's|.*=||g' | sed 's|"||g' | sed 's|.*var_cpu:-||g' | sed 's|}||g')
|
build_cpu=$(echo "$script" | { grep -m 1 "var_cpu" || test $? = 1; } | sed 's|.*=||g' | sed 's|"||g' | sed 's|.*var_cpu:-||g' | sed 's|}||g')
|
||||||
build_ram=$(echo "$script" | { grep -m 1 "var_ram" || test $? = 1; } | sed 's|.*=||g' | sed 's|"||g' | sed 's|.*var_ram:-||g' | sed 's|}||g')
|
build_ram=$(echo "$script" | { grep -m 1 "var_ram" || test $? = 1; } | sed 's|.*=||g' | sed 's|"||g' | sed 's|.*var_ram:-||g' | sed 's|}||g')
|
||||||
@ -168,6 +181,14 @@ for container in $CHOICE; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
|
os=$(pct config "$container" | awk '/^ostype/ {print $2}')
|
||||||
|
status=$(pct status $container)
|
||||||
|
template=$(pct config $container | grep -q "template:" && echo "true" || echo "false")
|
||||||
|
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
|
||||||
|
echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n"
|
||||||
|
pct start $container
|
||||||
|
echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n"
|
||||||
|
sleep 5
|
||||||
|
fi
|
||||||
|
|
||||||
#4) Update service, using the update command
|
#4) Update service, using the update command
|
||||||
case "$os" in
|
case "$os" in
|
||||||
@ -179,6 +200,11 @@ for container in $CHOICE; do
|
|||||||
esac
|
esac
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
|
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
|
||||||
|
echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n"
|
||||||
|
pct shutdown $container &
|
||||||
|
fi
|
||||||
|
|
||||||
#5) if build resources are different than run resources, then:
|
#5) if build resources are different than run resources, then:
|
||||||
if [ "$UPDATE_BUILD_RESOURCES" -eq "1" ]; then
|
if [ "$UPDATE_BUILD_RESOURCES" -eq "1" ]; then
|
||||||
pct set "$container" --cores "$run_cpu" --memory "$run_ram"
|
pct set "$container" --cores "$run_cpu" --memory "$run_ram"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user