mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-12-23 20:09:44 +00:00
Remove bashisms
This commit is contained in:
parent
3f6209e7f6
commit
60d4d4b380
|
@ -5,6 +5,7 @@
|
|||
RC='\033[0m'
|
||||
RED='\033[31m'
|
||||
YELLOW='\033[33m'
|
||||
CYAN='\033[36m'
|
||||
GREEN='\033[32m'
|
||||
|
||||
command_exists() {
|
||||
|
|
|
@ -68,8 +68,8 @@ setup_samba() {
|
|||
|
||||
if [ -f "$SAMBA_CONFIG" ]; then
|
||||
printf "%b\n" "${YELLOW}Samba configuration file already exists in $SAMBA_CONFIG.${RC}"
|
||||
echo "Do you want to modify the existing Samba configuration? (yes/no): "
|
||||
read MODIFY_SAMBA
|
||||
printf "Do you want to modify the existing Samba configuration? (yes/no): "
|
||||
read -r MODIFY_SAMBA
|
||||
if [ "$MODIFY_SAMBA" = "yes" ]; then
|
||||
"$ESCALATION_TOOL" "$EDITOR" "$SAMBA_CONFIG"
|
||||
fi
|
||||
|
@ -77,7 +77,7 @@ setup_samba() {
|
|||
printf "%b\n" "${YELLOW}No existing Samba configuration found. Setting up a new one...${RC}"
|
||||
|
||||
# Prompt user for shared directory path
|
||||
echo "Enter the path for the Samba share (default: /srv/samba/share): "
|
||||
printf "Enter the path for the Samba share (default: /srv/samba/share): "
|
||||
read -r SHARED_DIR
|
||||
SHARED_DIR=${SHARED_DIR:-/srv/samba/share}
|
||||
|
||||
|
@ -157,19 +157,19 @@ configure_firewall() {
|
|||
}
|
||||
|
||||
setup_ssh_samba(){
|
||||
echo "Samba and SSH Setup Script"
|
||||
echo "----------------------------"
|
||||
printf "Samba and SSH Setup Script\n"
|
||||
printf "----------------------------\n"
|
||||
clear
|
||||
|
||||
# Display menu
|
||||
echo "Select an option:"
|
||||
echo "1. Setup SSH"
|
||||
echo "2. Setup Samba"
|
||||
echo "3. Configure Firewall"
|
||||
echo "4. Setup All"
|
||||
echo "5. Exit"
|
||||
printf "Select an option:\n"
|
||||
printf "1. Setup SSH\n"
|
||||
printf "2. Setup Samba\n"
|
||||
printf "3. Configure Firewall\n"
|
||||
printf "4. Setup All\n"
|
||||
printf "5. Exit\n"
|
||||
|
||||
echo "Enter your choice [1-5]: "
|
||||
printf "Enter your choice [1-5]: "
|
||||
read CHOICE
|
||||
|
||||
case "$CHOICE" in
|
||||
|
|
|
@ -52,9 +52,9 @@ fetch_arch_older_isos() {
|
|||
|
||||
COUNTER=$((COUNTER + 1))
|
||||
done
|
||||
echo "" # New line after the last row
|
||||
|
||||
read -p "Select an Arch Linux version (1-$((COUNTER - 1))): " ARCH_OPTION
|
||||
printf "\n" # New line after the last row
|
||||
printf "Select an Arch Linux version (1-%d): " "$((COUNTER - 1))"
|
||||
read -r ARCH_OPTION
|
||||
ARCH_DIR=$(echo "$ARCH_VERSIONS" | sed -n "${ARCH_OPTION}p")
|
||||
ARCH_URL="${ARCH_BASE_URL}${ARCH_DIR}/archlinux-${ARCH_DIR}-x86_64.iso"
|
||||
printf "%b\n" "${GREEN}Selected Arch Linux (older) ISO URL: $ARCH_URL${RC}"
|
||||
|
@ -70,17 +70,19 @@ fetch_debian_latest_iso() {
|
|||
# Function to ask whether to use local or online ISO
|
||||
choose_iso_source() {
|
||||
printf "%b\n" "${YELLOW} Do you want to use a local ISO or download online? ${RC}"
|
||||
echo "1) Download online"
|
||||
echo "2) Use local ISO"
|
||||
echo ""
|
||||
read -p "Select option (1-2): " ISO_SOURCE_OPTION
|
||||
printf "1) Download online\n"
|
||||
printf "2) Use local ISO\n"
|
||||
printf "\n"
|
||||
printf "Select option (1-2): "
|
||||
read -r ISO_SOURCE_OPTION
|
||||
|
||||
case $ISO_SOURCE_OPTION in
|
||||
1)
|
||||
fetch_iso_urls # Call the function to fetch online ISO URLs
|
||||
;;
|
||||
2)
|
||||
read -p "Enter the path to the already downloaded ISO file: " ISO_PATH
|
||||
printf "Enter the path to the already downloaded ISO file: "
|
||||
read -r ISO_PATH
|
||||
if [ ! -f "$ISO_PATH" ]; then
|
||||
printf "%b\n" "${RED} ISO file not found: $ISO_PATH ${RC}"
|
||||
exit 1
|
||||
|
|
|
@ -79,8 +79,9 @@ get_unique_resolutions() {
|
|||
# Function to prompt for confirmation
|
||||
confirm_action() {
|
||||
action="$1"
|
||||
echo "$action"
|
||||
read -p "Are you sure? (y/n): " confirm
|
||||
printf "%b\n" "${CYAN}$action${RC}"
|
||||
printf "%b" "${CYAN}Are you sure? (y/n): ${RC}"
|
||||
read -r confirm
|
||||
if echo "$confirm" | grep -qE '^[Yy]$'; then
|
||||
return 0
|
||||
else
|
||||
|
|
|
@ -75,7 +75,8 @@ apply_or_remove_auto_cpufreq() {
|
|||
printf "%b\n" "${YELLOW}Do you want to apply the auto-cpufreq tweak or remove it?${RC}"
|
||||
printf "%b\n" "${YELLOW}1) Apply tweak${RC}"
|
||||
printf "%b\n" "${YELLOW}2) Remove tweak${RC}"
|
||||
read -rp "Enter your choice [1/2]: " choice
|
||||
printf "%b" "Enter your choice [1/2]: "
|
||||
read -r choice
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
|
|
|
@ -24,34 +24,36 @@ install_timeshift() {
|
|||
# Function to display the menu
|
||||
display_menu() {
|
||||
clear
|
||||
echo "Timeshift CLI Automation"
|
||||
echo "-------------------------"
|
||||
echo "1) List Snapshots"
|
||||
echo "2) List Devices"
|
||||
echo "3) Create Snapshot"
|
||||
echo "4) Restore Snapshot"
|
||||
echo "5) Delete Snapshot"
|
||||
echo "6) Delete All Snapshots"
|
||||
echo "7) Exit"
|
||||
echo ""
|
||||
printf "%b\n" "${CYAN}Timeshift CLI Automation${RC}"
|
||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
||||
printf "%b\n" "${CYAN}1) List Snapshots${RC}"
|
||||
printf "%b\n" "${CYAN}2) List Devices${RC}"
|
||||
printf "%b\n" "${CYAN}3) Create Snapshot${RC}"
|
||||
printf "%b\n" "${CYAN}4) Restore Snapshot${RC}"
|
||||
printf "%b\n" "${CYAN}5) Delete Snapshot${RC}"
|
||||
printf "%b\n" "${CYAN}6) Delete All Snapshots${RC}"
|
||||
printf "%b\n" "${CYAN}7) Exit${RC}"
|
||||
printf "%b\n" "${CYAN}\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-"
|
||||
}
|
||||
|
||||
# Function to list snapshots
|
||||
list_snapshots() {
|
||||
echo "Listing snapshots..."
|
||||
printf "%b\n" "${CYAN}Listing snapshots...${RC}"
|
||||
$ESCALATION_TOOL timeshift --list-snapshots
|
||||
}
|
||||
|
||||
# Function to list devices
|
||||
list_devices() {
|
||||
echo "Listing available devices..."
|
||||
printf "%b\n" "${CYAN}Listing available devices...${RC}"
|
||||
$ESCALATION_TOOL timeshift --list-devices
|
||||
}
|
||||
|
||||
# Function to create a new snapshot
|
||||
create_snapshot() {
|
||||
read -p "Enter a comment for the snapshot (optional): " COMMENT
|
||||
read -p "Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): " TAG
|
||||
printf "%b" "${CYAN}Enter a comment for the snapshot (optional): ${RC}"
|
||||
read -r COMMENT
|
||||
printf "%b" "${CYAN}Enter snapshot tag (O,B,H,D,W,M) (leave empty for no tag): ${RC}"
|
||||
read -r TAG
|
||||
|
||||
if [ -z "$COMMENT" ] && [ -z "$TAG" ]; then
|
||||
echo "Creating snapshot with no comment or tag..."
|
||||
|
@ -75,21 +77,25 @@ create_snapshot() {
|
|||
restore_snapshot() {
|
||||
list_snapshots
|
||||
|
||||
read -p "Enter the snapshot name you want to restore: " SNAPSHOT
|
||||
read -p "Enter the target device (e.g., /dev/sda1): " TARGET_DEVICE
|
||||
read -p "Do you want to skip GRUB reinstall? (yes/no): " SKIP_GRUB
|
||||
printf "%b" "${CYAN}Enter the snapshot name you want to restore: ${RC}"
|
||||
read -r SNAPSHOT
|
||||
printf "%b" "${CYAN}Enter the target device (e.g., /dev/sda1): ${RC}"
|
||||
read -r TARGET_DEVICE
|
||||
printf "%b" "${CYAN}Do you want to skip GRUB reinstall? (yes/no): ${RC}"
|
||||
read -r SKIP_GRUB
|
||||
|
||||
if [ "$SKIP_GRUB" = "yes" ]; then
|
||||
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --skip-grub --yes
|
||||
else
|
||||
read -p "Enter GRUB device (e.g., /dev/sda): " GRUB_DEVICE
|
||||
printf "%b" "${CYAN}Enter GRUB device (e.g., /dev/sda): ${RC}"
|
||||
read -r GRUB_DEVICE
|
||||
$ESCALATION_TOOL timeshift --restore --snapshot "$SNAPSHOT" --target-device "$TARGET_DEVICE" --grub-device "$GRUB_DEVICE" --yes
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Snapshot restored successfully."
|
||||
printf "%b\n" "${GREEN}Snapshot restored successfully.${RC}"
|
||||
else
|
||||
echo "Snapshot restore failed."
|
||||
printf "%b\n" "${RED}Snapshot restore failed.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -97,22 +103,24 @@ restore_snapshot() {
|
|||
delete_snapshot() {
|
||||
list_snapshots
|
||||
|
||||
read -p "Enter the snapshot name you want to delete: " SNAPSHOT
|
||||
printf "%b" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
|
||||
read -r SNAPSHOT
|
||||
|
||||
echo "Deleting snapshot $SNAPSHOT..."
|
||||
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
|
||||
$ESCALATION_TOOL timeshift --delete --snapshot "$SNAPSHOT" --yes
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Snapshot deleted successfully."
|
||||
printf "%b\n" "${GREEN}Snapshot deleted successfully.${RC}"
|
||||
else
|
||||
echo "Snapshot deletion failed."
|
||||
printf "%b\n" "${RED}Snapshot deletion failed.${RC}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to delete all snapshots
|
||||
delete_all_snapshots() {
|
||||
echo "WARNING: This will delete all snapshots!"
|
||||
read -p "Are you sure? (yes/no): " CONFIRMATION
|
||||
printf "%b\n" "${RED}WARNING: This will delete all snapshots!${RC}"
|
||||
printf "%b" "${CYAN}Are you sure? (yes/no): ${RC}"
|
||||
read -r CONFIRMATION
|
||||
|
||||
if [ "$CONFIRMATION" = "yes" ]; then
|
||||
echo "Deleting all snapshots..."
|
||||
|
@ -130,7 +138,8 @@ delete_all_snapshots() {
|
|||
main_menu() {
|
||||
while true; do
|
||||
display_menu
|
||||
read -p "Select an option (1-7): " OPTION
|
||||
printf "%b" "${CYAN}Select an option (1-7): ${RC}"
|
||||
read -r OPTION
|
||||
|
||||
case $OPTION in
|
||||
1) list_snapshots ;;
|
||||
|
@ -139,11 +148,11 @@ while true; do
|
|||
4) restore_snapshot ;;
|
||||
5) delete_snapshot ;;
|
||||
6) delete_all_snapshots ;;
|
||||
7) echo "Exiting..."; exit 0 ;;
|
||||
*) echo "Invalid option. Please try again." ;;
|
||||
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
|
||||
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
|
||||
esac
|
||||
|
||||
read -p "Press Enter to continue..."
|
||||
printf "%b" "${CYAN}Press Enter to continue...${RC}"
|
||||
read -r dummy
|
||||
done
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user