diff --git a/tabs/applications-setup/bottles-setup.sh b/tabs/applications-setup/bottles-setup.sh new file mode 100644 index 000000000..663b94727 --- /dev/null +++ b/tabs/applications-setup/bottles-setup.sh @@ -0,0 +1,36 @@ +#!/bin/sh -e + +. ../common-script.sh + +install_bottles() { + printf "%b\n" "${YELLOW}Installing Bottles...${RC}" + if ! command_exists flatpak; then + case $PACKAGER in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Syu --noconfirm flatpak + ;; + apt-get) + $ESCALATION_TOOL ${PACKAGER} update && $ESCALATION_TOOL ${PACKAGER} install -y flatpak + ;; + dnf) + $ESCALATION_TOOL ${PACKAGER} install -y flatpak + ;; + zypper) + $ESCALATION_TOOL ${PACKAGER} install flatpak + ;; + *) + printf "%b\n" "${RED}Your Linux distribution is not supported by this script.${RC}" + printf "%b\n" "${YELLOW}You can try installing Bottles using Flatpak manually:${RC}" + echo "1. Install Flatpak: https://flatpak.org/setup/" + echo "2. Install Bottles: flatpak install flathub com.usebottles.bottles" + ;; + esac + fi + flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo + flatpak install -y flathub com.usebottles.bottles + printf "%b\n" "${GREEN}Bottles installed successfully. Restart the system to apply changes...${RC}" +} + +checkEnv +checkEscalationTool +install_bottles diff --git a/tabs/system-setup/6-docker-setup.sh b/tabs/applications-setup/docker-setup.sh similarity index 100% rename from tabs/system-setup/6-docker-setup.sh rename to tabs/applications-setup/docker-setup.sh diff --git a/tabs/applications-setup/tab_data.toml b/tabs/applications-setup/tab_data.toml index ce8f1b92b..08c701aca 100644 --- a/tabs/applications-setup/tab_data.toml +++ b/tabs/applications-setup/tab_data.toml @@ -30,4 +30,12 @@ script = "zsh-setup.sh" [[data]] name = "Fastfetch" -script = "fastfetch-setup.sh" \ No newline at end of file +script = "fastfetch-setup.sh" + +[[data]] +name = "Install Bottles" +script = "bottles-setup" + +[[data]] +name = "Docker Setup" +script = "6-docker-setup.sh" \ No newline at end of file diff --git a/tabs/system-setup/7-automount.sh b/tabs/system-setup/7-automount.sh new file mode 100644 index 000000000..e7ec79297 --- /dev/null +++ b/tabs/system-setup/7-automount.sh @@ -0,0 +1,87 @@ +#!/bin/sh -e + +. ../common-script.sh + +# Function to display available drives and allow the user to select one +select_drive() { + clear + echo "Available drives and partitions:" + lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL,UUID | grep -v 'loop' # list all non-loop devices + echo "" + read -p "Enter the drive/partition name (e.g., sda1, sdb1): " drive_name + # Check if the input is valid + if lsblk | grep -q "${drive_name}"; then + partition="/dev/${drive_name}" + else + echo "Invalid drive/partition name!" + exit 1 + fi +} + +# Function to get UUID and FSTYPE of the selected drive +get_uuid_fstype() { + UUID=$(blkid -s UUID -o value "${partition}") + FSTYPE=$(lsblk -no FSTYPE "${partition}") + NAME=$(lsblk -no NAME "${partition}") + + if [ -z "$UUID" ]; then + echo "Failed to retrieve the UUID. Exiting." + exit 1 + fi + + if [ -z "$FSTYPE" ]; then + echo "Failed to retrieve the filesystem type. Exiting." + exit 1 + fi +} + +# Function to create a mount point +create_mount_point() { + read -p "Enter the mount point path (e.g., /mnt/hdd): " mount_point + if [ ! -d "$mount_point" ]; then + echo "Mount point doesn't exist. Creating it..." + $ESCALATION_TOOL mkdir -p "$mount_point" + else + echo "Mount point already exists." + fi +} + +# Function to update /etc/fstab with a comment on the first line and the actual entry on the second line +update_fstab() { + echo "Adding entry to /etc/fstab..." + $ESCALATION_TOOL cp /etc/fstab /etc/fstab.bak # Backup fstab + + # Prepare the comment and the fstab entry + comment="# Mount for /dev/$NAME" + fstab_entry="UUID=$UUID $mount_point $FSTYPE defaults 0 2" + + # Append the comment and the entry to /etc/fstab + echo "$comment" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + echo "$fstab_entry" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + echo "" | $ESCALATION_TOOL tee -a /etc/fstab > /dev/null + + echo "Entry added to /etc/fstab:" + echo "$comment" + echo "$fstab_entry" +} + + +# Function to mount the drive +mount_drive() { + echo "Mounting the drive..." + $ESCALATION_TOOL mount -a + if mount | grep "$mount_point" > /dev/null; then + echo "Drive mounted successfully at $mount_point." + else + echo "Failed to mount the drive." + exit 1 + fi +} + +checkEnv +checkEscalationTool +select_drive +get_uuid_fstype +create_mount_point +update_fstab +mount_drive diff --git a/tabs/system-setup/8-grub-theme.sh b/tabs/system-setup/8-grub-theme.sh new file mode 100644 index 000000000..428ef552b --- /dev/null +++ b/tabs/system-setup/8-grub-theme.sh @@ -0,0 +1,12 @@ +#!/bin/sh -e +. ../common-script.sh + +themeinstall(){ + cd "$HOME" && git clone "https://github.com/ChrisTitusTech/Top-5-Bootloader-Themes" + cd "Top-5-Bootloader-Themes" + $ESCALATION_TOOL ./install.sh +} + +checkEnv +checkEscalationTool +themeinstall \ No newline at end of file diff --git a/tabs/system-setup/tab_data.toml b/tabs/system-setup/tab_data.toml index c1c8f02b1..d5b2d2d13 100644 --- a/tabs/system-setup/tab_data.toml +++ b/tabs/system-setup/tab_data.toml @@ -53,5 +53,9 @@ name = "Remove Snaps" script = "4-remove-snaps.sh" [[data]] -name = "Docker Setup" -script = "6-docker-setup.sh" +name = "Automount Drive" +script = "7-automount.sh" + +[[data]] +name = "Grub Theme Setup" +script = "8-grub-theme.sh" diff --git a/tabs/utils/ssh.sh b/tabs/utils/ssh.sh new file mode 100755 index 000000000..3c8c25f19 --- /dev/null +++ b/tabs/utils/ssh.sh @@ -0,0 +1,220 @@ +#!/bin/sh -e + +. ../common-script.sh + +# Check if ~/.ssh/config exists, if not, create it +if [ ! -f ~/.ssh/config ]; then + touch ~/.ssh/config + chmod 600 ~/.ssh/config +fi + +# Function to show available hosts from ~/.ssh/config +show_available_hosts() { + echo "Available Systems:" + grep -E "^Host " ~/.ssh/config | awk '{print $2}' + echo "-------------------" +} + +# Function to ask for host details +ask_for_host_details() { + read -p "Enter Host Alias: " host_alias + read -p "Enter Remote Host (hostname or IP): " host + read -p "Enter Remote User: " user + printf "%b\n" "Host $host_alias" >> ~/.ssh/config + echo " HostName $host" >> ~/.ssh/config + echo " User $user" >> ~/.ssh/config + echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config + echo " StrictHostKeyChecking no" >> ~/.ssh/config + echo " UserKnownHostsFile=/dev/null" >> ~/.ssh/config + echo "Host $host_alias added successfully." +} + +# Function to generate SSH key if not exists +generate_ssh_key() { + if [ ! -f ~/.ssh/id_rsa ]; then + echo "SSH key not found, generating one..." + ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N "" -C "$(whoami)@$(hostname)" + else + echo "SSH key already exists." + fi +} + +# Function to share the SSH public key with the remote host +share_ssh_key() { + read -p "Enter the alias of the host to copy the key to: " host_alias + echo "Copying SSH key to $host_alias..." + ssh-copy-id "$host_alias" + echo "SSH key copied to $host_alias successfully." +} + +# Function to disable password authentication and allow only SSH keys +#repeated twice as changes should take place when in commented state or modified state. +disable_password_auth() { + echo "Disabling SSH password authentication and enabling key-only login..." + read -p "Enter the alias of the host: " host_alias + echo + ssh $host_alias " + $ESCALATION_TOOL -S sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^#PubkeyAuthentication no/PubkeyAuthentication yes/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^PubkeyAuthentication no/PubkeyAuthentication yes/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S systemctl restart sshd + " + echo "PasswordAuthentication set to no and PubkeyAuthentication set to yes." +} + +enable_password_auth() { + echo "Disabling SSH password authentication and enabling key-only login..." + read -p "Enter the alias of the host: " host_alias + echo + ssh $host_alias " + $ESCALATION_TOOL -S sed -i 's/^#PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^#PubkeyAuthentication yes/PubkeyAuthentication no/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S sed -i 's/^PubkeyAuthentication yes/PubkeyAuthentication no/' /etc/ssh/sshd_config && + $ESCALATION_TOOL -S systemctl restart sshd + " + echo "PasswordAuthentication set to yes and PubkeyAuthentication set to no." +} + +# Function to check if password authentication is disabled +check_password_auth() { + read -p "Enter the alias of the host: " host_alias + ssh $host_alias "grep '^PasswordAuthentication' /etc/ssh/sshd_config" +} + +# Function to run a command on a remote server +run_remote_command() { + read -p "Enter the alias of the host: " host_alias + read -p "Enter the command to run: " remote_command + ssh $host_alias "$remote_command" +} + +# Function to copy a file to a remote server +copy_file_to_remote() { + read -p "Enter the local file path: " local_file + read -p "Enter the alias of the host: " host_alias + read -p "Enter the remote destination path: " remote_path + scp $local_file $host_alias:$remote_path +} + +# Function to copy a directory to a remote server +copy_directory_to_remote() { + read -p "Enter the local directory path: " local_dir + read -p "Enter the alias of the host: " host_alias + read -p "Enter the remote destination path: " remote_path + scp -r $local_dir $host_alias:$remote_path +} + + +# Function to move a file to a remote server (copy and delete local) +move_file_to_remote() { + read -p "Enter the local file path: " local_file + read -p "Enter the alias of the host: " host_alias + read -p "Enter the remote destination path: " remote_path + scp $local_file $host_alias:$remote_path && rm $local_file +} + +# Function to move a directory to a remote server (copy and delete local) +move_directory_to_remote() { + read -p "Enter the local directory path: " local_dir + read -p "Enter the alias of the host: " host_alias + read -p "Enter the remote destination path: " remote_path + scp -r $local_dir $host_alias:$remote_path && rm -r $local_dir +} + +# Function to remove a system from SSH configuration +remove_system() { + read -p "Enter the alias of the host to remove: " host_alias + sed -i "/^Host $host_alias/,+3d" ~/.ssh/config + echo "Removed $host_alias from SSH configuration." +} + +# Function to view SSH configuration +view_ssh_config() { + read -p "Enter the alias of the host to view (or press Enter to view all): " host_alias + if [ -z "$host_alias" ]; then + cat ~/.ssh/config + else + grep -A 3 "^Host $host_alias" ~/.ssh/config + fi +} + +# Function to backup files from remote host +backup_files() { + read -p "Enter the alias of the host: " host_alias + read -p "Enter the files or directories to backup on remote host: " remote_files + read -p "Enter the local backup directory path: " local_backup_dir + scp -r $host_alias:$remote_files $local_backup_dir +} + +# Function to sync directories with remote host +sync_directories() { + read -p "Enter the local directory path: " local_dir + read -p "Enter the alias of the host: " host_alias + read -p "Enter the remote directory path: " remote_dir + rsync -avz $local_dir $host_alias:$remote_dir +} + +# Function to check SSH key authentication status +check_ssh_key_authentication() { + read -p "Enter the alias of the host: " host_alias + ssh $host_alias "grep '^PubkeyAuthentication' /etc/ssh/sshd_config" +} + +# Function to show options for the user +show_menu() { + echo "Select an SSH operation:" + echo "1. Add a new system" + echo "2. Connect to a system" + echo "3. Generate SSH key" + echo "4. Share SSH key with remote host" + echo "5. Disable password authentication on remote host" + echo "6. Enable password authentication on remote host" + echo "7. Check password authentication on remote host" + echo "8. Check SSH key authentication status" + echo "9. Run a command on remote host" + echo "10. Copy a file to remote host" + echo "11. Copy a directory to remote host" + echo "12. Move a file to remote host (copy and delete local)" + echo "13. Move a directory to remote host (copy and delete local)" + echo "14. Remove a system from SSH configuration" + echo "15. View SSH configuration" + echo "16. Backup files from remote host" + echo "17. Sync directories with remote host" + echo "18. Exit" + echo -n "Enter your choice: " +} + +# Function to execute the selected SSH operation +main() { + while true; do + show_menu + read choice + case $choice in + 1) ask_for_host_details ;; + 2) show_available_hosts && read -p "Enter the alias of the host to connect to: " host_alias; ssh $host_alias ;; + 3) generate_ssh_key ;; + 4) share_ssh_key ;; + 5) disable_password_auth ;; + 6) enable_password_auth ;; + 7) check_password_auth ;; + 8) check_ssh_key_authentication ;; + 9) run_remote_command ;; + 10) copy_file_to_remote ;; + 11) copy_directory_to_remote ;; + 12) move_file_to_remote ;; + 13) move_directory_to_remote ;; + 14) remove_system ;; + 15) view_ssh_config ;; + 16) backup_files ;; + 17) sync_directories ;; + 18) exit ;; + *) echo "Invalid choice. Please try again." ;; + esac +done +} + +checkEnv +checkEscalationTool +main \ No newline at end of file diff --git a/tabs/utils/tab_data.toml b/tabs/utils/tab_data.toml index bf05a1b36..680479130 100644 --- a/tabs/utils/tab_data.toml +++ b/tabs/utils/tab_data.toml @@ -12,6 +12,10 @@ script = "bluetooth-control.sh" name = "Numlock on Startup" script = "numlock.sh" +[[data]] +name = "SSH Commands" +script = "ssh.sh" + [[data]] name = "Ollama" script = "ollama.sh"