blob: 61d24d7d0fa5c354f17988ff0849037fcac26957 (
plain) (
blame)
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
|
#!/bin/ash
#
# Script to be called by systemd
#
# Downloads and appends addons per sqfs/aufs.
#
######################################################################################
#
# Two modes for this script:
# - without any arguments, it will just go through the list of addons to
# setup as given through the OpenSLX configuration file
# - with an argument, it will setup the addon given as $1
#
#
######################################################################################
# read global OpenSLX config
. /opt/openslx/config || { echo "Could not source config!"; exit 23; }
# read base slx servers from cmdline
BASE_MOUNT_POINT="/opt/openslx/mnt"
DOWNLOAD_DEST="/run/addons"
FINAL_DEST="/tmp/addons"
mkdir -p "$FINAL_DEST" || { echo "Failed to create $FINAL_DEST"; exit 1; }
######################################################################################
#
# NO ARGUMENTS
#
if [ $# -ne 1 ]; then
echo "No addon passed via command line. Pass exactly one addon."
exit 1
fi
######################################################################################
#
# WITH ARGUMENTS -> SETUP ADDON
#
ADDON="$1"
# check that is was properly downloaded
ADDON_PATH="${DOWNLOAD_DEST}/$(basename "$ADDON.sqfs")"
if [ ! -f "${ADDON_PATH}" ]; then
slxlog --echo "addon-setup-fnf" "Addon squashfs not found under: '${ADDON_PATH}'"
exit 1
fi
# do we have hdd tmp?
if grep -q '^/dev/\S+\s/tmp' '/proc/mounts'; then
# it's there, so move it to /tmp to save some ram
if mv -f "${ADDON_PATH}" "${FINAL_DEST}/$(basename $ADDON.sqfs)"; then
ADDON_PATH="${FINAL_DEST}/$(basename $ADDON.sqfs)"
else
slxlog --echo "addon-setup-mv" "Failed to move '$ADDON' from $DOWNLOAD_DEST to $FINAL_DEST. Keeping it in RAM"
fi
fi
# now mount it to $BASE_MOUNT_POINT/<addon-name>
ADDON_MOUNT_POINT="${BASE_MOUNT_POINT}/$(basename "$ADDON")"
mkdir -p "$ADDON_MOUNT_POINT"
mount -t squashfs -o ro "$ADDON_PATH" "$ADDON_MOUNT_POINT" || \
{ slxlog --echo "addon-setup-mount" "Failed to mount $ADDON_PATH."; exit 1; }
# now append it to /
echo "Appending ${ADDON_MOUNT_POINT} to /"
if ! mount -o "remount,ins:1:${ADDON_MOUNT_POINT}=rr" / ; then # ins:1 makes sure the addon is before stage32, after rw layer
slxlog --echo "addon-setup-aufs" "Failed to append ${ADDON_MOUNT_POINT} to the aufs. Cleaning up..."
umount -l "${ADDON_MOUNT_POINT}" || echo "Could not unmount ${ADDON_MOUNT_POINT}!"
exit 1
fi
# Run post-hook if available
if [ -x "$ADDON_MOUNT_POINT/addon-init" ]; then
"$ADDON_MOUNT_POINT/addon-init" || \
slxlog --echo "addon-setup-init" "Warning: Could not execute addon-init of $ADDON"
fi
if ! grep -q -F '/opt/openslx/mnt/stage4' "/proc/mounts"; then
ldconfig 2> /dev/null || ldconfig.real 2> /dev/null
fi
exit 0
|