From dbfe7f2bb89ec586f96cb4c026125a8b0bcdeab2 Mon Sep 17 00:00:00 2001 From: Heavybullets8 Date: Mon, 6 Jun 2022 18:10:39 -0600 Subject: [PATCH] regex improvements --- heavy_script.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/heavy_script.sh b/heavy_script.sh index 7a8bdbce..c852fa6b 100644 --- a/heavy_script.sh +++ b/heavy_script.sh @@ -126,7 +126,7 @@ if [[ $selection == "1" ]]; then app=$(echo -e "$list" | grep ^"$selection " | awk '{print $2}' | cut -c 4- ) [[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && exit #Check for valid selection. If none, kill script pvc=$(echo -e "$list" | grep ^"$selection ") - status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "(,|^)$app(,|$)" | awk -F ',' '{print $2}'| tr -d " \t\n\r") + status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") if [[ "$status" != "STOPPED" ]]; then [[ -z $timeout ]] && echo -e "\nDefault Timeout: 500" && timeout=500 || echo -e "\nCustom Timeout: $timeout" SECONDS=0 && echo -e "\nScaling down $app" && midclt call chart.release.scale "$app" '{"replica_count": 0}' &> /dev/null @@ -135,14 +135,14 @@ if [[ $selection == "1" ]]; then fi while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]] do - status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "(,|^)$app(,|$)" | awk -F ',' '{print $2}'| tr -d " \t\n\r") + status=$(cli -m csv -c 'app chart_release query name,status' | grep -E "^$app\b" | awk -F ',' '{print $2}'| tr -d " \t\n\r") echo -e "Waiting $((timeout-SECONDS)) more seconds for $app to be STOPPED" && sleep 5 done data_name=$(echo "$pvc" | awk '{print $3}') mount=$(echo "$pvc" | awk '{print $4}') volume_name=$(echo "$pvc" | awk '{print $4}') full_path=$(zfs list | grep "$volume_name" | awk '{print $1}') - echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" && zfs set mountpoint=/heavyscript/"$data_name" "$full_path" && echo -e "Mounted\n\nUnmount with the following command\nzfs set mountpoint=legacy "$full_path" && rmdir /mnt/heavyscript/"$data_name"\nOr use the Unmount All option\n" + echo -e "\nMounting\n$full_path\nTo\n/mnt/heavyscript/$data_name" && zfs set mountpoint=/heavyscript/"$data_name" "$full_path" && echo -e "Mounted\n\nUnmount with:\nzfs set mountpoint=legacy "$full_path" && rmdir /mnt/heavyscript/"$data_name"\n\nOr use the Unmount All option\n" exit elif [[ $selection == "2" ]]; then mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//") @@ -152,15 +152,15 @@ elif [[ $selection == "2" ]]; then main=$(k3s kubectl get pvc -A | grep "$i" | awk '{print $1, $2, $4}') app=$(echo "$main" | awk '{print $1}' | cut -c 4-) pvc=$(echo "$main" | awk '{print $3}') - path=$(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) - safety_check=$(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6- | wc -l) #if theres more than one new lines, that means theres more than one application with the same name on another pool. - if [[ "$safety_check" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused. + mapfile -t path < <(find /mnt/*/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) + if [[ "${#path[@]}" -gt 1 ]]; then #if there is another app with the same name on another pool, use the current pools application, since the other instance is probably old, or unused. echo "$i is a name used on more than one pool.. attempting to use your current kubernetes apps pool" pool=$(cli -c 'app kubernetes config' | grep dataset | awk -F '|' '{print $3}' | awk -F '/' '{print $1}' | tr -d " \t\n\r") full_path=$(find /mnt/"$pool"/ix-applications/releases/"$app"/volumes/ -maxdepth 0 | cut -c 6-) zfs set mountpoint=legacy "$full_path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" && continue || echo "failed to unmount $i" + else + zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" fi - zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/heavyscript/"$i" || echo "failed to unmount $i" done rmdir /mnt/heavyscript else @@ -212,7 +212,7 @@ update_apps(){ midclt call chart.release.scale "$app_name" '{"replica_count": 0}' &> /dev/null && SECONDS=0 || echo -e "FAILED" while [[ "$status" != "STOPPED" ]] do - status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep "$app_name," | awk -F ',' '{print $2}') + status=$(cli -m csv -c 'app chart_release query name,update_available,human_version,human_latest_version,status' | grep "^$app_name," | awk -F ',' '{print $2}') if [[ "$status" == "STOPPED" ]]; then echo "Stopped" [[ "$verbose" == "true" ]] && echo "Updating.."