Skip to content

Commit

Permalink
enh: implement cleanup command (#34)
Browse files Browse the repository at this point in the history
* mod(rhino-pkg): Hotfix upgrade nala

v0.14.0 has affected how upgrades work within Nala, as such we have had to apply some changes to rhino-pkg to accomodate. These flags have already existed in >=v0.13.0 and so are compatible with former versions of Nala according to @volitank

* mod(rhino-pkg): Update version number
Change to version v0.1.2

* ensure flatpack is sudo'ed

* add cleanup option

* Update README.md
---------

Co-authored-by: ajstrongdev <[email protected]>
  • Loading branch information
oklopfer and ajstrongdev authored Oct 12, 2023
1 parent ea73a1c commit 5ddaba4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ functions:
update: Updates all packages accessible to the wrapper - does
not accept <input>, instead use install to update
individual packages. Has confirmation prompt.
individual packages. Has a confirmation prompt.
cleanup: Attempts to repair broken dependencies and remove any
unused packages. Does not accept <input>, but has
a confirmation prompt.
flags:
--help/-h: Display this page
--description/-d: By default, rhino-pkg will only display packages
that contain <input> within their name. Use this flag to increase
range and display packages with <input> in their description.
-y: Makes functions with confirmation prompts run promptless.
input:
Provide a package name or description.
Expand Down
71 changes: 64 additions & 7 deletions rhino-pkg
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ functions:
update: Updates all packages accessible to the wrapper - does
not accept <input>, instead use install to update
individual packages. Has confirmation prompt.
individual packages. Has a confirmation prompt.
cleanup: Attempts to repair broken dependencies and remove any
unused packages. Does not accept <input>, but has
a confirmation prompt.
flags:
--help/-h: Display this page
--description/-d: By default, $(basename $0) will only display packages
that contain <input> within their name. Use this flag to increase
range and display packages with <input> in their description.
-y: Makes functions with confirmation prompts run promptless.
input:
Provide a package name or description.
Expand Down Expand Up @@ -80,7 +86,7 @@ ${c3} ''''''''${c2}kXOM.
${c3} .,,:${c2}dXMK
${c3} ${c2}:k
$(basename "$0") 0.1.1
$(basename "$0") 0.1.2
A package manager wrapper for Pacstall, APT, Flatpak and snap
Developed by Elsie19 <[email protected]> for
the Rhino Linux distribution."
Expand Down Expand Up @@ -125,9 +131,9 @@ function search_apt() {

function search_flatpak() {
if [[ -z $DESCRIPTION ]]; then
local contents=("$(LC_ALL=C flatpak search --columns="application" "$*" | grep -i --color=never "$*")")
local contents=("$(LC_ALL=C sudo flatpak search --columns="application" "$*" | grep -i --color=never "$*")")
else
local contents=("$(LC_ALL=C flatpak search --columns="application" "$*")")
local contents=("$(LC_ALL=C sudo flatpak search --columns="application" "$*")")
fi
if [[ ${contents[*]} == "No matches found" ]]; then
return 1
Expand Down Expand Up @@ -162,6 +168,14 @@ case "${1}" in
REMOVE=true
shift
;;
cleanup)
CLEANUP=true
shift
if [[ $1 == "-y" ]]; then
PROMPTLESS=true
shift
fi
;;
update)
UPDATE=true
shift
Expand Down Expand Up @@ -202,9 +216,9 @@ if [[ -n $UPDATE ]]; then
esac
if command -v nala &> /dev/null; then
if [[ -n $PROMPTLESS ]]; then
sudo nala upgrade -y -o Acquire::AllowReleaseInfoChange="true"
sudo nala upgrade -y --full --no-autoremove -o Acquire::AllowReleaseInfoChange="true"
else
sudo nala upgrade -o Acquire::AllowReleaseInfoChange="true"
sudo nala upgrade --full --no-autoremove -o Acquire::AllowReleaseInfoChange="true"
fi
else
if [[ -n $PROMPTLESS ]]; then
Expand Down Expand Up @@ -235,6 +249,49 @@ if [[ -n $UPDATE ]]; then
exit 0
fi

if [[ -n $CLEANUP ]]; then
if [[ -n $* ]]; then
exit 1
fi
if [[ -z $PROMPTLESS ]]; then
echo -n $"Attempting to repair dependencies and remove unused packages. Continue? (${BGreen}y${NC}/${BRed}N${NC}) "
read -ra read_update
echo -ne "${NC}"
else
read_update=("Y")
fi
case "${read_update[0]}" in
Y* | y*) ;;
*) exit 1 ;;
esac
if command -v nala &> /dev/null; then
if [[ -n $PROMPTLESS ]]; then
sudo nala install --fix-broken && sudo nala autoremove -y
else
sudo nala install --fix-broken && sudo nala autoremove
fi
else
if [[ -n $PROMPTLESS ]]; then
sudo apt --fix-broken install && sudo apt auto-remove -y
else
sudo apt --fix-broken install && sudo apt auto-remove
fi
fi
if command -v flatpak &> /dev/null; then
if [[ -n $PROMPTLESS ]]; then
sudo flatpak repair && sudo flatpak uninstall --unused -y
else
sudo flatpak repair && sudo flatpak uninstall --unused
fi
fi
if command -v snap &> /dev/null; then
if [[ -z "$(LANG=C snap list --all | while read snapname ver rev trk pub notes; do if [[ "$notes" == *disabled* ]]; then sudo snap remove "$snapname" --revision="$rev"; fi; done)" ]]; then
echo "Nothing for snap to clean."
fi
fi
exit 0
fi
# Lowercase the rest of input
set -- "${*,,}"
Expand Down Expand Up @@ -341,7 +398,7 @@ esac
for i in "${entered_input[@]}"; do
case "${pkgrepo[i]}" in
flatpak)
flatpak "${flatpak_cmd}" "${pkgs[i]}" -y
sudo flatpak "${flatpak_cmd}" "${pkgs[i]}" -y
ret=$?
;;
apt)
Expand Down

0 comments on commit 5ddaba4

Please sign in to comment.