2022-03-05 22:12:44 -06:00
|
|
|
#!/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"
|
|
|
|
|
|
2025-12-07 17:27:01 -06:00
|
|
|
echo "Finished exporting package names to ${FILE}"
|