general syntax improvements + echo mistakes fixed
This commit is contained in:
parent
bdf6641fac
commit
3ea7d03bb7
@ -1,7 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#If no argument is passed, kill the script.
|
#If no argument is passed, kill the script.
|
||||||
[[ -z "$@" ]] && echo "This script requires an arguent, use -h for help" && exit
|
[[ -z "$*" ]] && echo "This script requires an arguent, use -h for help" && exit
|
||||||
|
|
||||||
while getopts ":hsi:mt:uUp" opt
|
while getopts ":hsi:mt:uUp" opt
|
||||||
do
|
do
|
||||||
@ -26,30 +26,30 @@ do
|
|||||||
if [[ $selection == "1" ]]; then
|
if [[ $selection == "1" ]]; then
|
||||||
list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /")
|
list=$(k3s kubectl get pvc -A | sort -u | awk '{print NR-1, "\t" $1 "\t" $2 "\t" $4}' | column -t | sed "s/^0/ /")
|
||||||
echo "$list" && read -p "Please type a number : " selection
|
echo "$list" && read -p "Please type a number : " selection
|
||||||
app=$(echo -e "$list" | grep ^$selection | awk '{print $2}' | cut -c 4-)
|
app=$(echo -e "$list" | grep ^"$selection" | awk '{print $2}' | cut -c 4-)
|
||||||
pvc=$(echo -e "$list" | grep ^$selection || echo -e "\nInvalid selection")
|
pvc=$(echo -e "$list" | grep ^"$selection" || echo -e "\nInvalid selection")
|
||||||
status=$(cli -m csv -c 'app chart_release query name,status' | grep -w $app | awk -F ',' '{print $2}'| tr -d " \t\n\r") && SECONDS=0 && timeout=200
|
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "(,|^)$app(,|$)" | awk -F ',' '{print $2}'| tr -d " \t\n\r") && SECONDS=0 && timeout=200
|
||||||
[[ "$status" != "STOPPED" ]] && echo -e "\nScaling down -w $app" && midclt call chart.release.scale $app '{"replica_count": 0}' &> /dev/null
|
[[ "$status" != "STOPPED" ]] && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null
|
||||||
while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]]
|
while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]]
|
||||||
do
|
do
|
||||||
status=$(cli -m csv -c 'app chart_release query name,status' | grep $app | awk -F ',' '{print $2}'|tr -d " \t\n\r")
|
status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "(,|^)$app(,|$)" | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
||||||
echo -e "Waiting $(($timeout-$SECONDS)) more seconds for $app to be STOPPED" && sleep 10
|
echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 10
|
||||||
done
|
done
|
||||||
data_name=$(echo $pvc | awk '{print $3}')
|
data_name=$(echo "$pvc" | awk '{print $3}')
|
||||||
mount=$(echo $pvc | awk '{print $4}')
|
mount=$(echo "$pvc" | awk '{print $4}')
|
||||||
path=$(find /*/*/ix-applications/releases/$app/volumes/ -maxdepth 0 | cut -c 6-)
|
path=$(find /*/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
||||||
echo -e "\nMounting\n"$path""$mount"\nTo\n/mnt/temporary/$data_name" && zfs set mountpoint=/temporary/$data_name "$path""$mount" && echo -e "Mounted\n\nUnmount with the following command\nzfs set mountpoint=legacy "$path""$mount"\nOr use the Unmount All option"
|
echo -e "\nMounting\n""$path""""$mount""\nTo\n/mnt/temporary/$data_name" && zfs set mountpoint=/temporary/"$data_name" "$path""$mount" && echo -e "Mounted\n\nUnmount with the following command\nzfs set mountpoint=legacy ""$path"""$mount"\nOr use the Unmount All option"
|
||||||
break
|
break
|
||||||
elif [[ $selection == "2" ]]; then
|
elif [[ $selection == "2" ]]; then
|
||||||
unmount_array=($(basename -a /mnt/temporary/* | sed "s/*//"))
|
mapfile -t unmount_array < <(basename -a /mnt/temporary/* | sed "s/*//")
|
||||||
[[ -z $unmount_array ]] && echo "Theres nothing to unmount" && exit
|
[[ -z $unmount_array ]] && echo "Theres nothing to unmount" && exit
|
||||||
for i in ${unmount_array[@]}
|
for i in "${unmount_array[@]}"
|
||||||
do
|
do
|
||||||
main=$(k3s kubectl get pvc -A | grep $i | awk '{print $1, $2, $4}')
|
main=$(k3s kubectl get pvc -A | grep "$i" | awk '{print $1, $2, $4}')
|
||||||
app=$(echo $main | awk '{print $1}' | cut -c 4-)
|
app=$(echo "$main" | awk '{print $1}' | cut -c 4-)
|
||||||
pvc=$(echo $main | awk '{print $3}')
|
pvc=$(echo "$main" | awk '{print $3}')
|
||||||
path=$(find /*/*/ix-applications/releases/$app/volumes/ -maxdepth 0 | cut -c 6-)
|
path=$(find /*/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-)
|
||||||
zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/temporary/$i || echo "failed to unmount $i"
|
zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/temporary/"$i" || echo "failed to unmount $i"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "Invalid selection, type -h for help"
|
echo "Invalid selection, type -h for help"
|
||||||
@ -71,20 +71,20 @@ do
|
|||||||
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n$timeout is not an interger" >&2
|
! [[ $timeout =~ $re ]] && echo -e "Error: -t needs to be assigned an interger\n$timeout is not an interger" >&2
|
||||||
;;
|
;;
|
||||||
U)
|
U)
|
||||||
array=($(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep ,true,))
|
mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep ,true,)
|
||||||
[[ -z $array ]] && echo -e "\nThere are no updates available" && continue || echo -e "\n${#array[@]} update(s) available"
|
[[ -z $array ]] && echo -e "\nThere are no updates available" && continue || echo -e "\n${#array[@]} update(s) available"
|
||||||
[[ -z $timeout ]] && echo -e "\nSetting Default Timeout to 300\nChange timeout with -t" && timeout=300 || echo -e "\nTimeout was set to $timeout"
|
[[ -z $timeout ]] && echo -e "\nSetting Default Timeout to 300\nChange timeout with -t" && timeout=300 || echo -e "\nTimeout was set to $timeout"
|
||||||
for i in ${array[@]}
|
for i in "${array[@]}"
|
||||||
do
|
do
|
||||||
n=$(echo $i | awk -F ',' '{print $1}') #print out first catagory, name.
|
n=$(echo "$i" | awk -F ',' '{print $1}') #print out first catagory, name.
|
||||||
ov=$(echo $i | awk -F ',' '{print $4}') #Old version
|
ov=$(echo "$i" | awk -F ',' '{print $4}') #Old version
|
||||||
nv=$(echo $i | awk -F ',' '{print $5}') #New Version
|
nv=$(echo "$i" | awk -F ',' '{print $5}') #New Version
|
||||||
status=$(echo $i | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
status=$(echo "$i" | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
||||||
if [[ "${ignore[*]}" =~ "${n}" ]]; then
|
if [[ "${ignore[*]}" == *"${n}"* ]]; then
|
||||||
echo -e "\n$n\nIgnored, skipping"
|
echo -e "\n$n\nIgnored, skipping"
|
||||||
continue
|
continue
|
||||||
elif [[ "$status" == "STOPPED" ]]; then
|
elif [[ "$status" == "STOPPED" ]]; then
|
||||||
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'$n'"' &> /dev/null && echo -e "Updated\n$ov\n$nv\nWas Stopped, Beginning Stop Loop" && SECONDS=0 || { echo "FAILED"; continue; }
|
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'"$n"'"' &> /dev/null && echo -e "Updated\n$ov\n$nv\nWas Stopped, Beginning Stop Loop" && SECONDS=0 || { echo "FAILED"; continue; }
|
||||||
while [[ "$status" != "ACTIVE" ]]
|
while [[ "$status" != "ACTIVE" ]]
|
||||||
do
|
do
|
||||||
status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep $n | awk -F ',' '{print $2}')
|
status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep $n | awk -F ',' '{print $2}')
|
||||||
@ -95,46 +95,46 @@ do
|
|||||||
echo -e "Error: Run Time($SECONDS) has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher time with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nNot shutting down application for safety reasons, continuing to next applicaion"
|
echo -e "Error: Run Time($SECONDS) has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher time with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nNot shutting down application for safety reasons, continuing to next applicaion"
|
||||||
break
|
break
|
||||||
elif [[ "$status" == "DEPLOYING" ]]; then
|
elif [[ "$status" == "DEPLOYING" ]]; then
|
||||||
echo -e "Waiting $(($timeout-$SECONDS)) more seconds for $n to be ACTIVE" && sleep 15
|
echo -e "Waiting $((timeout-SECONDS)) more seconds for $n to be ACTIVE" && sleep 15
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
echo -e "Returing to STOPPED state.." && midclt call chart.release.scale $n '{"replica_count": 0}' &> /dev/null && echo -e "Stopped"|| echo "FAILED"
|
echo -e "Returing to STOPPED state.." && midclt call chart.release.scale "$n" '{"replica_count": 0}' &> /dev/null && echo -e "Stopped"|| echo "FAILED"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'$n'"' &> /dev/null && echo -e "Updated\n$ov\n$nv" || echo -e "FAILED"
|
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'"$n"'"' &> /dev/null && echo -e "Updated\n$ov\n$nv" || echo -e "FAILED"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
u)
|
u)
|
||||||
array=($(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep ,true,))
|
mapfile -t array < <(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep ,true,)
|
||||||
[[ -z $array ]] && echo -e "\nThere are no updates available" && continue || echo -e "\n${#array[@]} update(s) available"
|
[[ -z $array ]] && echo -e "\nThere are no updates available" && continue || echo -e "\n${#array[@]} update(s) available"
|
||||||
[[ -z $timeout ]] && echo -e "\nSetting Default Timeout to 300\nChange timeout with -t" && timeout=300 || echo -e "\nTimeout was set to $timeout"
|
[[ -z $timeout ]] && echo -e "\nSetting Default Timeout to 300\nChange timeout with -t" && timeout=300 || echo -e "\nTimeout was set to $timeout"
|
||||||
for i in ${array[@]}
|
for i in "${array[@]}"
|
||||||
do
|
do
|
||||||
n=$(echo $i | awk -F ',' '{print $1}') #print out first catagory, name.
|
n=$(echo "$i" | awk -F ',' '{print $1}') #print out first catagory, name.
|
||||||
ottv=$(echo $i | awk -F ',' '{print $4}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous Truecharts version
|
ottv=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous Truecharts version
|
||||||
nttv=$(echo $i | awk -F ',' '{print $5}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous version) #New Truecharts Version
|
nttv=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $1}' | awk -F '.' '{print $1}') #previous version) #New Truecharts Version
|
||||||
oav=$(echo $i | awk -F ',' '{print $4}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') #previous version) #New App Version
|
oav=$(echo "$i" | awk -F ',' '{print $4}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') #previous version) #New App Version
|
||||||
nav=$(echo $i | awk -F ',' '{print $5}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') #previous version) #New App Version
|
nav=$(echo "$i" | awk -F ',' '{print $5}' | awk -F '_' '{print $2}' | awk -F '.' '{print $1}') #previous version) #New App Version
|
||||||
status=$(echo $i | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
status=$(echo "$i" | awk -F ',' '{print $2}') #status of the app: STOPPED / DEPLOYING / ACTIVE
|
||||||
tt=$(diff <(echo "$ottv") <(echo "$nttv")) #caluclating difference in major Truecharts versions
|
tt=$(diff <(echo "$ottv") <(echo "$nttv")) #caluclating difference in major Truecharts versions
|
||||||
av=$(diff <(echo "$oav") <(echo "$nav")) #caluclating difference in major app versions
|
av=$(diff <(echo "$oav") <(echo "$nav")) #caluclating difference in major app versions
|
||||||
ov=$(echo $i | awk -F ',' '{print $4}') #Upgraded From
|
ov=$(echo "$i" | awk -F ',' '{print $4}') #Upgraded From
|
||||||
nv=$(echo $i | awk -F ',' '{print $5}') #Upraded To
|
nv=$(echo "$i" | awk -F ',' '{print $5}') #Upraded To
|
||||||
if [[ "${ignore[*]}" =~ "${n}" ]]; then
|
if [[ "${ignore[*]}" == *"${n}"* ]]; then
|
||||||
echo -e "\n$n\nIgnored, skipping"
|
echo -e "\n$n\nIgnored, skipping"
|
||||||
continue
|
continue
|
||||||
elif [[ "$tt" == "$av" && "$status" == "ACTIVE" || "$status" == "DEPLOYING" ]]; then
|
elif [[ "$tt" == "$av" && "$status" == "ACTIVE" || "$status" == "DEPLOYING" ]]; then
|
||||||
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'$n'"' &> /dev/null && echo -e "Updated\n$ov\n$nv" || echo "FAILED"
|
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'"$n"'"' &> /dev/null && echo -e "Updated\n$ov\n$nv" || echo "FAILED"
|
||||||
continue
|
continue
|
||||||
elif [[ "$tt" == "$av" && "$status" == "STOPPED" ]]; then
|
elif [[ "$tt" == "$av" && "$status" == "STOPPED" ]]; then
|
||||||
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'$n'"' &> /dev/null && echo -e "Updated\n$ov\n$nv\nWas Stopped, Beginning Stop Loop" && SECONDS=0 || { echo "FAILED"; continue; }
|
echo -e "\n$n\nUpdating" && cli -c 'app chart_release upgrade release_name=''"'$n'"' &> /dev/null && echo -e "Updated\n$ov\n$nv\nWas Stopped, Beginning Stop Loop" && SECONDS=0 || { echo "FAILED"; continue; }
|
||||||
while [[ "$status" != "ACTIVE" ]]
|
while [[ "$status" != "ACTIVE" ]]
|
||||||
do
|
do
|
||||||
status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep $n | awk -F ',' '{print $2}')
|
status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep "$n" | awk -F ',' '{print $2}')
|
||||||
if [[ "$status" == "STOPPED" ]]; then
|
if [[ "$status" == "STOPPED" ]]; then
|
||||||
echo -e "Stopped"
|
echo -e "Stopped"
|
||||||
break
|
break
|
||||||
@ -142,10 +142,10 @@ do
|
|||||||
echo -e "Error: Run Time($SECONDS) has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher time with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nNot shutting down application for safety reasons, continuing to next applicaion"
|
echo -e "Error: Run Time($SECONDS) has exceeded Timeout($timeout)\nIf this is a slow starting application, set a higher time with -t\nIf this applicaion is always DEPLOYING, you can disable all probes under the Healthcheck Probes Liveness section in the edit configuration\nNot shutting down application for safety reasons, continuing to next applicaion"
|
||||||
break
|
break
|
||||||
elif [[ "$status" == "DEPLOYING" ]]; then
|
elif [[ "$status" == "DEPLOYING" ]]; then
|
||||||
echo -e "Waiting $(($timeout-$SECONDS)) more seconds for $n to be ACTIVE" && sleep 15
|
echo -e "Waiting $((timeout-SECONDS)) more seconds for $n to be ACTIVE" && sleep 15
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
echo "Returing to STOPPED state.." && midclt call chart.release.scale $n '{"replica_count": 0}' &> /dev/null && echo "Stopped"|| echo -e "FAILED"
|
echo "Returing to STOPPED state.." && midclt call chart.release.scale "$n" '{"replica_count": 0}' &> /dev/null && echo "Stopped"|| echo -e "FAILED"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user