Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements/optimisation to the main script, the README and the documentation #18

Merged
merged 4 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Features:
- Includes a (.desktop) clickeable icon that automatically changes to act as an update notifier/applier. Easy to integrate with any DE/WM, dock, status/launch bar, app menu, etc...
- Automatic check and listing of every packages available for update (through [checkupdates](https://archlinux.org/packages/community/x86_64/pacman-contrib/ "pacman-contrib package")), optionally shows the version changes as well.
- Offers to print the latest Arch Linux news before applying updates (through [curl](https://archlinux.org/packages/core/x86_64/curl/ "curl package") and [hq](https://archlinux.org/packages/community/x86_64/hq/ "hq package")).
- Automatic check and listing of orphan packages, offering you to remove them.
- Automatic check and listing of orphan packages and offering you to remove them.
- Helps you processing pacnew/pacsave files (through [pacdiff](https://archlinux.org/packages/community/x86_64/pacman-contrib/ "pacman-contrib package")).
- Support for both [sudo](https://archlinux.org/packages/core/x86_64/sudo/ "sudo package") and [doas](https://archlinux.org/packages/community/x86_64/opendoas/ "opendoas package").
- Optional support for AUR package updates (through [yay](https://aur.archlinux.org/packages/yay "yay AUR package") or [paru](https://aur.archlinux.org/packages/paru "paru AUR package")).
Expand Down Expand Up @@ -84,7 +84,7 @@ When the icon is clicked, it launches the main `update` function which refreshes
You can optionally configure `arch-update` to show the version changes during the package listing *(see: [Tips and tricks - Show package version changes](#show-package-version-changes))*:
![List_of_packages_with_version](https://user-images.githubusercontent.com/53110319/204068369-2da6480f-7faa-4fa1-937c-6b168ca11795.png)

Once you gave the confirmation to proceed, `arch-update` offers to print latest Arch Linux news so you can acknowledge them easily. Select which news to read by typing its associated number. After your read a news, `arch-update` will once again offers to print latest Arch Linux news, so you can read multiple news at each update. Simply press "enter" without typing any number beforehand to proceed with update:
Once you gave the confirmation to proceed, `arch-update` offers to print latest Arch Linux news so you can acknowledge them easily. Select which news to read by typing its associated number. After your read a news, `arch-update` will once again offers to print latest Arch Linux news, so you can read multiple news at once. Simply press "enter" without typing any number to proceed with update:
![Arch_news](https://user-images.githubusercontent.com/53110319/204068653-de484935-344a-4956-b134-5b4b1771360e.png)

While `arch-update` is performing updates, the icon changes accordingly:
Expand All @@ -93,10 +93,10 @@ While `arch-update` is performing updates, the icon changes accordingly:
When the update is over, the icon changes accordingly:
![Up_to_date](https://user-images.githubusercontent.com/53110319/204068822-85f19af5-f817-49b9-9a25-96c5364e61fa.png)

`arch-update` will also scan your system for orphan packages and offers to remove them (if there are):
`arch-update` will also search for orphan packages and offers to remove them (if there are):
![Orphan](https://user-images.githubusercontent.com/53110319/217640788-c4d10023-185c-49a3-a3a9-b8beb893e09f.png)

Additionally `arch-update` will scan your system for pacnew/pacsave files and offers to process them via `pacdiff` (if there are):
Additionally `arch-update` will search for pacnew/pacsave files and offers to process them via `pacdiff` (if there are):
![Pacnew](https://user-images.githubusercontent.com/53110319/217660567-f00db345-55b9-424b-9436-77492d6c00b8.png)

## Documentation
Expand All @@ -117,17 +117,17 @@ Optionnal support for AUR package updates (through [yay](https://aur.archlinux.o

### OPTIONS

If no option is passed, perform the main update function: Check for updates and print the list of packages available for update, then ask for the user's confirmation to proceed with the installation (`pacman -Syu`).
It also supports AUR package updates if [yay](https://aur.archlinux.org/packages/yay) or [paru](https://aur.archlinux.org/packages/paru) is installed.
Before performing the updates, it offers to print the latest Arch Linux news to the user.
If no option is passed, perform the main update function: Print the list of packages available for update, then ask for the user's confirmation to proceed with the installation (`pacman -Syu`).
It also supports AUR packages updates if [yay](https://aur.archlinux.org/packages/yay) or [paru](https://aur.archlinux.org/packages/paru) is installed.
Before performing the update, it offers to print the latest Arch Linux news to the user.
It also checks for orphan packages and pacnew/pacsave files and, if there are, offers to process them."

The update function is launched when you click on the (.desktop) icon.

#### -c, --check

Check for available updates and change the (.desktop) icon accordingly if there are.
It sends a desktop notification containing the number of available update if [libnotify](https://archlinux.org/packages/extra/x86_64/libnotify/) is installed.
It sends a desktop notification containing the number of available updates if [libnotify](https://archlinux.org/packages/extra/x86_64/libnotify/) is installed.
It supports AUR package updates if [yay](https://aur.archlinux.org/packages/yay) or [paru](https://aur.archlinux.org/packages/paru) is installed.
The `--check` option is automatically launched at boot and then once every hour if you enabled the `systemd.timer` with the following command:
```
Expand Down
6 changes: 3 additions & 3 deletions doc/man/arch-update.1
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ An update notifier/applier for Arch Linux that assists you with important pre/po

.SH OPTIONS
.PP
.RB "If no option is passed, perform the main " "update " "function: Check for updates and print the list of packages available for update, then ask for the user's confirmation to proceed with the installation (" "pacman -Syu" ")."
.RB "If no option is passed, perform the main " "update " "function: Print the list of packages available for update, then ask for the user's confirmation to proceed with the installation (" "pacman -Syu" ")."
.br
.RB "It also supports AUR package updates if " "yay " "or " "paru " "is installed."
.RB "It also supports AUR packages updates if " "yay " "or " "paru " "is installed."
.br
.RB "Before performing the updates, it offers to print the latest Arch Linux news to the user."
.RB "Before performing the update, it offers to print the latest Arch Linux news to the user."
.br
.RB "It also checks for orphan packages and pacnew/pacsave files and, if there are, offers to process them."
.br
Expand Down
119 changes: 67 additions & 52 deletions src/script/arch-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
exit 1
fi

#Check if an AUR helper is installed (yay or paru) for the optional AUR package updates support
#Check if an AUR helper is installed (yay or paru) for the optional AUR packages updates support
if command -v yay > /dev/null; then
aur_helper="yay"
elif command -v paru > /dev/null; then
Expand All @@ -23,42 +23,42 @@ fi
#Check if notify-send is installed for the optional desktop notification support
notif=$(command -v notify-send)

#Replace the $1 var by "option" just to make the script more readable/less complex
#Replace the $1 var by "option" just to make the script more readable
option="${1}"

case "${option}" in
#If no option is passed to the "arch-update" command, execute the main update function
#This is triggered by cliking on the desktop icon
#This is triggered by cliking on the desktop icon or by running the following command in a terminal: arch-update
"")
#Change the desktop icon to "checking"
cp -f /usr/share/icons/arch-update/arch-update_checking.svg /usr/share/icons/arch-update/arch-update.svg

#Get the available updates list for Pacman
#Get the list of available update(s) for Pacman
packages=$(checkupdates | awk '{print $1}')

#Get the available updates list for the AUR (if "yay" or "paru" is installed)
#Get the list of available update(s) for the AUR (if "yay" or "paru" is installed)
if [ -n "${aur_helper}" ]; then
aur_packages=$("${aur_helper}" -Qua | awk '{print $1}')
fi

#If there are updates available for pacman, print them
if [ -n "${packages}" ]; then
echo "--Packages--" && echo -e "${packages}\n"
echo -e "--Packages--\n${packages}\n"
fi

#If there are updates available for the AUR, print them
if [ -n "${aur_packages}" ]; then
echo "--AUR Packages--" && echo -e "${aur_packages}\n"
echo -e "--AUR Packages--\n${aur_packages}\n"
fi

#If there is no update available for Pacman nor the AUR, change the desktop icon to "up-to-date"
#If there is no update available for Pacman nor the AUR, change the desktop icon to "up-to-date" and print a relevant sentence
if [ -z "${packages}" ] && [ -z "${aur_packages}" ]; then
cp -f /usr/share/icons/arch-update/arch-update_up-to-date.svg /usr/share/icons/arch-update/arch-update.svg
echo -e "No update available\n"
#If there are updates available, change the desktop icon to "updates-available" and ask the confirmation to apply them to the user
#If there are updates available, change the desktop icon to "updates-available" and ask for the user's confirmation to proceed with the update
else
cp -f /usr/share/icons/arch-update/arch-update_updates-available.svg /usr/share/icons/arch-update/arch-update.svg
read -rp $'Proceed with installation? [Y/n] ' answer
read -rp $'Proceed with update? [Y/n] ' answer

case "${answer}" in
#If the user gives the confirmation to proceed, change the desktop icon to "installing"
Expand All @@ -80,160 +80,175 @@ case "${option}" in
((i=i+1))
done < <(printf '%s\n' "${news_title}")

#Ask the user which news he wants to read
read -rp $'\nSelect the news to read (just press \"enter\" to proceed with the installation): ' answer
#Ask the user which news to read
read -rp $'\nSelect the news to read (or just press \"enter\" to proceed with update): ' answer

case "${answer}" in
#If the user selected a news to read, print its info and content and offer to read news once again (in case the user wants to read another one)
#If the user selects a news to read, print its info and content and offer to read news once again (in case the user wants to read another one)
1|2|3|4|5)
news_selected=$(sed -n "${answer}"p <<< "${news_title}" | sed s/\ /-/g | sed s/[.]//g | awk '{print tolower($0)}')
news_info=$(curl -Ls "https://www.archlinux.org/news/${news_selected}" | hq '.article-info' text)
news_content=$(curl -Ls "https://www.archlinux.org/news/${news_selected}" | hq '.article-content' text)
echo -e "\n${news_info}\n\n${news_content}\n" && read -n 1 -r -s -p $'Press \"enter\" to continue\n'

;;

#If the user didn't select a news to read, proceed with the installation
#If the user doesn't select a news to read, proceed with update
*)
echo ""
redo="n"
;;
esac
done

#Update for pacman (if there are)
#Apply updates for Pacman (if there are)
if [ -n "${packages}" ]; then
#Launch the update and check if there was an error during the update process. If there was an error, change the desktop icon to "updates-available", print an error and quit
#Launch the update process and check for errors. If there was an error, change the desktop icon to "updates-available", print an error and quit
if ! "${su_cmd}" pacman -Syu; then
cp -f /usr/share/icons/arch-update/arch-update_updates-available.svg /usr/share/icons/arch-update/arch-update.svg
echo -e >&2 "\nAn error has occured\nUpdates have been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
echo -e >&2 "\nAn error has occured\nThe update has been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
exit 1
fi
fi

#Update for the AUR (if there are)
#Apply updates for the AUR (if there are)
if [ -n "${aur_packages}" ]; then
#Launch the update and check if there was an error during the update process. If there was an error, change the desktop icon to "updates-available", print an error and quit
#Launch the update process and check for errors. If there was an error, change the desktop icon to "updates-available", print an error and quit
if ! "${aur_helper}" -Syu; then
cp -f /usr/share/icons/arch-update/arch-update_updates-available.svg /usr/share/icons/arch-update/arch-update.svg
echo -e >&2 "\nAn error has occured\nUpdates have been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
echo -e >&2 "\nAn error has occured\nThe update has been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
exit 1
fi
fi
;;

#If the user doesn't give the confirmation to proceed, exit
#If the user doesn't give the confirmation to proceed, print an error and exit
*)
echo -e >&2 "The update has been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
exit 1
;;
esac

#If everything went well, change the desktop icon to "up-to-date"
#If everything goes well, change the desktop icon to "up-to-date"
cp -f /usr/share/icons/arch-update/arch-update_up-to-date.svg /usr/share/icons/arch-update/arch-update.svg
echo -e "\nUpdates have been applied\n"
echo -e "\nThe update has been applied\n"
fi

#Checking for orphan packages
orphan_packages=$(pacman -Qtdq)

#If there are orphan packages, ask the user's confirmation to remove them
#If there are orphan packages, print them and ask the user's confirmation to proceed with the removal
if [ -n "${orphan_packages}" ]; then
echo -e "--Orphan Packages--\n${orphan_packages}\n"
read -rp $'Would you like to remove those orphan packages (and their dependencies) now? [y/N] ' answer
echo ""

#Grammar
if [ "$(echo "${orphan_packages}" | wc -l)" -eq 1 ]; then
read -rp $'Would you like to remove this orphan package (and its potential dependencies) now? [y/N] ' answer
else
read -rp $'Would you like to remove these orphan packages (and their potential dependencies) now? [y/N] ' answer
fi

case "${answer}" in
#If the user gives the confirmation to proceed, remove orphan package(s). If an error occured during the removal process, print an error
[Yy])
pacman -Qtdq | "${su_cmd}" pacman -Rns -
echo -e "\nOrphan packages have been removed\n"
echo ""
pacman -Qtdq | "${su_cmd}" pacman -Rns - && echo -e "\nThe removal has been applied\n" || echo -e >&2 "\nAn error has occured\nThe removal has been aborted\n"
;;

#If the user doesn't give the confirmation to proceed, print a relevant sentence
*)
echo -e "Orphan packages haven't been removed\n"
echo -e "The removal hasn't been applied\n"
;;
esac
#If there's no orphan package, print a relevant sentence
else
echo -e "No orphan packages found\n"
echo -e "No orphan package found\n"
fi

#Checking for pacnew/pacsave files
pacnew_files=$(find /etc -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null)

#If there are pacnew/pacsave files, ask the user if he wants to manage them
#If there are pacnew/pacsave files, print them and ask for the user's confirmation to process them
if [ -n "${pacnew_files}" ]; then
echo -e "--Pacnew files--\n${pacnew_files}\n"
read -rp $'Would you like to process these files now? [Y/n] ' answer
echo ""
echo -e "--Pacnew Files--\n${pacnew_files}\n"

#Grammar
if [ "$(echo "${pacnew_files}" | wc -l)" -eq 1 ]; then
read -rp $'Would you like to process this file now? [Y/n] ' answer
else
read -rp $'Would you like to process these files now? [Y/n] ' answer
fi

case "${answer}" in
#If the user gives the confirmation to proceed, launch pacdiff to manage the pacnew/pacsave files
[Yy]|"")
echo ""
"${su_cmd}" pacdiff
echo -e "\nPacnew/Pacsave files have been processed\n"
echo -e "\nThe pacnew file(s) processing has been applied\n"
;;

#If the user doesn't give the confirmation to proceed, print a relevant sentence
*)
echo -e "Pacnew/Pacsave files haven't been processed\n"
echo -e "The pacnew file(s) processing hasn't been applied\n"
;;
esac
#If there's no pacnew/pacsave files, print a relevant sentence
else
echo -e "No Pacnew/Pacsave files found\n"
echo -e "No pacnew file found\n"
fi

#If everything went well, exit
#If everything goes well, exit
read -n 1 -r -s -p $'Press \"enter\" to quit\n'
exit 0
;;

#If the -c (or --check) option is passed to the "arch-update" command, execute the check function
#This is triggered by the systemd --user arch-update.service, which is automatically launched at boot and then every hour by the systemd --user arch-update.timer (that has to be enabled)
#This is triggered by the systemd --user arch-update.service, which is automatically launched at boot and then every hour by the systemd --user arch-update.timer (which has to be enabled by running the following command in a terminal: systemctl --user enable --now arch-update.timer)
-c|--check)
#Change the desktop icon to "checking"
cp -f /usr/share/icons/arch-update/arch-update_checking.svg /usr/share/icons/arch-update/arch-update.svg

#Get the number of available
#Get the number of available update(s)
if [ -n "${aur_helper}" ]; then
update_number=$( (checkupdates ; "${aur_helper}" -Qua) | wc -l)
update_number=$( (checkupdates ; "${aur_helper}" -Qua) | wc -l )
else
update_number=$(checkupdates | wc -l)
fi

#If there are updates available, change the desktop icon to "updates-available" and quit
if [ "${update_number}" -gt 0 ]; then
if [ "${update_number}" -ne 0 ]; then
cp -f /usr/share/icons/arch-update/arch-update_updates-available.svg /usr/share/icons/arch-update/arch-update.svg
#If notify-send (libnotify) is installed, also send a desktop notification before quitting
#If notify-send (libnotify) is installed, also send a desktop notification
if [ -n "${notif}" ]; then
#Grammar
if [ "${update_number}" -eq 1 ]; then
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} update available"
else
notify-send -i /usr/share/icons/arch-update/arch-update_updates-available.svg "Arch Update" "${update_number} updates available"
fi
fi
exit 0
#If there is no update available, change the desktop icon to "up-to-date" and quit
#If there is no update available, change the desktop icon to "up-to-date"
else
cp -f /usr/share/icons/arch-update/arch-update_up-to-date.svg /usr/share/icons/arch-update/arch-update.svg
exit 0
fi

exit 0
;;

#If the -v (or --version) option is passed to the "malias" command, print the current version
#If the -v (or --version) option is passed to the "arch-update" command, print the current version and quit
-v|--version)
echo "${version}"
exit 0
;;

#If the -h (or --help) option is passed to the script, print the documentation (man page)
#This can be triggered directly by the user, by typing the following command in a terminal: arch-update --help
#The documentation is also readable here https://github.com/Antiz96/Arch-Update or by typing the following command in a terminal: man arch-update
#If the -h (or --help) option is passed to the "arch-update" command, print the documentation (man page)
#The documentation is also readable here https://github.com/Antiz96/Arch-Update or by running the following command in a terminal: man arch-update
-h|--help)
#Print the documentation (man page) and quit
man arch-update | col
exit 0
;;

#If any other option(s) are passed to the script, print an error and quit
#If any other option(s) are passed to the "arch-update" command, print an error and quit
*)
echo -e >&2 "arch-update: invalid option -- '${option}'\nTry 'arch-update --help' for more information."
exit 1
Expand Down