#!/usr/bin/env bash # klevstul # https://wiki.archlinux.org/title/pacman echo "<< 99_software.sh >>" user=poq if [ "$EUID" -ne 0 ] ; then echo "error: run as 'root'"; exit 1; fi this_file_name=`basename "$0"` if [ $# -lt 1 ]; then echo "error: $# arguments given" echo "usage: '$this_file_name [operation] [argument?]'" exit 1 fi operation=$1 parameter=$2 # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ param_check() { parameter=$1 error_msg=$2 if [ -z "${parameter}" ] ; then echo "error: ${error_msg}" ; exit 1 fi } # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # ----- # always update the system # ----- echo "- - - - -" echo "if no uninstallable packages were found, the following error will be displayed:" echo "\"error: no targets specified (use -h for help)\"" echo "- - - - -" echo "removing obsolete packages:" pacman -Rns $(pacman -Qtdq) # remove packages that are not needed echo "update installed packages:" pacman -Syu # update installed packages echo "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-" do_update() { hostname=$1 param_check "${hostname}" "no host name given" echo echo "installing packages for the host '${hostname}':" package_list_url=https://git.mz.fo/fro/lnx-arch/raw/branch/master/dots/archinstall/${hostname}/packages.txt trg_file=/tmp/packages.txt rm -rf ${trg_file} rm -rf ${trg_file}.tmp wget --no-check-certificate -q ${package_list_url} -O ${trg_file} if ! [ -s ${trg_file} ] ; then echo "error: packages.txt is empty" echo "" echo "attempted to to download 'packages.txt' from: echo '${package_list_url}'" echo "'${hostname}' might be an invalid hostname, or 'packages.txt' might be missing for given host." exit 1 fi # https://unix.stackexchange.com/questions/157328/how-can-i-remove-all-comments-from-a-file sed '/^[[:blank:]]*#/d;s/#.*//' ${trg_file} > ${trg_file}.tmp # https://stackoverflow.com/questions/30988586/creating-an-array-from-a-text-file-in-bash mapfile -t packages < ${trg_file}.tmp installed=$(pacman -Qq) list=() list_aur=() for x in ${packages[@]} do if [[ $installed == $x ]] then echo "Skipping (1) $x" else if [[ $(echo "$installed" | grep -E -o "^$x$") != $x ]] then if [[ "$x" =~ ^aur:* ]]; then x=${x:4} echo "Adding $x to AUR list" list_aur+="$x " else echo "Adding $x to Arch list" list+="$x " fi else echo "Skipping (2) $x" fi fi done if [[ -n "$list" ]] then pacman -S --needed --noconfirm $list else echo "No Arch packages to install" fi if [[ -n "$list_aur" ]] then # using sudo with the -c flag, it does not work to use variables, like `${list_aur}`` # hence the list of aur packages is written to a file, which is used with yay echo ${list_aur} > /tmp/list_aur.txt sudo -u ${user} bash -c 'yay -S --needed --noconfirm --timeupdate $(