You are not logged in.

#1 2018-06-11 02:23:52

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

maint - automatic Arch system maintenance

Hello everyone,
Arch Linux can be a lot of work to maintain at times. I used to visit the maintenance wiki page (https://wiki.archlinux.org/index.php/System_maintenance) to look up a bunch of commands for execution every time I wanted to do any kind of system maintenance task. Now that is all fine and good, but one day I decided to streamline the whole process and just script all those commands. After that, I decided to add a bunch of features to make it even more convenient.

This project has made my Arch Linux system maintenance routine so much easier, and if it was able to help me out so much I figure that it could help some of you guys out as well.

Current Functionality:
- Get Arch Linux News
- Upgrade System (Following best practices)
- Clean Filesystem
- System Error Check
- Backup System
- Restore System

Here is a link to my GitLab repo housing the project: (check out the readme to get a bunch more information)
https://gitlab.com/mgdobachesky/ArchSystemMaintenance

Additionally, I have posted this package to the AUR under the name maint:
https://aur.archlinux.org/packages/maint/

It would be much appreciated if you guys would try it out and leave some feedback for potential improvements. (maybe even make some improvements yourself and follow up with a merge request on the GitLab repo!)

I really appreciate all of your feedback and contributions
- Mike

Last edited by mgdobachesky (2018-09-04 02:03:12)

Offline

#2 2018-06-11 02:36:16

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 26,237
Website

Re: maint - automatic Arch system maintenance

A couple of thoughts, based on a quick read.

If you are using bash, consider using [[ over [. And paccache is a more controlled approach than -Sc

Also Awk does a better job that multiple grep/tail/whatever pipes, eg:  awk '/WARNING/' /var/log/pacman.log


Moving to Community Contributions


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#3 2018-06-11 02:45:32

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Thank you jasonwryan!
On my next batch of edits I will switch over to using double square brakets instead of single, switch over to paccache, and move towards Awk instead of using multiple pipes.
All excellent suggestions for making the project much cleaner!

- Mike

Last edited by mgdobachesky (2018-06-11 03:17:10)

Offline

#4 2018-06-11 02:59:01

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 2,547

Re: maint - automatic Arch system maintenance

You have a custom function with several conditionals in order to accept a numbered list choosing which actions to perform in a loop. The whole thing could be replaced by:

PS3='Action to take: '
select opt in "Arch Linux News" "Upgrade the System" "Clean the Filesystem" "Exit"; do
    case $REPLY in
        1) fetch_news;;
        2) system_upgrade;;
        3) system_clean;;
        4) break;;
        *) echo "Please choose an existing option";;
    esac
done

Last edited by eschwartz (2018-06-11 03:00:05)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Online

#5 2018-06-11 03:16:09

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Thank you Eschwartz!
That seems like a much more efficient way to go about implementing the UI loop.
I will certainly be adding your suggestions into the next batch of updates as well!

- Mike

Last edited by mgdobachesky (2018-06-11 03:17:55)

Offline

#6 2018-06-11 16:01:48

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 1,874
Website

Re: maint - automatic Arch system maintenance

Some bikeshed assuming you want other people to use it:

https://gitlab.com/mgdobachesky/ArchSys … /run.sh#L5

Use paclog from pacutils to handle this more generally

https://gitlab.com/mgdobachesky/ArchSys … /run.sh#L7

Always quote variables in bash

https://gitlab.com/mgdobachesky/ArchSys … /run.sh#L8

Going by this segment the python script sets the exit code to the amount of news, but it always appears to be 1.

https://gitlab.com/mgdobachesky/ArchSys … run.sh#L28

Not everyone lives in US

https://gitlab.com/mgdobachesky/ArchSys … run.sh#L36

What does this do?

https://gitlab.com/mgdobachesky/ArchSys … run.sh#L57

This blindly merges changes from the AUR repo, which is a bad idea since a malicious or incompetent maintainer may take over a package

https://gitlab.com/mgdobachesky/ArchSys … run.sh#L72

You don't need to run pacman twice, just save the results (newline delimited) in an array.

mapfile -t orphans < <(pacman -Qtdq)
if [[ ${orphans[*]} ]]; then
  # print stuff 
  sudo pacman -Rns "${orphans[@]}"
fi

https://gitlab.com/mgdobachesky/ArchSys … run.sh#L82

First I'd use lower-case variables since none of these variables are exported. Otherwise this looks like an awfully complicated way to use grep:

grep -Fxvf <(aur_list) <(pacman -Qmq) | sudo pacman -Rns -

https://gitlab.com/mgdobachesky/ArchSys … un.sh#L112

Again paclog is your friend

https://gitlab.com/mgdobachesky/ArchSys … un.sh#L124

Use pacdiff, doesn't require sudo updatedb either

https://gitlab.com/mgdobachesky/ArchSys … un.sh#L137

That comment is generally wrong, see CleanMethod in pacman.conf

https://gitlab.com/mgdobachesky/ArchSys … un.sh#L143

Similar to the above on orphans you don't need to run find twice (in particular since links may have changed between both invocations)

https://gitlab.com/mgdobachesky/ArchSys … un.sh#L164

In most of the functions above that you ask if the user wants to remove something, here you run rmlint.sh without confirmation.

edit: I will add that most people will want pacutils installed anyway, due to pacrepairdb which is a tremendous help when something breaks the pacman db.

Last edited by Alad (2018-06-11 16:51:41)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

#7 2018-06-11 16:34:55

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 20,459
Website

Re: maint - automatic Arch system maintenance

If you don't want to use paclog, at very least get rid of the useless use of cat.  There is also no reason for the pipeline:

LAST_UPGRADE=$(sed -n '/pacman -Syu/h; ${x;s/.\([0-9-]*\).*/\1/p;}' /var/log/pacman.log)

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2018-06-11 23:09:30

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Thank you Alad!
Your feedback covers issues that I had not even thought of, like creating mirrorlists outside of the US and switching over to cleaner tools like paclog and pacdiff.
I am really excited for my next opportunity to start implementing these (and other) improvements!

Also, you asked what the following code does:

aur_list() {
	LIST=""
	while IFS= read -r -d $'\0'; do
		for D in $REPLY/*/; do 
			if [ -d "$D" ]; then
				LIST="${LIST},${D}"
			fi
		done
	done < <(sudo find /home -name ".aur" -print0)

	echo "${LIST:1}"
}

I keep all of my AUR packages in a directory named .aur, so I call the function above whenever I want to do anything with them in the script. (It returns a comma-separated list of absolute paths)
I know this part is a bit specific, so if I can find a more standard way to handle AUR packages then I will switch over as soon as possible.

- Mike

Last edited by mgdobachesky (2018-06-11 23:18:46)

Offline

#9 2018-06-11 23:16:35

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Thank you Trilby!
sed accomplishes the task of getting the last upgrade in a way that is so much cleaner than piping all those commands!
While I do plan on switching over to using paclog, your feedback has still given me insight as to of the better alternatives I can use in the future.

- Mike

EDIT: I ended using your sed command to avoid the pipeline afterall, atleast until I can figure out how to simplify things a bit more with paclog.

Last edited by mgdobachesky (2018-06-19 02:25:00)

Offline

#10 2018-06-12 10:36:17

Alad
Wiki Admin/IRC Op/TU
From: Bagelstan
Registered: 2014-05-04
Posts: 1,874
Website

Re: maint - automatic Arch system maintenance

I know this part is a bit specific, so if I can find a more standard way to handle AUR packages then I will switch over as soon as possible.

I'm not sure; pacaur and aurutils use AURDEST to set this directory so I guess you could use the same or a similar environment variable.

If not I'd consider following the XDG spec, e.g. XDG_DATA_HOME/aur or XDG_CACHE_HOME/aur, cf. https://wiki.archlinux.org/index.php/XD … irectories

Last edited by Alad (2018-06-12 10:36:59)


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Honest Alad's Package Emporium—Now with added bugs! (Grand reopening: December 1st 2018)

Offline

#11 2018-06-12 21:59:07

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Okay awesome, thanks for the tip!
I will probably go with AURDEST, but I will look into the pros and cons of using that over an XDG variable.

- Mike

Offline

#12 2018-09-04 00:54:16

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

Got it smile

Thankyou,
- Mike

Last edited by mgdobachesky (2018-09-15 22:02:04)

Offline

#13 2018-09-04 00:58:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 26,237
Website

Re: maint - automatic Arch system maintenance

You can edit it: use the edit button on the first post.


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Offline

#14 2018-09-04 02:04:06

mgdobachesky
Member
Registered: 2018-06-03
Posts: 17

Re: maint - automatic Arch system maintenance

I didn't realize I could do that.
Thanks for the help!

- Mike

Last edited by mgdobachesky (2018-09-15 22:03:03)

Offline

Board footer

Powered by FluxBB