vhost-stack/update.sh
Matthew Saunders Brown c3ffd5c419 rework systemd stuff
move service to paths.target
remove startup dependency
change to try-reload-or-restart which has this logic:
  Reload service if it supports it.
  If not, stop and then start instead.
  Does nothing if the service is not running.
2023-12-20 10:07:20 -08:00

98 lines
2.8 KiB
Bash
Executable File

#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
if [ "${EUID}" -ne 0 ]; then
echo "You must be root to run this installer."
exit
fi
# update repo
git pull
# update scripts in bin
chmod 755 bin/*
readarray -t bin_script_array < <(ls -1 bin/)
for bin_script in "${bin_script_array[@]}"; do
if [ -f /usr/local/bin/$bin_script ]; then
if ! diff -q bin/$bin_script /usr/local/bin/$bin_script ; then
echo "Updating /usr/local/bin/$bin_script"
cp bin/$bin_script /usr/local/bin/$bin_script
echo
fi
else
echo "Adding new script /usr/local/bin/$bin_script"
cp bin/$bin_script /usr/local/bin/$bin_script
echo
fi
done
# update scripts in bin
chmod 755 sbin/*
readarray -t sbin_script_array < <(ls -1 sbin/)
for sbin_script in "${sbin_script_array[@]}"; do
if [ -f /usr/local/sbin/$sbin_script ]; then
if ! diff -q sbin/$sbin_script /usr/local/sbin/$sbin_script ; then
echo "Updating /usr/local/sbin/$sbin_script"
cp sbin/$sbin_script /usr/local/sbin/$sbin_script
echo
fi
else
echo "Adding new script /usr/local/sbin/$sbin_script"
cp sbin/$sbin_script /usr/local/sbin/$sbin_script
echo
fi
done
# check etc configs for diffs
readarray -t etc_configs_array < <(find etc/ -type f)
for etc_config in "${etc_configs_array[@]}"; do
if [ -f /$etc_config ]; then
if ! diff -q $etc_config /$etc_config ; then
echo To update run:
echo diff $etc_config /$etc_config
echo cp $etc_config /$etc_config
echo
fi
else
echo "Adding new config file /$etc_config"
cp $etc_config /$etc_config
echo
fi
done
# update html/status.php
if ! diff -q html/status.php /srv/www/html/status.php ; then
cp html/status.php /srv/www/html/status.php
chmod 644 /srv/www/html/status.php
chown vhost:vhost /srv/www/html/status.php
echo "/srv/www/html/status.php updated"
echo
fi
# update libexec script
if ! diff -q libexec/command-not-found-handle /usr/local/libexec/command-not-found-handle ; then
cp libexec/command-not-found-handle /usr/local/libexec/command-not-found-handle
chmod 755 /usr/local/libexec/command-not-found-handle
echo "/usr/local/libexec/command-not-found-handle updated"
echo
fi
# check for systemd updates
systemdConfigs=(`ls -1 systemd/`)
for systemdConfig in "${systemdConfigs[@]}"
do
if ! diff -q systemd/$systemdConfig /usr/local/lib/systemd/system/$systemdConfig ; then
cp systemd/$systemdConfig /usr/local/lib/systemd/system/$systemdConfig
chmod 644 /usr/local/lib/systemd/system/$systemdConfig
systemctl daemon-reload
systemctl --quiet try-reload-or-restart $systemdConfig
echo "systemd/$systemdConfig updated"
echo
fi
done