diff --git a/bin/uau b/bin/uau index cb23154..82887ed 100755 --- a/bin/uau +++ b/bin/uau @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ############################################################################ # # Unattended Upgrade of Arch @@ -7,67 +7,123 @@ # TODO: log rotate (I do not want to overwrite by each run..) -# unattended upgrade config -UACONF=/etc/unattended-arch-upgrade.conf - export TERM=non-interactive # get current time stamp -STARTTIME="$(date '+%F %T')" +NOW=$(date --iso-8601=seconds) +STARTTIME=$(date --date="$NOW" +'%F %T') + +# unattended upgrade config +UACONF=/etc/unattended-arch-upgrade.conf # source the necessary conf -[ ! -f $UACONF ]&& echo "ERROR MISSING $UACONF!!!" && exit 3 +if [ ! -f $UACONF ]; then + echo "ERROR: MISSING $UACONF!!!" >&2 + exit 3 +fi +# shellcheck disable=SC1090 . $UACONF LOG=$LOGDIR/upgrade-latest.log FULLLOG=$LOGDIR/upgrade.log -echo "started $(date)" -echo -e "$0 has started $(date)\n\n" > $LOG +START_DATE=$(date --date="$NOW") +echo "started $START_DATE" +printf '%s has started %s\n\n\n' "$0" "$START_DATE" > "$LOG" -if [ "$AUTOUPGRADE" == "I-UNDERSTAND-THAT-THIS-COULD-BREAK-MY-SYSTEM" ];then - UPGRADECONF="$UAUON" -else - echo "unattended upgrade is disabled in $UACONF" && exit 3 +if [ "$AUTOUPGRADE" != "I-UNDERSTAND-THAT-THIS-COULD-BREAK-MY-SYSTEM" ]; then + echo "unattended upgrade is disabled in $UACONF" + exit 3 fi +UPGRADECONF=$UAUON echo "fetching the latest news (and AUR comments) before upgrading" -echo -e "\n##########################################################\nArch news & AUR comments (for updatable packages only!)\n##########################################################" >> $LOG -echo -e "as recommended by:\nhttps://wiki.archlinux.org/index.php/System_maintenance#Read_before_upgrading_the_system\n" >> $LOG -echo -e "Please check $NEWSLOG\n(gets automatically attached when you've activated mail notify)\n" >> $LOG +cat <> "$LOG" + +########################################################## +Arch news & AUR comments (for updatable packages only!) +########################################################## + +as recommended by: +https://wiki.archlinux.org/index.php/System_maintenance#Read_before_upgrading_the_system +Please check $NEWSLOG +(gets automatically attached when you've activated mail notify) + +EOF [ -x "$ANEWSWRAP" ] && UA=true $ANEWSWRAP echo "starting the unattended system upgrade!" # first check the current systemd status and errors and save them for later comparison -systemctl --failed --plain > $LOGDIR/systemclt-failed.before +systemctl --failed --plain > "$LOGDIR"/systemctl-failed.before echo "check & upgrade repo binaries" -echo -e "\n##########################################################\ncheck & upgrade REPO binaries\n##########################################################\n" >> $LOG -sudo -n $PACBIN -Syu --noconfirm --needed --noprogressbar $PACARG >> $LOG 2>&1 +cat <> "$LOG" + +########################################################## +check & upgrade REPO binaries +########################################################## + +EOF +# shellcheck disable=SC2086 +sudo -n $PACBIN -Syu --noconfirm --needed --noprogressbar $PACARG 2>&1 | tee -a "$LOG" echo "check & upgrade AUR packages" -echo -e "\n##########################################################\ncheck & upgrade AUR packages\n##########################################################\n" >> $LOG -$AURBIN -Syu --noconfirm --needed --noprogressbar $AURARG >> $LOG 2>&1 +cat <> "$LOG" + +########################################################## +check & upgrade AUR packages +########################################################## + +EOF +# shellcheck disable=SC2086 +$AURBIN -Syu --noconfirm --needed --noprogressbar $AURARG >> "$LOG" 2>&1 # check the systemd status and errors again after the upgrade made -systemctl --failed --plain > $LOGDIR/systemclt-failed.after +systemctl --failed --plain > "$LOGDIR"/systemctl-failed.after # compare systemd status and errors and show differences only -echo -e "\n##########################################################\nShowing systemd status difference (before VS. after upgrade)\n##########################################################" >> $LOG -echo -e "as recommended by:\nhttps://wiki.archlinux.org/index.php/System_maintenance#Failed_systemd_services\n" >> $LOG -diff -wu $LOGDIR/systemclt-failed.before $LOGDIR/systemclt-failed.after >> $LOG -[ $? -eq 0 ]&& echo -e "-- Nothing has changed --\n" >> $LOG +cat <> "$LOG" + +########################################################## +Showing systemd status difference (before VS. after upgrade) +########################################################## + +as recommended by: +https://wiki.archlinux.org/index.php/System_maintenance#Failed_systemd_services + +EOF +if ! diff -wu \ + "$LOGDIR"/systemctl-failed.before \ + "$LOGDIR"/systemctl-failed.after >> "$LOG"; then + # shellcheck disable=SC3045 + printf '-- Nothing has changed --\n\n' >> "$LOG" +fi + +cat <> "$LOG" + +########################################################## +Showing journal high prio errors (since the upgrade) +########################################################## + +as recommended by: +https://wiki.archlinux.org/index.php/System_maintenance#Logfiles -echo -e "\n##########################################################\nShowing journal high prio errors (since the upgrade)\n##########################################################" >> $LOG -echo -e "as recommended by:\nhttps://wiki.archlinux.org/index.php/System_maintenance#Logfiles\n" >> $LOG -journalctl -p 3 -xb --since "$STARTTIME" >> $LOG +EOF +journalctl -p 3 -xb --since "$STARTTIME" >> "$LOG" -if [ "$UPGRADEMAIL" == "yes" ];then - echo -e "$(date)\n$UPGRADECONF" | mail -a $LOG -a $NEWSLOG -r $FROM -s "Unattended Arch upgrade on $(hostname)" $TO +END_DATE=$(date) +if [ "$UPGRADEMAIL" = yes ]; then + printf "%s\n%s\n" "$END_DATE" "$UPGRADECONF" \ + | mail \ + -r "$FROM" \ + -s "Unattended Arch upgrade on $(hostname)" \ + -a "$LOG" \ + -a "$NEWSLOG" \ + "$TO" fi -echo "$0 has finished $(date)" >> $LOG -cat $LOG >> $FULLLOG +echo "$0 has finished $END_DATE" >> "$LOG" +cat "$LOG" >> "$FULLLOG" echo "finished" diff --git a/bin/uau-archnews b/bin/uau-archnews index e1196a0..e208339 100755 --- a/bin/uau-archnews +++ b/bin/uau-archnews @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh ############################################################### # # @@ -13,128 +13,162 @@ UACONF=/etc/unattended-arch-upgrade.conf ############################################################## export TERM=non-interactive -BIN=${0##*/} - # source the necessary conf -[ ! -f $UACONF ]&& echo "ERROR MISSING $UACONF!!!" && exit 3 +if [ ! -f $UACONF ]; then + echo "ERROR: MISSING $UACONF!!!" >&2 + exit 3 +fi +# shellcheck disable=1090 . $UACONF LOG="$NEWSLOG" # set amount of comments for AUR packages -if [ "$BRIEFNEWSAUR" == 1 ];then - AURFETCHARGS="-n 1" # fetch the last comment +if [ "$BRIEFNEWSAUR" = 1 ]; then + AURFETCHARGS="-n 1" # fetch the last comment else - AURFETCHARGS="-n $AURCOMMENTS" # fetch the last X comments + AURFETCHARGS="-n $AURCOMMENTS" # fetch the last X comments fi # enforce a full refresh for repo and AUR - otherwise checkupdates will not show the real state.. +# shellcheck disable=SC2086 $AURBIN $AURNEWSSYNCARG >> $LOG 2>&1 # source the ignores of pacman config -[ -f "$PACCONF" ]&& PACIGN=$(egrep "^IgnorePkg" $PACCONF | cut -d "=" -f 2) +[ -f "$PACCONF" ]&& PACIGN=$(grep -E "^IgnorePkg" "$PACCONF" | cut -d "=" -f 2) # source the ignores of unattended config -[ -f "$UAIGNORE" ] && UAIGN=$(egrep "^IgnorePkg" $UAIGNORE | cut -d "=" -f 2) +[ -f "$UAIGNORE" ] && UAIGN=$(grep -E "^IgnorePkg" "$UAIGNORE" | cut -d "=" -f 2) #first adjust the filter -for filter in $PACIGN $UAIGN;do - if [ -z "$FILTER" ];then - [ ! -z "$filter" ] && FILTER="$filter" - else - [ ! -z "$filter" ] && FILTER="$FILTER|$filter" - fi +for filter in $PACIGN $UAIGN; do + FILTER="${FILTER:+$FILTER|}$filter" done -# using checkupdates & checkupdates-aur) to find available packages then filter with archnews for relevant info +# using checkupdates & checkupdates-aur) to find available packages then filter with archnews for relevant info # within the Arch news feed for each package. -echo -e "These binary packages can be upgraded on your machine ($(hostname)):" > $LOG -echo -e "---------------------------------------------------------------------------\n" >> $LOG -for cu in $($PACBIN -Qu 2>> $LOG |tr " " "|");do - unset PKG - - if [ -z "$FILTER" ];then - PKG=$(echo "${cu}") +cat <> "$LOG" +These binary packages can be upgraded on your machine ($(hostname)): +--------------------------------------------------------------------------- + +EOF +for cu in $($PACBIN -Qu 2>> "$LOG" | tr " " "|"); do + unset PKG + + if [ -z "$FILTER" ]; then + PKG=$cu + else + PKG=$(echo "${cu}" | grep -Evi "($FILTER)") + fi + SPKG=${PKG%%|*} + + if [ "$BRIEFNEWS" = 1 ]; then + FPKG=$SPKG + else + FPKG=$(echo "$PKG" | tr "|" " ") + fi + + # make a list of all packages + if [ -n "$PKG" ]; then + SPKGLIST=${SPKGLIST:+$SPKGLIST }$SPKG + if [ "$BRIEFNEWS" = 1 ]; then + PKGLIST="${PKGLIST:+$PKGLIST,}$FPKG" else - PKG=$(echo "${cu}" | egrep -vi "($FILTER)") + PKGLIST="${PKGLIST:+$PKGLIST\n}$FPKG" fi - SPKG=${PKG/|*/} - - if [ $BRIEFNEWS == 1 ];then - FPKG=$SPKG - else - FPKG=$(echo "$PKG" | sed 's/|/ /g') - fi - - # make a list of all packages - if [ ! -z "$PKG" ];then - - if [ -z "$PKGLIST" ];then - PKGLIST="$FPKG" - SPKGLIST="$SPKG" - else - if [ $BRIEFNEWS == 1 ];then - PKGLIST="$PKGLIST,$FPKG" - else - PKGLIST="$PKGLIST\n$FPKG" - fi - SPKGLIST="$SPKGLIST $SPKG" - fi - fi + fi done # now send the package summary to the log -echo -e "$PKGLIST" >> $LOG +printf "%s\n" "$PKGLIST" >> "$LOG" +cat <> "$LOG" + -echo -e "\n\nThese binary packages have been mentioned on the Arch news page!!" >> $LOG -echo -e "---------------------------------------------------------------------------" >> $LOG -echo -e "(please also take a look at the bottom so you don't miss any GLOBAL news!)\n" >> $LOG +These binary packages have been mentioned on the Arch news page!! +--------------------------------------------------------------------------- +(please also take a look at the bottom so you don't miss any GLOBAL news!) + +EOF # query arch news for each pkg -for pkgl in $SPKGLIST;do - FPKG=$(echo "#---- $pkgl ----#" |tr "|" " ") - $ANEWSBIN -rc -n 10 --grep "$pkgl " >> /dev/null 2>&1 - [ $? -eq 0 ] && echo -e "${FPKG}\n$($ANEWSBIN -rc -n 10 --grep "$pkgl ")\n" >> $LOG 2>&1 +for pkgl in $SPKGLIST; do + FPKG=$(echo "#---- $pkgl ----#" | tr "|" " ") + + if OUT=$($ANEWSBIN -rc -n 10 --grep "$pkgl "); then + printf '%s\n%s\n\n' "$FPKG" "$OUT" >> "$LOG" 2>&1 + fi done -echo -e "\n\nThese AUR packages can be upgraded on your machine ($(hostname)):" >> $LOG -echo -e "---------------------------------------------------------------------------\n" >> $LOG -for cuaur in $($AURBIN $AURARGS_CHKUPGRADE 2>> $LOG |tr " " "|");do - unset FPKG PKG - FPKG=$(echo "#---- $cuaur ----#" |tr "|" " ") - PKG=$(echo "${cuaur/|*/}" | egrep -vi "($FILTER)") - [ ! -z "$PKG" ] && echo -e "$FPKG\n$($AURFETCH $AURFETCHARGS $PKG | egrep -v '^\s*$' | sed 's/\[[0-9]*m//g' 2>/dev/null)" >> $LOG - [ ! -z "$PKG" ] && echo -e "\n" >> $LOG +cat <> "$LOG" + + +These AUR packages can be upgraded on your machine ($(hostname)): +--------------------------------------------------------------------------- + +EOF +# shellcheck disable=SC2086 +for cuaur in $($AURBIN $AURARGS_CHKUPGRADE 2>> "$LOG" | tr " " "|"); do + unset FPKG PKG + FPKG=$(echo "#---- $cuaur ----#" |tr "|" " ") + PKG=$(echo "${cuaur%%|*}" | grep -Evi "($FILTER)") + if [ -n "$PKG" ]; then + echo "$FPKG" + $AURFETCH $AURFETCHARGS $PKG \ + | grep -Ev '^\s*$' \ + | sed 's/\[[0-9]*m//g' 2>/dev/null >> "$LOG" + echo >> $LOG + fi done # prepare topic line depending on brief or not -if [ $BRIEFNEWS == 1 ];then - if [ -f $ANEWSCONF ];then - NINF="only UNREAD - since: $(grep -v '#' $ANEWSCONF)" - else - NINF="only UNREAD - first run!" - fi +if [ "$BRIEFNEWS" = 1 ]; then + if [ -f "$ANEWSCONF" ]; then + NINF="only UNREAD - since: $(grep -v '#' "$ANEWSCONF")" + else + NINF="only UNREAD - first run!" + fi else - NINF="with args: $ANEWSARGS" + NINF="with args: $ANEWSARGS" fi -echo -e "\n\n\nLatest Arch News feed ($NINF):" >> $LOG -echo -e "---------------------------------------------------------------------------\n" >> $LOG +cat <> "$LOG" + + +Latest Arch News feed ($NINF): +--------------------------------------------------------------------------- + +EOF # we make a new same if loop to handle the formatted output more easily -if [ "$BRIEFNEWS" == "1" ];then - yes | $ANEWSBIN $ANEWSARGS --unread 2>> $LOG | grep -iv "Mark messages as read" >> $LOG +if [ "$BRIEFNEWS" = 1 ]; then + # shellcheck disable=SC2086 + yes | $ANEWSBIN $ANEWSARGS --unread 2>> "$LOG" \ + | grep -iv "Mark messages as read" >> "$LOG" else - # delete any unread option config so we actually be able to read news again - [ -f "$ANEWSCONF" ] && rm "$ANEWSCONF" - $ANEWSBIN $ANEWSARGS >> $LOG + # delete any unread option config so we actually be able to read news again + [ -f "$ANEWSCONF" ] && rm -f "$ANEWSCONF" + # shellcheck disable=SC2086 + $ANEWSBIN $ANEWSARGS >> "$LOG" fi -if [ "$AUTOUPGRADE" == "I-UNDERSTAND-THAT-THIS-COULD-BREAK-MY-SYSTEM" ];then - UPGRADECONF="$UAUON" +if [ "$AUTOUPGRADE" = "I-UNDERSTAND-THAT-THIS-COULD-BREAK-MY-SYSTEM" ]; then + UPGRADECONF=$UAUON else - UPGRADECONF="$UAUOFF" + UPGRADECONF=$UAUOFF fi # only send an email when wanted by the user and not called by unattended upgrade -if [ "$NEWSMAIL" == "yes" ]&&[ -z "$UA" ];then - echo -e "$(date)\n$UPGRADECONF\n\n$(cat $LOG)\n\nCHECK THE ATTACHMENT(S)!!\n\n" | mail -r $FROM -s "Arch Update information for $(hostname)" $TO +if [ "$NEWSMAIL" = yes ] && [ -z "$UA" ]; then + cat <&1 >> /dev/null