#! /bin/bash # # This is a hook script for the yupdate tool, it is automatically executed # after running "rake install" command. # # The script does several tasks: # - it restarts the DBus service when any file in the ruby gem was updated # - saves the installed NPM packages to a cache so they can be reused in the # next yupdate run # set -e if [ "$DEBUG" == "1" ]; then set -x fi SERVICE_NAME="agama" # restart the installer service if needed function restart_service() { # get the service start time SERVICE_START=$(systemctl show "$SERVICE_NAME" | grep "^ExecMainStartTimestamp=" | sed -e "s/^ExecMainStartTimestamp=\(.*\)\$/\\1/") if [ -n "$SERVICE_START" ]; then SERVICE_START_UNIX_TIME=$(date -d "$SERVICE_START" +"%s") # find the date of the latest file in the product configuration or in the gem NEWEST_FILE_TIME=$(find /usr/share/agama/products.d /usr/lib*/ruby/gems/*/gems/$SERVICE_NAME-* -exec stat --format %Y "{}" \; | sort -nr | head -n 1) # when a file is newer than the start time then restart the service if [ -n "$NEWEST_FILE_TIME" ] && [ "$SERVICE_START_UNIX_TIME" -lt "$NEWEST_FILE_TIME" ]; then echo "Restarting $SERVICE_NAME service..." systemctl restart "$SERVICE_NAME" fi fi } # copy installed NPM packages to cache function save_npm_cache() { echo "Saving NPM cache..." CACHEDIR="$HOME/.cache/$SERVICE_NAME-devel/" mkdir -p "$CACHEDIR" MYDIR=$(realpath "$(dirname "$0")") cp -aR "$MYDIR/web/node_modules" "$CACHEDIR" } restart_service # cache the installed NPM packages if [ "$NPM_CACHE" = "1" ] ; then save_npm_cache fi