2022-07-25 02:29:58 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-08-26 04:39:26 +00:00
|
|
|
|
2022-07-25 02:29:58 +00:00
|
|
|
mount(){
|
2022-09-01 03:30:07 +00:00
|
|
|
pool=$(cli -c 'app kubernetes config' | grep -E "pool\s\|" | awk -F '|' '{print $3}' | tr -d " \t\n\r")
|
2022-07-29 04:48:22 +00:00
|
|
|
while true
|
|
|
|
do
|
|
|
|
clear -x
|
|
|
|
title
|
2022-09-02 23:28:47 +00:00
|
|
|
echo "PVC Mount Menu"
|
|
|
|
echo "--------------"
|
2022-07-29 04:48:22 +00:00
|
|
|
echo "1) Mount"
|
|
|
|
echo "2) Unmount All"
|
|
|
|
echo
|
|
|
|
echo "0) Exit"
|
2022-07-30 23:08:57 +00:00
|
|
|
read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
|
2022-07-29 04:48:22 +00:00
|
|
|
case $selection in
|
|
|
|
0)
|
|
|
|
echo "Exiting.."
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
1)
|
2022-07-29 07:53:05 +00:00
|
|
|
call=$(k3s kubectl get pvc -A | sort -u | awk '{print $1 "\t" $2 "\t" $4}' | sed "s/^0/ /")
|
2022-07-29 07:51:37 +00:00
|
|
|
mount_list=$(echo "$call" | sed 1d | nl -s ") ")
|
|
|
|
mount_title=$(echo "$call" | head -n 1)
|
2022-07-29 07:56:58 +00:00
|
|
|
list=$(echo -e "# $mount_title\n$mount_list" | column -t)
|
2022-07-29 04:48:22 +00:00
|
|
|
while true
|
2022-07-29 04:36:14 +00:00
|
|
|
do
|
2022-07-29 06:58:49 +00:00
|
|
|
clear -x
|
|
|
|
title
|
2022-07-29 04:48:22 +00:00
|
|
|
echo "$list"
|
2022-07-29 07:30:27 +00:00
|
|
|
echo
|
2022-07-29 07:56:58 +00:00
|
|
|
echo "0) Exit"
|
2022-07-30 22:43:42 +00:00
|
|
|
read -rt 120 -p "Please type a number: " selection || { echo -e "\nFailed to make a selection in time" ; exit; }
|
2022-09-01 03:51:49 +00:00
|
|
|
|
|
|
|
#Check for valid selection. If no issues, continue
|
2022-07-29 07:30:27 +00:00
|
|
|
[[ $selection == 0 ]] && echo "Exiting.." && exit
|
2022-07-29 07:56:58 +00:00
|
|
|
app=$(echo -e "$list" | grep ^"$selection)" | awk '{print $2}' | cut -c 4- )
|
2022-09-01 03:51:49 +00:00
|
|
|
[[ -z "$app" ]] && echo "Invalid Selection: $selection, was not an option" && sleep 3 && continue
|
2022-07-29 07:56:58 +00:00
|
|
|
pvc=$(echo -e "$list" | grep ^"$selection)")
|
2022-09-01 03:37:17 +00:00
|
|
|
|
|
|
|
#Stop applicaiton if not stopped
|
2022-11-02 00:55:53 +00:00
|
|
|
status=$(cli -m csv -c 'app chart_release query name,status' | grep "^$app," | awk -F ',' '{print $2}'| tr -d " \t\n\r")
|
2022-07-29 04:48:22 +00:00
|
|
|
if [[ "$status" != "STOPPED" ]]; then
|
2022-09-01 03:45:19 +00:00
|
|
|
echo -e "\nStopping $app prior to mount"
|
2022-09-01 03:43:23 +00:00
|
|
|
if ! cli -c 'app chart_release scale release_name='\""$app"\"\ 'scale_options={"replica_count": 0}' &> /dev/null; then
|
|
|
|
echo "Failed to stop $app"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Stopped"
|
|
|
|
fi
|
2022-07-29 04:48:22 +00:00
|
|
|
else
|
|
|
|
echo -e "\n$app is already stopped"
|
|
|
|
fi
|
2022-09-01 03:37:17 +00:00
|
|
|
|
2022-09-01 03:51:49 +00:00
|
|
|
#Grab data then output and mount
|
2022-07-29 04:48:22 +00:00
|
|
|
data_name=$(echo "$pvc" | awk '{print $3}')
|
|
|
|
volume_name=$(echo "$pvc" | awk '{print $4}')
|
2022-09-22 03:02:45 +00:00
|
|
|
full_path=$(zfs list -t filesystem -r "$pool"/ix-applications/releases/"$app"/volumes -o name -H | grep "$volume_name")
|
2022-09-01 03:43:23 +00:00
|
|
|
if ! zfs set mountpoint=/heavyscript/"$data_name" "$full_path" ; then
|
|
|
|
echo "Error: Failed to mount $app"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo -e "\nMounted\n$data_name"
|
|
|
|
fi
|
|
|
|
echo -e "\nUnmount with:\nzfs set mountpoint=legacy $full_path && rmdir /mnt/heavyscript/$data_name\n\nOr use the Unmount All option\n"
|
2022-09-01 03:37:17 +00:00
|
|
|
|
|
|
|
#Ask if user would like to mount something else
|
2022-07-29 04:48:22 +00:00
|
|
|
while true
|
|
|
|
do
|
2022-07-30 22:57:52 +00:00
|
|
|
echo
|
2022-07-30 23:07:28 +00:00
|
|
|
read -rt 120 -p "Would you like to mount anything else? (y/N): " yesno || { echo -e "\nFailed to make a selection in time" ; exit; }
|
2022-07-29 04:48:22 +00:00
|
|
|
case $yesno in
|
2022-07-30 22:57:52 +00:00
|
|
|
[Yy] | [Yy][Ee][Ss])
|
2022-07-29 06:52:26 +00:00
|
|
|
clear -x
|
2022-07-29 06:53:11 +00:00
|
|
|
title
|
2022-07-29 04:48:22 +00:00
|
|
|
break
|
|
|
|
;;
|
2022-07-30 22:57:52 +00:00
|
|
|
[Nn] | [Nn][Oo])
|
2022-07-29 04:48:22 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid selection \"$yesno\" was not an option"
|
2022-07-29 22:13:01 +00:00
|
|
|
sleep 3
|
2022-07-29 04:48:22 +00:00
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2022-07-29 04:36:14 +00:00
|
|
|
done
|
2022-07-29 04:48:22 +00:00
|
|
|
;;
|
|
|
|
2)
|
|
|
|
mapfile -t unmount_array < <(basename -a /mnt/heavyscript/* | sed "s/*//")
|
2022-07-29 04:52:54 +00:00
|
|
|
[[ -z ${unmount_array[*]} ]] && echo "Theres nothing to unmount" && sleep 3 && continue
|
2022-07-29 04:48:22 +00:00
|
|
|
for i in "${unmount_array[@]}"
|
2022-07-29 04:36:14 +00:00
|
|
|
do
|
2022-07-29 04:48:22 +00:00
|
|
|
main=$(k3s kubectl get pvc -A | grep -E "\s$i\s" | awk '{print $1, $2, $4}')
|
|
|
|
app=$(echo "$main" | awk '{print $1}' | cut -c 4-)
|
|
|
|
pvc=$(echo "$main" | awk '{print $3}')
|
2022-09-01 03:30:07 +00:00
|
|
|
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" || echo "failed to unmount $i"
|
2022-07-29 04:36:14 +00:00
|
|
|
done
|
2022-07-29 04:48:22 +00:00
|
|
|
rmdir /mnt/heavyscript
|
2022-07-29 22:13:01 +00:00
|
|
|
sleep 3
|
2022-07-29 04:48:22 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid selection, \"$selection\" was not an option"
|
2022-07-29 22:13:01 +00:00
|
|
|
sleep 3
|
2022-07-29 04:48:22 +00:00
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2022-07-25 02:29:58 +00:00
|
|
|
}
|
2022-07-29 05:11:09 +00:00
|
|
|
export -f mount
|