-
Notifications
You must be signed in to change notification settings - Fork 44
/
.yupdate.pre
executable file
·95 lines (78 loc) · 2.81 KB
/
.yupdate.pre
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#! /bin/bash
#
# This is a hook script for the yupdate tool, it is automatically executed
# before running "rake install" command.
#
# This script prepares the live system for compiling and installing new code.
#
# The script does several tasks:
# - it checks if there is enough RAM, if there is not enough RAM the system
# might freeze completely
# - installs some packages required for compilations (mainly make, npm and nodejs),
# - if there is no package repository configured it adds the main OSS repository
# automatically
# - optionally caches the installed NPM packages, this is useful if you want to
# run the yupdate script several times
#
set -e
if [ "$DEBUG" == "1" ]; then
set -x
fi
if [ "$YUPDATE_SKIP_FRONTEND" == "1" ]; then
exit 0
fi
# the needed packages for compiling the cockpit module
PACKAGES=(appstream-glib-devel make npm)
# name of the service
SERVICE_NAME="agama"
# add repositories
function add_repos() {
# only if no repository is defined
if zypper lr | grep -q "No repositories defined"; then
SYSTEM=$(. /etc/os-release && echo "$ID")
# check the installed system, add the proper repo for TW or Leap
if [ "$SYSTEM" = "opensuse-tumbleweed" ]; then
URL="http://download.opensuse.org/tumbleweed/repo/oss"
elif [ "$SYSTEM" = "opensuse-leap" ]; then
URL="http://download.opensuse.org/distribution/leap/\${releasever}/repo/oss/"
else
echo "Unsupported system: $SYSTEM"
exit 1
fi
zypper addrepo "$URL" main-repo
zypper --gpg-auto-import-keys refresh
fi
}
function install_packages() {
# stop the service, it might hold the libzypp lock preventing from installing the packages
systemctl stop "$SERVICE_NAME"
add_repos
zypper --non-interactive install --no-recommends "${PACKAGES[@]}"
systemctl start "$SERVICE_NAME"
}
# restore the NPM cache if it is present
function load_npm_cache() {
CACHEDIR="$HOME/.cache/$SERVICE_NAME-devel/"
if [ -d "$CACHEDIR/node_modules" ]; then
echo "Restoring NPM cache..."
MYDIR=$(realpath "$(dirname "$0")")
cp -aR "$CACHEDIR/node_modules" "$MYDIR/web/"
fi
}
# memory check, with not enough memory the system freezes
RAM=$(grep "MemTotal:" /proc/meminfo | sed -e "s/MemTotal:[[:space:]]*\([0-9]\+\) kB/\\1/")
# less than ~2GB RAM
if [ "$RAM" -lt 2000000 ] && [ "$SKIP_MEM_CHECK" != "1" ]; then
echo >&2
echo "ERROR: The system has too low memory ($RAM kB) for applying the update." >&2
echo "The system could completely freeze and become unresponsive." >&2
echo "You can skip this check with SKIP_MEM_CHECK=1 environment variable." >&2
echo >&2
exit 1
fi
# check if all needed packages are installed, if not then install them
rpm -q --whatprovides "${PACKAGES[@]}" > /dev/null || install_packages
# optionally restore the cached NPM packages
if [ "$NPM_CACHE" = "1" ] ; then
load_npm_cache
fi