2016-11-09 22:25:00 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-06-23 13:56:31 -05:00
|
|
|
export logfile="/var/log/sysupdate.log"
|
|
|
|
export tmpfile=/tmp/shadowarch-cowerfile
|
|
|
|
unset apply
|
|
|
|
|
|
|
|
while getopts "al:h" OPTION
|
|
|
|
do
|
|
|
|
case $OPTION in
|
|
|
|
a) export apply="true"; ;;
|
|
|
|
c) export logfile=${OPTARG}; ;;
|
|
|
|
*) printf "ShadowArch Update Checker\n-a Apply changes\n-l Logfile\n-h Show this helptext\n"; exit 1;;
|
|
|
|
esac;
|
|
|
|
done
|
|
|
|
|
|
|
|
date > $logfile
|
2016-11-09 22:25:00 -06:00
|
|
|
|
|
|
|
# Update
|
2017-06-23 13:56:31 -05:00
|
|
|
echo == Updating Arch Packages == | tee -a $logfile
|
|
|
|
if [ ! -z "$apply" ]; then
|
|
|
|
pacman -Syu 2>&1 | tee -a $logfile # I've been having troubles with this causing crashes while online.
|
|
|
|
# Hook for MediaWiki
|
2018-02-13 13:22:57 -06:00
|
|
|
if [ `grep $(date +%F) /var/log/pacman.log | grep -c mediawiki` -eq 1 ] && [ -d /usr/share/webapps/mediawiki ]; then
|
2017-06-23 13:56:31 -05:00
|
|
|
php /usr/share/webapps/mediawiki/maintenance/update.php | tee -a $logfile
|
2017-11-20 14:33:26 -06:00
|
|
|
for i in `find /usr/share/webapps/ -maxdepth 1 -type d | grep mediawiki\-`; do
|
|
|
|
rsync -avz --exclude images --exclude Images --exclude LocalSettings.php /usr/share/webapps/mediawiki/ "$i"
|
|
|
|
php "$i"/maintenance/update.php
|
|
|
|
done
|
2017-06-23 13:56:31 -05:00
|
|
|
fi
|
|
|
|
# Hook for Grimoire
|
2018-02-13 13:22:57 -06:00
|
|
|
if [ `grep $(date +%F) /var/log/pacman.log | grep -c 'upgraded postgresql '` -eq 1 ]; then
|
2017-06-23 13:56:31 -05:00
|
|
|
echo "Updating PostGreSQL databases" | tee -a $logfile
|
|
|
|
#Clear old backups.
|
|
|
|
rm -Rf /var/lib/postgres/olddata
|
|
|
|
#Stop the service and save old database version.
|
|
|
|
if [ -f /usr/lib/systemd/system/grimoire.service ]; then systemctl stop grimoire; else systemctl stop postgresql.service; fi
|
|
|
|
su -l postgres -c 'mv /var/lib/postgres/data /var/lib/postgres/olddata'
|
|
|
|
# Init new database and upgrade.
|
|
|
|
su -l postgres -c 'initdb --locale en_US.UTF-8 -E UTF8 -D /var/lib/postgres/data' | tee -a $logfile
|
|
|
|
upstr=`grep "$(date +%F)" /var/log/pacman.log | grep 'upgraded postgresql '`
|
|
|
|
oldver=`echo $upstr | rev | cut -f 2 -d '>' | cut -f 1 -d '(' | rev | sed s/\ -//`
|
|
|
|
newver=`echo $upstr | rev | cut -f 1 -d '>' | cut -f 2 -d ')' | rev`
|
|
|
|
# Upgrade the database.
|
|
|
|
su -l postgres -c "pg_upgrade -d /var/lib/postgres/olddata/ -D /var/lib/postgres/data/ -b /opt/pgsql-$oldver/bin/ -B /usr/bin/" | tee -a $logfile
|
|
|
|
# Create dump file for restores.
|
|
|
|
/opt/pgsql-$oldver/bin/pg_ctl -D /var/lib/postgres/olddata/ start
|
|
|
|
/opt/pgsql-$oldver/bin/pg_dumpall >> /var/lib/postgres/olddata/dump.psql
|
|
|
|
/opt/pgsql-$oldver/bin/pg_ctl -D /var/lib/postgres/olddata/ stop
|
|
|
|
# Restart the service.
|
|
|
|
if [ -f /usr/lib/systemd/system/grimoire.service ]; then systemctl start grimoire; else systemctl start postgresql.service; fi
|
|
|
|
echo "Updated PostGreSQL databases" | tee -a $logfile
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
checkupdates | tee -a $logfile
|
|
|
|
fi
|
|
|
|
echo | tee -a $logfile
|
2016-11-09 22:25:00 -06:00
|
|
|
|
|
|
|
# Get AUR list of update candidates
|
2017-06-23 13:56:31 -05:00
|
|
|
echo == AUR Candidate List == | tee -a $logfile
|
|
|
|
if [ ! -z "$apply" ]; then
|
|
|
|
cower -u | cut -f 2 -d ' ' &> $tmpfile
|
|
|
|
echo Edit the package list.
|
|
|
|
read
|
|
|
|
${EDITOR} ${tmpfile}
|
|
|
|
chmod 0755 $tmpfile;
|
|
|
|
printf "What deprivileged user do you want to use? "
|
|
|
|
read deprivuser;
|
|
|
|
sudo -u "$deprivuser" /bin/bash -c "for i in `cat $tmpfile`; do cd /usr/local/src/"$i"; git pull; makepkg -sri; done"
|
|
|
|
(echo Updated the following AUR packages:; cat $tmpfile) | tee -a $logfile
|
|
|
|
rm $tmpfile;
|
|
|
|
else
|
|
|
|
cower -u | tee -a $logfile
|
|
|
|
fi
|
|
|
|
echo | tee -a $logfile
|
2016-11-09 22:25:00 -06:00
|
|
|
|
2017-11-20 14:33:26 -06:00
|
|
|
# Update AniNIX packages
|
|
|
|
echo == Updating AniNIX Packages == | tee -a $logfile
|
|
|
|
if [ ! -z "$apply" ]; then
|
|
|
|
for i in `find /usr/local/src/ -maxdepth 6 -type f -name config -exec egrep -l aninix\|foundation {} \; | sed 's#.git/config$##'`; do
|
|
|
|
cd "$i"
|
|
|
|
git pull
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-09 22:25:00 -06:00
|
|
|
# Generate list of installed packages
|
2017-06-23 13:56:31 -05:00
|
|
|
echo == Generated installed-packages list == | tee -a $logfile
|
|
|
|
pacman -Qqe | egrep '^[a-z]' | sed 's#local/##' > /var/log/installed-packages.txt
|
2016-11-09 22:25:00 -06:00
|
|
|
|
|
|
|
# Generate list of orphaned packages
|
2017-06-23 13:56:31 -05:00
|
|
|
echo == Generated orphaned-packages list == | tee -a $logfile
|
2016-11-09 22:25:00 -06:00
|
|
|
pacman -Qdtq > /var/log/orphaned-packages.txt
|
2017-06-23 13:56:31 -05:00
|
|
|
echo | tee -a $logfile
|
|
|
|
date | tee -a $logfile
|
|
|
|
printf '\n\n' | tee -a $logfile
|
2016-11-09 22:25:00 -06:00
|
|
|
|
2017-06-23 13:56:31 -05:00
|
|
|
if [ -z "$apply" ]; then cat $logfile | mail -s "AniNIX::$(hostname) Update Candidates" sh1k0b4@gmail.com; fi
|