move to truetool folder

This commit is contained in:
Kjeld Schouten-Lebbing
2023-03-16 09:47:07 +01:00
parent 9d41ae3875
commit 8ac7f0fb9c
26 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,10 @@
#!/bin/bash
## Simple shortcut to just list the backups without promts and such
listBackups(){
echo -e "${BWhite}Backup Listing Tool${Color_Off}"
clear -x && echo "pulling all restore points.."
list_backups=$(cli -c 'app kubernetes list_backups' | grep -v system-update | sort -t '_' -Vr -k2,7 | tr -d " \t\r" | awk -F '|' '{print $2}' | nl | column -t)
[[ -z "$list_backups" ]] && echo -e "${IRed}No restore points available${Color_Off}" && exit || echo "Detected Backups:" && echo "$list_backups"
}
export -f listBackups

View File

@ -0,0 +1,60 @@
#!/bin/bash
helmEnable(){
echo -e "${BWhite}Enabling Helm${Color_Off}"
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml && echo -e "${IGreen}Helm Enabled${Color_Off}"|| echo -e "${IRed}Helm Enable FAILED${Color_Off}"
}
export -f helmEnable
aptEnable(){
echo -e "${BWhite}Enabling Apt-Commands${Color_Off}"
chmod +x /usr/bin/apt* && echo -e "${IGreen}APT enabled${Color_Off}"|| echo -e "${IRed}APT Enable FAILED${Color_Off}"
}
export -f aptEnable
kubeapiEnable(){
local -r comment='iX Custom Rule to drop connection requests to k8s cluster from external sources'
echo -e "${BWhite}Enabling Kubernetes API${Color_Off}"
if iptables -t filter -L INPUT 2> /dev/null | grep -q "${comment}" ; then
iptables -D INPUT -p tcp -m tcp --dport 6443 -m comment --comment "${comment}" -j DROP && echo -e "${IGreen}Kubernetes API enabled${Color_Off}"|| echo -e "${IRed}Kubernetes API Enable FAILED${Color_Off}"
else
echo -e "${IGreen}Kubernetes API already enabled${Color_Off}"
fi
}
export -f kubeapiEnable
# Prune unused docker images to prevent dataset/snapshot bloat related slowdowns on SCALE
prune(){
echo -e "🄿 🅁 🅄 🄽 🄴"
if (( "$scaleVersion" >= 22120 )); then
cli -c 'app container config prune prune_options={"remove_unused_images": true, "remove_stopped_containers": true}' | head -n -4 || echo "Failed to Prune Docker Images"
else
docker image prune -af | grep "^Total" || echo "Failed to Prune Docker Images"
fi
}
export -f prune
middlewareRestart() {
echo "We need to restart middlewared."
echo "This will cause a short downtime for the webui approximately 10-30 seconds"
echo "Restarting middlewared"
service middlewared restart &
wait $!
echo "Restarted middlewared"
}
export -f middlewareRestart
sync(){
echo_sync+=("🅂 🅈 🄽 🄲")
cli -c 'app catalog sync_all' &> /dev/null && echo_sync+=("Catalog sync complete")
#Dump the echo_array, ensures all output is in a neat order.
for i in "${echo_sync[@]}"
do
echo -e "$i"
done
echo
echo
}
export -f sync

35
truetool/includes/help.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/bash
help(){
[[ $help == "true" ]] && clear -x
echo ""
echo -e "${BWhite}Basic Utilities${Color_Off}"
echo "--mount | Initiates mounting feature, choose between unmounting and mounting PVC data"
echo "--restore | Opens a menu to restore a \"truetool\" backup that was taken on your \"ix-applications\" dataset"
echo "--delete-backup | Opens a menu to delete backups on your system"
echo "--list-backups | Prints a list of backups available"
echo "--helm-enable | Enables Helm command access on SCALE"
echo "--apt-enable | Enables Apt command access on SCALE"
echo "--kubeapi-enable | Enables external access to Kuberntes API port"
echo "--dns | List all of your applications DNS names and their web ports"
echo
echo -e "${BWhite}Update Options${Color_Off}"
echo "-U | Update all applications, ignores versions"
echo "-u | Update all applications, does not update Major releases"
echo "-b | Back-up your ix-applications dataset, specify a number after -b"
echo "-i | Add application to ignore list, one by one, see example below."
echo "-v | verbose output"
echo "-t | Set a custom timeout in seconds when checking if either an App or Mountpoint correctly Started, Stopped or (un)Mounted. Defaults to 500 seconds"
echo "-s | sync catalog"
echo "-p | Prune unused/old docker images"
echo
echo -e "${BWhite}Examples${Color_Off}"
echo "bash truetool.sh -b 14 -i portainer -i arch -i sonarr -i radarr -t 600 -vsUp"
echo "bash /mnt/tank/scripts/truetool.sh -t 150 --mount"
echo "bash /mnt/tank/scripts/truetool.sh --dns"
echo "bash /mnt/tank/scripts/truetool.sh --restore"
echo "bash /mnt/tank/scripts/truetool.sh --delete-backup"
echo
exit
}
export -f help

View File

@ -0,0 +1,57 @@
#!/bin/bash
mountPVC(){
echo -e "${BWhite}PVC Mounting Tool${Color_Off}"
clear -x
title
echo -e "1 Mount\n2 Unmount All" && read -rt 600 -p "Please type a number: " selection
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
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/ /")
echo "$list" && read -rt 120 -p "Please type a number: " selection
[[ -z "$selection" ]] && echo "Your selection cannot be empty" && exit #Check for valid selection. If none, kill script
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\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
else
echo -e "\n$app is already stopped"
fi
while [[ "$SECONDS" -le "$timeout" && "$status" != "STOPPED" ]]
do
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}')
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/truetool/$data_name" && zfs set mountpoint="/truetool/$data_name" "$full_path" && echo -e "Mounted, Use the Unmount All option to unmount\n"
exit
elif [[ $selection == "2" ]]; then
mapfile -t unmount_array < <(basename -a /mnt/truetool/* | sed "s/*//")
[[ -z ${unmount_array[*]} ]] && echo "Theres nothing to unmount" && exit
for i in "${unmount_array[@]}"
do
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}')
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 -E "dataset\s\|" | 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/truetool/"$i" || echo "${IRed}FAILED${Color_Off} to unmount $i"
else
# shellcheck disable=SC2128
zfs set mountpoint=legacy "$path""$pvc" && echo "$i unmounted" && rmdir /mnt/truetool/"$i" || echo "${IRed}FAILED${Color_Off} to unmount $i"
fi
done
rmdir /mnt/truetool
else
echo -e "${IRed}Invalid selection, \"$selection\" was not an option${Color_Off}"
fi
}
export -f mountPVC

View File

@ -0,0 +1,72 @@
#!/bin/bash
# shellcheck disable=SC2034
no_args(){
echo "0 Show Help"
echo "1 List Internal Service DNS Names"
echo "2 Mount and Unmount PVC storage for easy access"
echo "3 List Backups"
echo "4 Create a Backup"
echo "5 Restore a Backup"
echo "6 Delete a Backup"
echo "7 Enable Helm Commands"
echo "8 Enable Apt and Apt-Get Commands"
echo "9 Update All Apps"
echo "10 Enable external access to Kuberntes API port"
read -rt 600 -p "Please select an option by number: " selection
case $selection in
0)
help="true"
;;
1)
dns="true"
;;
2)
mountPVC="true"
;;
3)
listBackups="true"
;;
4)
read -rt 600 -p "Please type the max number of backups to keep: " backups
re='^[0-9]+$'
number_of_backups=$backups
! [[ $backups =~ $re ]] && echo -e "Error: -b needs to be assigned an interger\n\"""$number_of_backups""\" is not an interger" >&2 && exit
[[ "$number_of_backups" -le 0 ]] && echo "Error: Number of backups is required to be at least 1" && exit
;;
5)
restore="true"
;;
6)
deleteBackup="true"
;;
7)
helmEnable="true"
;;
8)
aptEnable="true"
;;
9)
echo ""
echo "1 Update Apps Excluding likely breaking major changes"
echo "2 Update Apps Including likely breaking major changes"
read -rt 600 -p "Please select an option by number: " updateType
if [[ "$updateType" == "1" ]]; then
update_apps="true"
elif [[ "$updateType" == "2" ]]; then
update_all_apps="true"
else
echo "INVALID ENTRY" && exit 1
fi
;;
10)
kubeapiEnable="true"
;;
*)
echo "Unknown option" && exit 1
;;
esac
echo ""
}
export -f no_args

View File

@ -0,0 +1,30 @@
#!/bin/bash
patchv22120(){
echo "Applying 22.12 HotPatch 1"
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/patch/2212/HP1.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP1.patch && echo "patch completed" || echo "Patch Already Applied" ) && rm -rf /tmp/HP1.patch
echo "Applying 22.12 HotPatch 2"
( wget -q -P /tmp https://github.com/truecharts/truetool/raw/main/patch/2212/HP2.patch && echo "download completed" || echo "download failed" ) && ( patch -N -s -p0 -d /usr/lib/python3/dist-packages/middlewared/ &>/dev/null < /tmp/HP2.patch && echo "patch completed" && restartmiddleware=yes || echo "Patch Already Applied" ) && rm -rf /tmp/HP2.patch
}
export -f patchv22120
hotpatch(){
echo "Starting hotpatcher..."
restartmiddleware=no
if (( "$scaleVersion" == 22120 )); then
patchv22120
else
echo "No hotpatch available for your version, congratulations!"
fi
if [[ "$restartmiddleware" == "yes" ]]; then
middlewareRestart
fi
restartmiddleware=no
}
export -f hotpatch

View File

@ -0,0 +1,22 @@
#!/bin/bash
# Fancy ascii title.
title(){
if [[ -z $titleShown ]]; then
echo -e "${IRed} _______ _____ _ _ ";
echo " |__ __| / ____| | | | ";
echo " | |_ __ _ _ ___| | | |__ __ _ _ __| |_ ___ ";
echo -e "${IYellow} | | '__| | | |/ _ \ | | '_ \ / _\` | '__| __/ __|";
echo " | | | | |_| | __/ |____| | | | (_| | | | |_\__ \\";
echo -e "${IGreen} __|_|_| \__,_|\___|\_____|_| |_|\__,_|_| \__|___/";
echo " |__ __| |__ __| | | ";
echo -e "${IBlue} | |_ __ _ _ ___| | ___ ___ | | ";
echo " | | '__| | | |/ _ \ |/ _ \ / _ \| | ";
echo -e "${IPurple} | | | | |_| | __/ | (_) | (_) | | ";
echo " |_|_| \__,_|\___|_|\___/ \___/|_| ";
echo " ";
echo -e "${Color_Off} ";
fi
titleShown='true'
}
export -f title

View File

@ -0,0 +1,31 @@
#!/bin/bash
## AutoUpdate TrueTool using Git
updater(){
echo -e "${BWhite}Checking for updates...${Color_Off}"
git remote set-url origin "${targetRepo}"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git fetch -q
git update-index -q --refresh
if [[ $(git status --branch --porcelain) == *"behind"* ]]; then
echo -e "${IPurple}TrueTool requires update${Color_Off}"
git reset --hard -q
git checkout -q "${BRANCH}"
git pull -q
echo "script updated"
if [[ "$CHANGED" == "true" ]]; then
echo "LOOP DETECTED, exiting"
exit 1
else
echo "restarting script after update..."
export CHANGED="true"
. "${SCRIPT_DIR}/truetool.sh" "$@"
exit
fi
else
echo -e "${IGreen}script up-to-date${Color_Off}"
export CHANGED="false"
fi
echo ""
}
export -f updater