Skip to content

Instantly share code, notes, and snippets.

@cyberofficial
Last active September 4, 2025 05:14
Show Gist options
  • Save cyberofficial/73e50bbfbffe37ad5272eac9ca977c09 to your computer and use it in GitHub Desktop.
Save cyberofficial/73e50bbfbffe37ad5272eac9ca977c09 to your computer and use it in GitHub Desktop.
My simple manager for Termux of handing simple mundane tasks
#!/bin/bash
SNAPSHOT_SUFFIX="_snapshot.tar"
main_menu() {
while true; do
echo ""
echo "== Debian Manager =="
echo " 1) Snapshot (Backup)"
echo " 2) Restore"
echo " 3) Login"
echo " 4) Danger Zone"
echo " 0) Exit"
read -rp "Select an option: " main_choice
case "$main_choice" in
1) snapshot_menu ;;
2) restore_menu ;;
3) login_menu ;;
4) danger_menu ;;
0) echo "Goodbye."; exit 0 ;;
*) echo "Invalid option." ;;
esac
done
}
snapshot_menu() {
FILE="$(date +%b%d%Y%H%M%S)${SNAPSHOT_SUFFIX}"
NOTEFILE="${FILE%.tar}.txt"
echo "Snapshot filename will be: $FILE"
while true; do
echo "Enter a note for this snapshot (optional):"
read -r note
echo ""
echo "Snapshot preview:"
echo "Filename: $FILE"
echo "Note : $note"
echo ""
echo "Proceed?"
select confirm in "Yes, make snapshot" "Redo note" "Cancel"; do
case "$confirm" in
"Yes, make snapshot")
echo "Creating snapshot..."
proot-distro backup debian --output "$FILE"
echo "$note" > "$NOTEFILE"
echo "Snapshot saved as $FILE"
echo "Note saved to $NOTEFILE"
return
;;
"Redo note") break ;;
"Cancel") echo "Snapshot canceled."; return ;;
*) echo "Invalid option." ;;
esac
done
done
}
restore_menu() {
echo "Available snapshots:"
mapfile -t files < <(ls *"$SNAPSHOT_SUFFIX" 2>/dev/null)
if [[ ${#files[@]} -eq 0 ]]; then
echo "No snapshots found."
return
fi
echo " 0) Cancel"
for i in "${!files[@]}"; do
file="${files[$i]}"
notefile="${file%.tar}.txt"
if [[ -f "$notefile" ]]; then
note=$(<"$notefile")
else
note="(No note)"
fi
printf " %d) %s - %s\n" "$((i + 1))" "$file" "$note"
done
read -rp "Enter the number of the snapshot to restore: " choice
if [[ "$choice" == "0" ]]; then
echo "Restore canceled."
return
fi
index=$((choice - 1))
if [[ $index -ge 0 && $index -lt ${#files[@]} ]]; then
echo "Restoring from ${files[$index]}"
proot-distro restore "${files[$index]}"
else
echo "Invalid choice."
fi
}
login_menu() {
echo "Login to Debian:"
select opt in "Login as root" "Login as specific user" "Cancel"; do
case "$opt" in
"Login as root")
echo "Logging in as root..."
proot-distro login debian
return
;;
"Login as specific user")
while true; do
read -rp "Enter username (or leave blank to cancel): " username
if [[ -z "$username" ]]; then
echo "Cancelled."
return
fi
echo "You entered: $username"
read -rp "Proceed with login as '$username'? [y/N]: " confirm
case "$confirm" in
[yY][eE][sS]|[yY])
echo "Logging in as user '$username'..."
proot-distro login debian --user "$username"
return
;;
[nN][oO]|[nN]|"") echo "Let's try again." ;;
*) echo "Invalid input. Please answer y or n." ;;
esac
done
;;
"Cancel") echo "Login canceled."; return ;;
*) echo "Invalid option." ;;
esac
done
}
danger_menu() {
echo ""
echo "!! DANGER ZONE !!"
echo " 1) Factory Reset Debian (Restore from freshdebian.tar)"
echo " 0) Cancel"
read -rp "Select an option: " danger_choice
case "$danger_choice" in
1)
if [[ ! -f "freshdebian.tar" ]]; then
echo "Error: freshdebian.tar not found in current directory."
return
fi
echo "Are you absolutely sure you want to restore Debian from freshdebian.tar?"
read -rp "Type YES to continue: " confirm1
if [[ "$confirm1" != "YES" ]]; then
echo "Aborted."
return
fi
read -rp "This will overwrite your current Debian environment. Type 'DELETE' to confirm again: " confirm2
if [[ "$confirm2" != "DELETE" ]]; then
echo "Aborted."
return
fi
code=$(( RANDOM % 9000 + 1000 ))
echo "Final step: To confirm, type the following number: $code"
read -rp "Enter number: " usercode
if [[ "$usercode" == "$code" ]]; then
# Take a snapshot before resetting
FILE="$(date +%b%d%Y%H%M%S)${SNAPSHOT_SUFFIX}"
NOTEFILE="${FILE%.tar}.txt"
echo "Creating automatic snapshot: $FILE"
proot-distro backup debian --output "$FILE"
echo "Before factory reset" > "$NOTEFILE"
echo "Snapshot saved as $FILE"
echo "Note saved to $NOTEFILE"
# Proceed with restore
echo "Restoring Debian from freshdebian.tar..."
proot-distro restore freshdebian.tar
echo "Debian has been reset to the fresh image."
else
echo "Incorrect code. Aborted."
fi
;;
0)
echo "Canceled."
;;
*)
echo "Invalid option."
;;
esac
}
main_menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment