#!/usr/bin/env bash function usage { echo "./$(basename "$0")[-h] [-r -d -y] -- Makes a list of installed packages for Solus, optionaly removes package cache, adds the repo specified and reinstalls packages where: -h Show this help text -b Back up list of packages even if the backup file already exists -d Delete the repo cache -r Repo to install: stable (default) or unstable -v Show verbose output Ex: Restore the unstable repo and packages solus_package_restore.sh -r unstable Make package backup, delete repo cache, restore the unstable repo and packages solus_package_restore.sh -b -d -r unstable " } function print_out { local MESSAGE="$*" if [[ "${VERBOSE}" == true ]];then echo "$MESSAGE" fi } function savepkgs { echo "Saving package list as requested" source "${FOLDER}"/solus_package_backup.sh } function delete_cache { if [[ "${DELCACHE}" == true ]];then print_out "Deleting the package cache" sudo rm -rf /var/lib/eopkg/* print_out "Rebuilding package database" sudo eopkg rdb fi } function check_repo_status { echo "Checking repo status" STABLE_STATUS=$(sudo eopkg list-repo |sed -n '/Solus \+/p') UNSTABLE_STATUS=$(sudo eopkg list-repo |sed -n '/Solus-Dev \+/p') } function install_repo { sudo eopkg ar $NAME $URL sudo eopkg enable-repo $NAME } # Set defaults FILE=~/InstalledPackages FOLDER=~/git/shell-scripts REPO=stable NAME=Solus URL=https://mirrors.rit.edu/solus/packages/shannon/eopkg-index.xml.xz # list of arguments expected in the input optstring=":hbdr:v" while getopts ${optstring} option; do case "${option}" in h) usage exit ;; b) BACKUP_PKGS='true' ;; d) DELCACHE='true' delete_cache ;; r) REPO="${OPTARG}" ;; v) VERBOSE='true' print_out "Verbose mode is ON" ;; ?) echo "Invalid option: -${OPTARG}." >&2 usage >&2 exit 1 ;; esac done shift $((OPTIND - 1)) print_out "Repo to install from: $REPO" # Export all installed packages to a text file in one line if the file does not exist if [ -f "${FILE}" ]; then print_out "Package list file ${FILE} found." else echo "${FILE} does not exist or is empty! Making a backup of packages now." savepkgs fi if [[ "${BACKUP_PKGS}" == true ]];then savepkgs fi check_repo_status # Add stable repo and enable if necessary # The stable repo should always be installed if [[ $STABLE_STATUS =~ active ]]; then print_out "Stable repo is already installed" else echo "Installing and enabling the stable repo" install_repo fi # Add unstable repo and enable based on input if [[ ${REPO} = 'unstable' ]]; then print_out "Checking the unstable repo" if [[ $UNSTABLE_STATUS =~ active ]]; then echo "Unstable repo is already installed" else echo "Installing and enabling the unstable repo, disabling the stable repo" URL=https://mirrors.rit.edu/solus/packages/unstable/eopkg-index.xml.xz NAME=Solus-Dev sudo eopkg disable-repo Solus install_repo fi fi # Upgrade sudo eopkg up # Install all previously installed packages. sudo eopkg install $(cat ${FILE}) echo "Package restore complete"