diff --git a/README.md b/README.md index 1207020..5cac386 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,2 @@ # Scripts Scripts for managing Arch Linux servers - -## Overview - -### User management - -The `adduser`, `deluser`, and `moduser` scripts are convenience wrappers around `ldapadd`, `ldapdel`, and `ldapvi`. - -### upgrade -Upgrades the system, all AUR packages, and Nextcloud. - -### backup -Creates an incremental system backup using `bup`. - -### setid -Sets up the `/etc/subuid` and `/etc/subgid` files for [rootless Podman](https://wiki.archlinux.org/title/Podman#Set_subuid_and_subgid). - -### sysusers -A script that compares the `/usr/lib/sysusers.d` directory and output of `getent passwd` to find unneeded users. - -### synapse-rm -A command-line wrapper around [synadm](https://github.com/JOJ0/synadm) to quickly delete multiple Matrix rooms. - -### pacplot -Graphs the number of installed packages over time by parsing `/var/log/pacman.log`. diff --git a/adduser b/adduser index 101a875..703fdd9 100755 --- a/adduser +++ b/adduser @@ -1,7 +1,9 @@ #!/usr/bin/python +# A wrapper script over ldapadd + from sys import argv -from os import remove, environ +from os import remove from subprocess import run, call, check_output from crypt import crypt @@ -57,8 +59,8 @@ gidNumber: {uid}''' f.write(ldif) # Add user - ret = call(['ldapadd', '-D', 'cn=Manager,dc=exozy,dc=me', - '-w', open('/etc/exozyme.conf', 'r').read().split()[0], '-f', filename]) + ret = call(['ldapadd', '-D', 'cn=Manager,dc=exozy,dc=me', '-w', + open('/etc/ldappass', 'r').read(), '-f', filename]) remove(filename) if ret != 0: return diff --git a/backup b/backup index cce90af..38bfd8f 100755 --- a/backup +++ b/backup @@ -1,18 +1,20 @@ #!/usr/bin/fish +# Create an incremental system backup using bup +# Useful resources: # https://gist.github.com/bradfa/a710a4e4b83b07b7a8be77cae86ff56b # https://gist.github.com/jasontbradshaw/6a69d7c9ae0c73f54200 name=(date -u +'%Y-%m-%d') -repository=/mnt/drive/bup/ +repository=/mnt/drive/bup # Set the `bup` directory here so it affects all the `bup` commands. export BUP_DIR=$repository # Create the backup repository if it doesn't exist. if test -d $repository - bup init - chmod 700 $repository + bup init + chmod 700 $repository end # Do the backup as non-intrusively as possible. diff --git a/deluser b/deluser index 4c8f398..ec88f34 100755 --- a/deluser +++ b/deluser @@ -1,5 +1,7 @@ #!/usr/bin/python +# A wrapper script over ldapdelete + from sys import argv from subprocess import run @@ -8,8 +10,8 @@ def deluser(username): """Delete a user""" # Delete from LDAP server - ldappass = open('/etc/exozyme.conf', 'r').read().split()[0] - run(f'ldapdelete -w {ldappass} -D -cn=Manager,dc=exozy,dc=me uid={username},ou=People,dc=exozy,dc=me cn={username},ou=Group,dc=exozy,dc=me'.split()) + run(['ldapdelete', '-w', open('/etc/ldappass', 'r').read(), '-D', 'cn=Manager,dc=exozy,dc=me', + 'uid=' + username + ',ou=People,dc=exozy,dc=me', 'cn=' + username + ',ou=Group,dc=exozy,dc=me']) # Cleanup run(['sudo', 'rm', '-rf', '/home/' + username]) diff --git a/moduser b/moduser index 3b710cd..61052d0 100755 --- a/moduser +++ b/moduser @@ -1,5 +1,8 @@ #!/usr/bin/python +# A wrapper script over ldapvi +# Requires http://www.lichteblau.com/ldapvi/ + from sys import argv from subprocess import run from ldappass import ldappass @@ -9,7 +12,7 @@ def moduser(username): """Modify an existing user""" if username == 'Manager': - run(['ldapvi', '-w', open('/etc/exozyme.conf', 'r').read().split()[0], '--user', 'cn=Manager,dc=exozy,dc=me']) + run(['ldapvi', '-w', open('/etc/ldappass', 'r').read(), '--user', 'cn=Manager,dc=exozy,dc=me']) else: run(['ldapvi', '--user', 'uid=' + username + ',ou=People,dc=exozy,dc=me']) diff --git a/pacplot b/pacplot index ad6249f..3b4cf38 100755 --- a/pacplot +++ b/pacplot @@ -1,5 +1,7 @@ #!/usr/bin/python +# Graphs the number of installed packages over time by parsing /var/log/pacman.log + from datetime import datetime from matplotlib import pyplot as plt diff --git a/setid b/setid index bca8d40..f83fe9b 100755 --- a/setid +++ b/setid @@ -1,13 +1,16 @@ #!/usr/bin/python -# Set up rootless Podman +# Set up subuid and subgid for rootless Podman # https://wiki.archlinux.org/title/Podman#Set_subuid_and_subgid + + ids = '' for uid in range(1000, 2000): start = uid * 10**5 num = 65536 # Allocate 65536 UIDs ids += str(uid) + ':' + str(start) + ':' + str(num) + '\n' + # Save to system files with open('/etc/subuid', 'w') as f: f.write(ids) diff --git a/synapse-rm b/synapse-rm index 5760bf6..6459942 100755 --- a/synapse-rm +++ b/synapse-rm @@ -1,5 +1,8 @@ #!/usr/bin/fish +# Quickly delete multiple Matrix rooms using synadm +# Requires https://github.com/JOJ0/synadm + for i in $argv echo y | synadm room delete $i end diff --git a/sysusers b/sysusers index a35bcc5..75864a2 100755 --- a/sysusers +++ b/sysusers @@ -1,5 +1,7 @@ #!/usr/bin/fish +# Compare /usr/lib/sysusers.d and getent passwd to find unneeded users + for i in (getent passwd | cut -d: -f1) echo -n "$i "; grep -or $i /usr/lib/sysusers.d | wc -l end diff --git a/upgrade b/upgrade index b402f9e..569c48e 100755 --- a/upgrade +++ b/upgrade @@ -1,5 +1,7 @@ #!/usr/bin/fish +# Upgrades the system, all AUR packages, and Nextcloud apps + # Upgrade packages paru # Remove unneeded packages