Merge pull request #465 from guruswarupa/main

brightness control(xorg) , Auto login DM, Bootable pendrive maker script, auto power profiling using auto-cpufreq, timeshift backup, samba-ssh server setup
This commit is contained in:
Chris Titus 2024-09-18 12:56:10 -05:00 committed by GitHub
commit 62093df6b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 960 additions and 3 deletions

View File

@ -5,6 +5,7 @@
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
CYAN='\033[36m'
GREEN='\033[32m'
command_exists() {

View File

@ -0,0 +1,205 @@
#!/bin/sh -e
# Load common script functions
. ../common-script.sh
# Function to install packages based on the package manager
install_package() {
PACKAGE=$1
if ! command_exists "$PACKAGE"; then
case "$PACKAGER" in
pacman)
$ESCALATION_TOOL "$PACKAGER" -S --noconfirm "$PACKAGE"
;;
*)
$ESCALATION_TOOL "$PACKAGER" install -y "$PACKAGE"
;;
esac
else
echo "$PACKAGE is already installed."
fi
}
# Function to setup and configure SSH
setup_ssh() {
printf "%b\n" "${YELLOW}Setting up SSH...${RC}"
# Detect package manager and install appropriate SSH package
case "$PACKAGER" in
"apt-get")
install_package openssh-server
SSH_SERVICE="ssh"
;;
"pacman")
install_package openssh
SSH_SERVICE="sshd"
;;
*)
install_package openssh-server
SSH_SERVICE="sshd"
;;
esac
# Enable and start the appropriate SSH service
$ESCALATION_TOOL systemctl enable "$SSH_SERVICE"
$ESCALATION_TOOL systemctl start "$SSH_SERVICE"
# Get the local IP address
LOCAL_IP=$(ip -4 addr show | awk '/inet / {print $2}' | tail -n 1)
printf "%b\n" "${GREEN}Your local IP address is: $LOCAL_IP${RC}"
# Check if SSH is running
if systemctl is-active --quiet "$SSH_SERVICE"; then
printf "%b\n" "${GREEN}SSH is up and running.${RC}"
else
printf "%b\n" "${RED}Failed to start SSH.${RC}"
fi
}
# Function to setup and configure Samba
setup_samba() {
printf "%b\n" "${YELLOW}Setting up Samba...${RC}"
# Install Samba if not installed
install_package samba
SAMBA_CONFIG="/etc/samba/smb.conf"
if [ -f "$SAMBA_CONFIG" ]; then
printf "%b\n" "${YELLOW}Samba configuration file already exists in $SAMBA_CONFIG.${RC}"
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
else
printf "%b\n" "${YELLOW}No existing Samba configuration found. Setting up a new one...${RC}"
# Prompt user for shared directory path
printf "Enter the path for the Samba share (default: /srv/samba/share): "
read -r SHARED_DIR
SHARED_DIR=${SHARED_DIR:-/srv/samba/share}
# Create the shared directory if it doesn't exist
$ESCALATION_TOOL mkdir -p "$SHARED_DIR"
$ESCALATION_TOOL chmod -R 0777 "$SHARED_DIR"
# Add a new Samba user
echo "Enter Samba username: "
read -r SAMBA_USER
# Loop until the passwords match
while true; do
echo "Enter Samba password: "
stty -echo
read -r SAMBA_PASSWORD
stty echo
echo "Confirm Samba password: "
stty -echo
read SAMBA_PASSWORD_CONFIRM
stty echo
echo ""
if [ "$SAMBA_PASSWORD" = "$SAMBA_PASSWORD_CONFIRM" ]; then
printf "%b\n" "${GREEN}Passwords match.${RC}"
break
else
printf "%b\n" "${RED}Passwords do not match. Please try again.${RC}"
fi
done
# Add the user and set the password
$ESCALATION_TOOL smbpasswd -a "$SAMBA_USER"
# Configure Samba settings
$ESCALATION_TOOL sh -c "cat > $SAMBA_CONFIG" <<EOL
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
map to guest = bad user
dns proxy = no
[Share]
path = $SHARED_DIR
browsable = yes
writable = yes
guest ok = no
read only = no
EOL
fi
# Enable and start Samba services
$ESCALATION_TOOL systemctl enable smb nmb
$ESCALATION_TOOL systemctl start smb nmb
# Check if Samba is running
if systemctl is-active --quiet smb && systemctl is-active --quiet nmb; then
printf "%b\n" "${GREEN}Samba is up and running.${RC}"
printf "%b\n" "${YELLOW}Samba share available at: $SHARED_DIR${RC}"
else
printf "%b\n" "${RED}Failed to start Samba.${RC}"
fi
}
# Function to configure firewall (optional)
configure_firewall() {
printf "%b\n" "${BLUE}Configuring firewall...${RC}"
if command_exists ufw; then
$ESCALATION_TOOL ufw allow OpenSSH
$ESCALATION_TOOL ufw allow Samba
$ESCALATION_TOOL ufw enable
printf "%b\n" "${GREEN}Firewall configured for SSH and Samba.${RC}"
else
printf "%b\n" "${YELLOW}UFW is not installed. Skipping firewall configuration.${RC}"
fi
}
setup_ssh_samba(){
printf "Samba and SSH Setup Script\n"
printf "----------------------------\n"
clear
# Display menu
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"
printf "Enter your choice [1-5]: "
read CHOICE
case "$CHOICE" in
1)
setup_ssh
;;
2)
setup_samba
;;
3)
configure_firewall
;;
4)
setup_ssh
setup_samba
configure_firewall
;;
5)
printf "%b\n" "${GREEN}Exiting.${RC}"
exit 0
;;
*)
printf "%b\n" "${RED}Invalid choice. Please enter a number between 1 and 5.${RC}"
exit 1
;;
esac
printf "%b\n" "${GREEN}Setup completed.${RC}"
}
checkEnv
checkEscalationTool
setup_ssh_samba

View File

@ -52,6 +52,10 @@ script = "3-global-theme.sh"
name = "Remove Snaps"
script = "4-remove-snaps.sh"
[[data]]
name = "SSH-Samba Setup"
script = "5-samba-ssh-setup.sh"
[[data]]
name = "Docker Setup"
script = "6-docker-setup.sh"

179
tabs/utils/auto-login.sh Normal file
View File

@ -0,0 +1,179 @@
#!/bin/sh -e
. ../common-script.sh
# Function to list common session options
list_sessions() {
echo "Select the session:"
echo "1) GNOME (gnome.desktop)"
echo "2) KDE Plasma (plasma.desktop)"
echo "3) XFCE (xfce.desktop)"
echo "4) LXDE (LXDE.desktop)"
echo "5) LXQt (lxqt.desktop)"
echo "6) Cinnamon (cinnamon.desktop)"
echo "7) MATE (mate.desktop)"
echo "8) Openbox (openbox.desktop)"
echo "9) i3 (i3.desktop)"
echo "10) Custom session"
echo "Enter your choice [1-10]: "
read session_choice
case "$session_choice" in
1) session="gnome.desktop" ;;
2) session="plasma.desktop" ;;
3) session="xfce.desktop" ;;
4) session="LXDE.desktop" ;;
5) session="lxqt.desktop" ;;
6) session="cinnamon.desktop" ;;
7) session="mate.desktop" ;;
8) session="openbox.desktop" ;;
9) session="i3.desktop" ;;
10)
echo "Enter custom session name (e.g., mysession.desktop): "
read -r session ;;
*)
echo "Invalid option selected."
exit 1 ;;
esac
}
# Function to configure LightDM
configure_lightdm() {
echo "Configuring LightDM for autologin..."
echo "Enter username for LightDM autologin: "
read -r user
$ESCALATION_TOOL "echo '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
$ESCALATION_TOOL "echo 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
$ESCALATION_TOOL "echo 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
echo "LightDM has been configured for autologin."
}
# Function to remove LightDM autologin
remove_lightdm_autologin() {
echo "Removing LightDM autologin configuration..."
$ESCALATION_TOOL rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
echo "LightDM autologin configuration has been removed."
}
# Function to configure GDM
configure_gdm() {
echo "Configuring GDM for autologin..."
echo "Enter username for GDM autologin: "
read -r user
$ESCALATION_TOOL "echo '[daemon]' > /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"
echo "GDM has been configured for autologin."
}
# Function to remove GDM autologin
remove_gdm_autologin() {
echo "Removing GDM autologin configuration..."
$ESCALATION_TOOL sed -i '/AutomaticLoginEnable/d' /etc/gdm/custom.conf
$ESCALATION_TOOL sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
echo "GDM autologin configuration has been removed."
}
# Function to configure SDDM
configure_sddm() {
echo "Configuring SDDM for autologin..."
echo "Enter username for SDDM autologin: "
read -r user
list_sessions # Show session options
$ESCALATION_TOOL "echo '[Autologin]' > /etc/sddm.conf"
$ESCALATION_TOOL "echo 'User=$user' >> /etc/sddm.conf"
$ESCALATION_TOOL "echo 'Session=$session' >> /etc/sddm.conf"
echo "SDDM has been configured for autologin."
}
# Function to remove SDDM autologin
remove_sddm_autologin() {
echo "Removing SDDM autologin configuration..."
$ESCALATION_TOOL sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
echo "SDDM autologin configuration has been removed."
}
# Function to configure LXDM
configure_lxdm() {
echo "Configuring LXDM for autologin..."
echo "Enter username for LXDM autologin: "
read -r user
list_sessions # Show session options
$ESCALATION_TOOL sed -i "s/^#.*autologin=.*$/autologin=${user}/" /etc/lxdm/lxdm.conf
$ESCALATION_TOOL sed -i "s|^#.*session=.*$|session=/usr/bin/${session}|; s|^session=.*$|session=/usr/bin/${session}|" /etc/lxdm/lxdm.conf
echo "LXDM has been configured for autologin."
}
# Function to remove LXDM autologin
remove_lxdm_autologin() {
echo "Removing LXDM autologin configuration..."
$ESCALATION_TOOL sed -i "s/^autologin=.*$/#autologin=/" /etc/lxdm/lxdm.conf
$ESCALATION_TOOL sed -i "s/^session=.*$/#session=/" /etc/lxdm/lxdm.conf
echo "LXDM autologin configuration has been removed."
}
# Function to configure or remove autologin based on user choice
configure_or_remove_autologin() {
echo "Do you want to add or remove autologin?"
echo "1) Add autologin"
echo "2) Remove autologin"
echo "Enter your choice [1-2]: "
read action_choice
if [ "$action_choice" = "1" ]; then
echo "Choose the display manager to configure:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
read choice
case "$choice" in
1) configure_lightdm ;;
2) configure_gdm ;;
3) configure_sddm ;;
4) configure_lxdm ;;
*) echo "Invalid option selected." ;;
esac
elif [ "$action_choice" = "2" ]; then
echo "Choose the display manager to remove autologin:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
read choice
case "$choice" in
1) remove_lightdm_autologin ;;
2) remove_gdm_autologin ;;
3) remove_sddm_autologin ;;
4) remove_lxdm_autologin ;;
*) echo "Invalid option selected." ;;
esac
else
echo "Invalid choice. Exiting..."
exit 1
fi
echo "Action completed. Exiting..."
exit 0
}
checkEnv
checkEscalationTool
configure_or_remove_autologin

View File

@ -0,0 +1,193 @@
#!/bin/sh -e
. ../common-script.sh
# Function to display usage instructions
usage() {
printf "%b\n" "${RED} Usage: $0 ${RC}"
echo "No arguments needed. The script will prompt for ISO path and USB device."
exit 1
}
# Function to display all available block devices
list_devices() {
printf "%b\n" "${YELLOW} Available devices and partitions: ${RC}"
echo ""
$ESCALATION_TOOL lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
echo ""
}
# Function to fetch the latest Arch Linux ISO
fetch_arch_latest_iso() {
ARCH_BASE_URL="https://archive.archlinux.org/iso/"
ARCH_LATEST=$(curl -s "$ARCH_BASE_URL" | grep -oP '(?<=href=")[0-9]{4}\.[0-9]{2}\.[0-9]{2}(?=/)' | sort -V | tail -1)
ARCH_URL="${ARCH_BASE_URL}${ARCH_LATEST}/archlinux-${ARCH_LATEST}-x86_64.iso"
printf "%b\n" "${GREEN} Selected Arch Linux (latest) ISO URL: ${RC} $ARCH_URL"
}
# Function to fetch older Arch Linux ISOs and display in a table format
fetch_arch_older_isos() {
ARCH_BASE_URL="https://archive.archlinux.org/iso/"
ARCH_VERSIONS=$(curl -s "$ARCH_BASE_URL" | grep -oP '(?<=href=")[0-9]{4}\.[0-9]{2}\.[0-9]{2}(?=/)' | sort -V)
# Filter versions to include only those from 2017-04-01 and later
MIN_DATE="2017.04.01"
ARCH_VERSIONS=$(echo "$ARCH_VERSIONS" | awk -v min_date="$MIN_DATE" '$0 >= min_date')
if [ -z "$ARCH_VERSIONS" ]; then
printf "%b\n" "${RED}No Arch Linux versions found from ${MIN_DATE} onwards.${RC}"
exit 1
fi
printf "%b\n" "${YELLOW}Available Arch Linux versions from ${MIN_DATE} onwards:${RC}"
COUNTER=1
ROW_ITEMS=6 # Number of versions to show per row
for VERSION in $ARCH_VERSIONS; do
printf "%-5s${YELLOW}%-15s ${RC}" "$COUNTER)" "$VERSION"
if [ $(( COUNTER % ROW_ITEMS )) -eq 0 ]; then
echo "" # New line after every 6 versions
fi
COUNTER=$((COUNTER + 1))
done
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}"
}
# Function to fetch the latest Debian Linux ISO
fetch_debian_latest_iso() {
DEBIAN_URL=$(curl -s https://www.debian.org/distrib/netinst | grep -oP '(?<=href=")[^"]+debian-[0-9.]+-amd64-netinst.iso(?=")' | head -1)
printf "%b\n" "${GREEN} Selected Debian Linux (latest) ISO URL: ${RC} $DEBIAN_URL"
}
# 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}"
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)
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
fi
;;
*)
printf "%b\n" "${RED}Invalid option selected. ${RC}"
exit 1
;;
esac
}
# Function to fetch ISO URLs
fetch_iso_urls() {
clear
printf "%b\n" "${YELLOW}Available ISOs for download:${RC}"
echo "1) Arch Linux (latest)"
echo "2) Arch Linux (older versions)"
echo "3) Debian Linux (latest)"
echo ""
read -p "Select the ISO you want to download (1-3): " ISO_OPTION
case $ISO_OPTION in
1)
fetch_arch_latest_iso
ISO_URL=$ARCH_URL
;;
2)
fetch_arch_older_isos
ISO_URL=$ARCH_URL
;;
3)
fetch_debian_latest_iso
ISO_URL=$DEBIAN_URL
;;
*)
printf "%b\n" "${RED}Invalid option selected.${RC}"
exit 1
;;
esac
ISO_PATH=$(basename "$ISO_URL")
printf "%b\n" "${YELLOW}Downloading ISO...${RC}"
curl -L -o "$ISO_PATH" "$ISO_URL"
if [ $? -ne 0 ]; then
printf "%b\n" "${RED}Failed to download the ISO file.${RC}"
exit 1
fi
}
write_iso(){
clear
# Ask whether to use a local or online ISO
choose_iso_source
clear
# Display all available devices
list_devices
# Prompt user for USB device
read -p "Enter the USB device (e.g., /dev/sdX): " USB_DEVICE
# Verify that the USB device exists
if [ ! -b "$USB_DEVICE" ]; then
printf "%b\n" "${RED}USB device not found: $USB_DEVICE${RC}"
exit 1
fi
# Confirm the device selection with the user
printf "%b\n" "${RED}WARNING: This will erase all data on ${USB_DEVICE}. Are you sure you want to continue? (yes/no)${RC}"
read -r CONFIRMATION
if [ "$CONFIRMATION" != "yes" ]; then
printf "%b\n" "${YELLOW}Operation cancelled.${RC}"
exit 1
fi
# Display progress and create the bootable USB drive
printf "%b\n" "${YELLOW}Creating bootable USB drive...${RC}"
if ! $ESCALATION_TOOL dd if="$ISO_PATH" of="$USB_DEVICE" bs=4M status=progress oflag=sync; then
printf "%b\n" "${RED}Failed to create bootable USB drive${RC}"
exit 1
fi
# Sync to ensure all data is written
if ! $ESCALATION_TOOL sync; then
printf "%b\n" "${RED}Failed to sync data${RC}"
exit 1
fi
printf "%b\n" "${GREEN}Bootable USB drive created successfully!${RC}"
# Eject the USB device
printf "%b\n" "${YELLOW}Ejecting ${USB_DEVICE}...${RC}"
if ! $ESCALATION_TOOL umount "${USB_DEVICE}"* 2>/dev/null; then
printf "%b\n" "${RED}Failed to unmount ${USB_DEVICE}${RC}"
fi
if ! $ESCALATION_TOOL eject "$USB_DEVICE"; then
printf "%b\n" "${RED}Failed to eject ${USB_DEVICE}${RC}"
fi
printf "%b\n" "${GREEN}You can safely remove your USB drive. Reinsert the drive to be detected.${RC}"
}
checkEnv
checkEscalationTool
write_iso

View File

@ -0,0 +1,85 @@
#!/bin/sh -e
. ./utility_functions.sh
# Function to adjust brightness for a selected monitor
adjust_monitor_brightness() {
while true; do
monitor_list=$(detect_connected_monitors)
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
set -- $monitor_array
count=1
clear
printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW} Adjust Monitor Brightness${RC}"
printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW}Choose a monitor to adjust brightness:${RC}"
for monitor in "$@"; do
echo "$count. $monitor"
count=$((count + 1))
done
echo "Enter the number of the monitor (or 'q' to quit): "
read monitor_choice
if [ "$monitor_choice" = "q" ]; then
printf "%b\n" "${RED}Exiting...${RC}"
return
fi
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$'; then
echo "Invalid selection. Please try again."
echo "Press [Enter] to continue..."
read dummy
continue
fi
if [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$#" ]; then
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
echo "Press [Enter] to continue..."
read dummy
continue
fi
monitor_name=$(eval echo "\${$monitor_choice}")
current_brightness=$(get_current_brightness "$monitor_name")
# Correctly calculate the brightness percentage
current_brightness_percentage=$(awk "BEGIN {printf \"%.0f\", $current_brightness * 100}")
printf "%b\n" "${YELLOW}Current brightness for $monitor_name${RC}: ${GREEN}$current_brightness_percentage%${RC}"
while true; do
echo "Enter the new brightness value as a percentage (10 to 100, or 'q' to quit): "
read new_brightness_percentage
if [ "$new_brightness_percentage" = "q" ]; then
printf "%b\n" "${RED}Exiting...${RC}"
return
fi
# Validate brightness input: accept only values above 10
if ! echo "$new_brightness_percentage" | grep -qE '^[0-9]+$' || [ "$new_brightness_percentage" -lt 10 ] || [ "$new_brightness_percentage" -gt 100 ]; then
printf "%b\n" "${RED}Invalid brightness value. Please enter a value between 10 and 100.${RC}"
continue
fi
# Convert percentage to xrandr brightness value (10% to 0.10)
new_brightness=$(awk "BEGIN {printf \"%.2f\", $new_brightness_percentage / 100}")
echo "Set brightness for $monitor_name to $new_brightness_percentage%? (y/n): "
read confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]; then
printf "%b\n" "${GREEN}Setting brightness for $monitor_name to $new_brightness_percentage%${RC}"
execute_command "xrandr --output $monitor_name --brightness $new_brightness"
printf "%b\n" "${GREEN}Brightness for $monitor_name set to $new_brightness_percentage% successfully.${RC}"
break
else
printf "%b\n" "${RED}Action canceled. Please choose a different brightness value.${RC}"
fi
done
done
}
# Call the adjust_monitor_brightness function
adjust_monitor_brightness

View File

@ -38,6 +38,12 @@ detect_connected_monitors() {
echo "$xrandr_output" | grep " connected" | awk '{print $1}'
}
# Function to get the current brightness for a monitor
get_current_brightness() {
monitor="$1"
xrandr --verbose | grep -A 10 "^$monitor connected" | grep "Brightness:" | awk '{print $2}'
}
# Function to get resolutions for a monitor
get_unique_resolutions() {
monitor="$1"
@ -73,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

100
tabs/utils/power-profile.sh Normal file
View File

@ -0,0 +1,100 @@
#!/bin/sh -e
. ../common-script.sh
installAutoCpufreq() {
clear
printf "%b\n" "${YELLOW}Checking if auto-cpufreq is already installed...${RC}"
# Check if auto-cpufreq is already installed
if command_exists auto-cpufreq; then
printf "%b\n" "${GREEN}auto-cpufreq is already installed.${RC}"
else
printf "%b\n" "${YELLOW}Installing auto-cpufreq...${RC}"
# Install git if not already installed
if ! command_exists git; then
printf "%b\n" "${YELLOW}git not found. Installing git...${RC}"
case ${PACKAGER} in
pacman)
$ESCALATION_TOOL ${PACKAGER} -S --needed --noconfirm git
;;
*)
$ESCALATION_TOOL ${PACKAGER} install -y git
;;
esac
fi
# Clone the auto-cpufreq repository and run the installer
if [ ! -d "auto-cpufreq" ]; then
printf "%b\n" "${YELLOW}Cloning auto-cpufreq repository...${RC}"
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
fi
case ${PACKAGER} in
*)
cd auto-cpufreq
printf "%b\n" "${YELLOW}Running auto-cpufreq installer...${RC}"
$ESCALATION_TOOL ./auto-cpufreq-installer
;;
esac
cd ..
fi
}
configureAutoCpufreq() {
printf "%b\n" "${YELLOW}Configuring auto-cpufreq...${RC}"
if command_exists auto-cpufreq; then
# Check if the system has a battery to determine if it's a laptop
if [ -d /sys/class/power_supply/BAT0 ]; then
printf "%b\n" "${GREEN}System detected as laptop. Updating auto-cpufreq for laptop...${RC}"
$ESCALATION_TOOL auto-cpufreq --force powersave
else
printf "%b\n" "${GREEN}System detected as desktop. Updating auto-cpufreq for desktop...${RC}"
$ESCALATION_TOOL auto-cpufreq --force performance
fi
else
printf "%b\n" "${RED}auto-cpufreq is not installed, skipping configuration.${RC}"
fi
}
removeAutoCpufreqTweak() {
printf "%b\n" "${YELLOW}Removing auto-cpufreq tweak...${RC}"
if command_exists auto-cpufreq; then
printf "%b\n" "${YELLOW}Resetting auto-cpufreq configuration...${RC}"
$ESCALATION_TOOL auto-cpufreq --force reset
else
printf "%b\n" "${RED}auto-cpufreq is not installed, skipping removal.${RC}"
fi
}
apply_or_remove_auto_cpufreq() {
# Prompt user for action
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}"
printf "%b" "Enter your choice [1/2]: "
read -r choice
case $choice in
1)
configureAutoCpufreq
;;
2)
removeAutoCpufreqTweak
;;
*)
printf "%b\n" "${RED}Invalid choice. Exiting.${RC}"
exit 1
;;
esac
printf "%b\n" "${GREEN}auto-cpufreq setup complete.${RC}"
}
checkEnv
checkEscalationTool
installAutoCpufreq
apply_or_remove_auto_cpufreq

View File

@ -20,6 +20,22 @@ script = "ollama.sh"
name = "Service Manager"
script = "service-control.sh"
[[data]]
name = "Auto Login"
script = "auto-login.sh"
[[data]]
name = "Bootable USB Creator"
script = "create-bootable-usb.sh"
[[data]]
name = "Auto Power Profiling"
script = "power-profile.sh"
[[data]]
name = "Timeshift Backup"
script = "timeshift.sh"
[[data]]
name = "Monitor Control"
@ -73,3 +89,8 @@ script = "monitor-control/scale_monitor.sh"
name = "Reset Scaling"
script = "monitor-control/reset_scaling.sh"
matches = true
[[data.entries]]
name = "Set Brightness"
script = "monitor-control/set_brightness.sh"
matches = true

162
tabs/utils/timeshift.sh Normal file
View File

@ -0,0 +1,162 @@
#!/bin/sh -e
. ../common-script.sh
# Function to install Timeshift
install_timeshift() {
clear
printf "%b\n" "${YELLOW}Checking if Timeshift is installed...${RC}"
if ! command_exists timeshift; then
case ${PACKAGER} in
pacman)
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm timeshift
;;
*)
$ESCALATION_TOOL "${PACKAGER}" install -y timeshift
;;
esac
else
echo "Timeshift is already installed."
fi
}
# Function to display the menu
display_menu() {
clear
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() {
printf "%b\n" "${CYAN}Listing snapshots...${RC}"
$ESCALATION_TOOL timeshift --list-snapshots
}
# Function to list devices
list_devices() {
printf "%b\n" "${CYAN}Listing available devices...${RC}"
$ESCALATION_TOOL timeshift --list-devices
}
# Function to create a new snapshot
create_snapshot() {
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..."
$ESCALATION_TOOL timeshift --create
elif [ -z "$TAG" ]; then
echo "Creating snapshot with no tag..."
$ESCALATION_TOOL timeshift --create --comments "$COMMENT"
else
echo "Creating snapshot with tag: $TAG..."
$ESCALATION_TOOL timeshift --create --comments "$COMMENT" --tags "$TAG"
fi
if [ $? -eq 0 ]; then
echo "Snapshot created successfully."
else
echo "Snapshot creation failed."
fi
}
# Function to restore a snapshot
restore_snapshot() {
list_snapshots
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
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
printf "%b\n" "${GREEN}Snapshot restored successfully.${RC}"
else
printf "%b\n" "${RED}Snapshot restore failed.${RC}"
fi
}
# Function to delete a snapshot
delete_snapshot() {
list_snapshots
printf "%b" "${CYAN}Enter the snapshot name you want to delete: ${RC}"
read -r SNAPSHOT
printf "%b\n" "${YELLOW}Deleting snapshot $SNAPSHOT...${RC}"
$ESCALATION_TOOL timeshift --delete --snapshot "$SNAPSHOT" --yes
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}Snapshot deleted successfully.${RC}"
else
printf "%b\n" "${RED}Snapshot deletion failed.${RC}"
fi
}
# Function to delete all snapshots
delete_all_snapshots() {
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..."
$ESCALATION_TOOL timeshift --delete-all --yes
if [ $? -eq 0 ]; then
printf "%b\n" "${GREEN}All snapshots deleted successfully.${RC}"
else
printf "%b\n" "${RED}Failed to delete snapshots.${RC}"
fi
else
printf "%b\n" "${RED}Operation cancelled.${RC}"
fi
}
main_menu() {
while true; do
display_menu
printf "%b" "${CYAN}Select an option (1-7): ${RC}"
read -r OPTION
case $OPTION in
1) list_snapshots ;;
2) list_devices ;;
3) create_snapshot ;;
4) restore_snapshot ;;
5) delete_snapshot ;;
6) delete_all_snapshots ;;
7) printf "%b\n" "${GREEN}Exiting...${RC}"; exit 0 ;;
*) printf "%b\n" "${RED}Invalid option. Please try again.${RC}" ;;
esac
printf "%b" "${CYAN}Press Enter to continue...${RC}"
read -r dummy
done
}
checkEnv
checkEscalationTool
install_timeshift
main_menu