First commit of files to backup and restore Solus packages

This commit is contained in:
Tracey Clark 2022-03-05 22:12:44 -06:00
commit 29bcf0a4c2
2 changed files with 198 additions and 0 deletions

63
solus_package_backup.sh Executable file
View file

@ -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"