forked from agama-project/agama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.yupdate.post
executable file
·54 lines (43 loc) · 1.58 KB
/
.yupdate.post
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /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