diff --git a/solus_package_backup.sh b/solus_package_backup.sh new file mode 100755 index 0000000..c17d8c2 --- /dev/null +++ b/solus_package_backup.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +function usage { + echo "./$(basename "$0")[-h] [-v] -- Makes a list of installed packages for Solus, and saves it to ~/InstalledPackages + + where: + -h show this help text + -v Show verbose output + " +} + +function print_out { + local MESSAGE="$*" + if [[ "${VERBOSE}" == true ]];then + echo "$MESSAGE" + fi +} + +function execute { + local COMMAND="$*" + if [[ "${VERBOSE}" == true ]];then + bash -c "${COMMAND}" + fi +} + +FILE=~/InstalledPackages + +# list of arguments expected in the input +optstring=":hv" + +while getopts ${optstring} option; do + case "${option}" in + h) usage + exit + ;; + v) + VERBOSE='true' + print_out "Verbose mode is ON" + ;; + ?) + echo "Invalid option: -${OPTARG}." >&2 + echo usage >&2 + exit 1 + ;; + esac +done +shift $((OPTIND - 1)) + +print_out "Exporting all installed package names to ${FILE}" +eopkg li | cut -d " " -f 1 | tr '\n' ' ' > ${FILE} + +if [ -s "${FILE}" ]; then + print_out "${FILE} successfully written." +else + echo "${FILE} does not exist or is empty! Something went wrong. Trying to cat the file:" + + cat ~/InstalledPackages +fi + +print_out "Content of ${FILE}" +execute "cat ${FILE} && echo" + +echo "Finished exporting package names" \ No newline at end of file diff --git a/solus_package_restore.sh b/solus_package_restore.sh new file mode 100755 index 0000000..0d84255 --- /dev/null +++ b/solus_package_restore.sh @@ -0,0 +1,135 @@ +#!/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" \ No newline at end of file