Added check where it looks if the config exists
Created an if statement which checks if a config exists, if not, then it will create one with default values which are defined in the script. Added two variables in the config, one variable for which aur-helper you wanna use and another variable where you choose if it should do the pre- and after-backups.
This commit is contained in:
		
							
								
								
									
										56
									
								
								update
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								update
									
									
									
									
									
								
							@@ -1,25 +1,42 @@
 | 
				
			|||||||
#!/bin/bash
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					 | 
				
			||||||
# updates via yay and flatpak with flags
 | 
					 | 
				
			||||||
# version 2.beta
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# shellcheck source=/dev/null
 | 
					# shellcheck source=/dev/null
 | 
				
			||||||
source ~/.config/update/update.conf
 | 
					
 | 
				
			||||||
 | 
					# updates via an aur-helper and flatpak with flags
 | 
				
			||||||
 | 
					# version 0.3
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# add options to change aur-helper in the config
 | 
				
			||||||
 | 
					# maybe make a first time setup, which asks for backup_location and aur_helper, maybe even if you wanna opt-in to non-interactive flatpak-update (maybe a flag?)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IGreen="\033[0;92m"        # Green
 | 
					IGreen="\033[0;92m"        # Green
 | 
				
			||||||
NC="\033[0m"               # Text Reset
 | 
					NC="\033[0m"               # Text Reset
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# check if config exists, if not, then a config with default values will be created
 | 
				
			||||||
 | 
					if [ -f ~/.config/update/update.conf ]; then
 | 
				
			||||||
 | 
					    source ~/.config/update/update.conf;
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
 | 
					    echo "# Backup to this folder
 | 
				
			||||||
 | 
					backup_location=~/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# use this aur-helper
 | 
				
			||||||
 | 
					aur_helper=yay
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# if you should backup or not
 | 
				
			||||||
 | 
					# should stay true unless you know what you're doing 
 | 
				
			||||||
 | 
					should_backup=true" > ~/.config/update/update.conf && echo -e "${IGreen} created config file ${NC}"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# output if wrong flag is used
 | 
					# output if wrong flag is used
 | 
				
			||||||
Help() {
 | 
					Help() {
 | 
				
			||||||
   echo "updates via yay and flatpak with flags"
 | 
					   echo "updates via an aur-helper and flatpak with flags"
 | 
				
			||||||
   echo
 | 
					   echo
 | 
				
			||||||
   echo "Usage: update [OPTION]"
 | 
					   echo "Usage: update [OPTION]"
 | 
				
			||||||
   echo
 | 
					   echo
 | 
				
			||||||
   echo "options:"
 | 
					   echo "options:"
 | 
				
			||||||
   echo "no flag    same as -a"
 | 
					   echo "no flag    same as -a"
 | 
				
			||||||
   echo "f          updates using flatpak update only"
 | 
					   echo "f          updates using flatpak update only"
 | 
				
			||||||
   echo "y          updates using yay only"
 | 
					   echo "y          updates using an aur-helper only"
 | 
				
			||||||
   echo "a          updates using flatpak update and yay"
 | 
					   echo "a          updates using flatpak update and an aur-helper"
 | 
				
			||||||
   echo "g          shutdowns the computer afterwards (needs to be the last or only option to work properly)"
 | 
					   echo "g          shutdowns the computer afterwards (needs to be the last or only option to work properly)"
 | 
				
			||||||
   echo "r          reboots the computer afterwards (needs to be the last or only option to work properly)"
 | 
					   echo "r          reboots the computer afterwards (needs to be the last or only option to work properly)"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -41,37 +58,38 @@ after_backup() {
 | 
				
			|||||||
    rsync --remove-source-files ~/after_backup.zip "$backup_location"
 | 
					    rsync --remove-source-files ~/after_backup.zip "$backup_location"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# updates using yay
 | 
					# aur-helper needs to be added to the config, which should be in /home/*/.config/update/update.conf
 | 
				
			||||||
update_with_yay() {
 | 
					# updates using aur-helper
 | 
				
			||||||
	yay
 | 
					update_with_aur_helper() {
 | 
				
			||||||
 | 
						"$aur_helper"
 | 
				
			||||||
    paclog-pkglist > ~/pacman-after.txt
 | 
					    paclog-pkglist > ~/pacman-after.txt
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# updates using flatpak update
 | 
					# updates using flatpak update
 | 
				
			||||||
update_with_flatpak() {
 | 
					update_with_flatpak() {
 | 
				
			||||||
	flatpak update --system --user
 | 
						flatpak update -uy --noninteractive
 | 
				
			||||||
    flatpak list > ~/flatpak-after.txt
 | 
					    flatpak list > ~/flatpak-after.txt
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
before_backup && echo -e "${IGreen} pre-backup complete ${NC}"
 | 
					[[ "$should_backup" = true ]] && before_backup && echo -e "${IGreen} pre-backup complete ${NC}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[ -z $1 ]] && update_with_yay && update_with_flatpak;
 | 
					[[ -z $1 ]] && update_with_aur_helper && update_with_flatpak;
 | 
				
			||||||
while getopts 'fyagr' OPTION; do
 | 
					while getopts 'fyagr' OPTION; do
 | 
				
			||||||
    case "$OPTION" in
 | 
					    case "$OPTION" in
 | 
				
			||||||
        f)
 | 
					        f)
 | 
				
			||||||
            update_with_flatpak ;;
 | 
					            update_with_flatpak ;;
 | 
				
			||||||
        y)
 | 
					        y)
 | 
				
			||||||
            update_with_yay ;;
 | 
					            update_with_aur_helper ;;
 | 
				
			||||||
        a)
 | 
					        a)
 | 
				
			||||||
            update_with_yay
 | 
					            update_with_aur_helper
 | 
				
			||||||
            update_with_flatpak ;;
 | 
					            update_with_flatpak ;;
 | 
				
			||||||
        g)
 | 
					        g)
 | 
				
			||||||
            [[ $1 = -g ]] && update_with_yay && update_with_flatpak;
 | 
					            [[ $1 = -g ]] && update_with_aur_helper && update_with_flatpak;
 | 
				
			||||||
            after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
					            after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
				
			||||||
            sleep 15s
 | 
					            sleep 15s
 | 
				
			||||||
            shutdown now ;;
 | 
					            shutdown now ;;
 | 
				
			||||||
        r)
 | 
					        r)
 | 
				
			||||||
            [[ $1 = -r ]] && update_with_yay && update_with_flatpak;
 | 
					            [[ $1 = -r ]] && update_with_aur_helper && update_with_flatpak;
 | 
				
			||||||
            after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
					            after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
				
			||||||
            sleep 5s
 | 
					            sleep 5s
 | 
				
			||||||
            reboot ;;
 | 
					            reboot ;;
 | 
				
			||||||
@@ -81,4 +99,4 @@ while getopts 'fyagr' OPTION; do
 | 
				
			|||||||
    esac
 | 
					    esac
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
					[[ "$should_backup" = true ]] && after_backup && echo -e "${IGreen} after-backup complete ${NC}"
 | 
				
			||||||
@@ -1,2 +1,9 @@
 | 
				
			|||||||
# Backup to this folder
 | 
					# Backup to this folder
 | 
				
			||||||
backup_location=/Hephaistos
 | 
					backup_location=~/balls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# use this aur-helper
 | 
				
			||||||
 | 
					aur_helper=paru
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# if you should backup or not
 | 
				
			||||||
 | 
					# should stay true unless you know what you're doing 
 | 
				
			||||||
 | 
					should_backup=false
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user