summaryrefslogtreecommitdiffstats
path: root/core/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-download_slx_addons
blob: c9b06f9dc0ce79e74a4084cdcffbda6260455c93 (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
83
84
85
86
#!/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; }

# source functions.inc for the download function
. /opt/openslx/inc/functions || { echo "/opt/openslx/inc/functions not found!"; exit 42; }

# quick fix for the missing FUTURE_ROOT needed by /opt/openslx/etc/functions.inc
export FUTURE_ROOT="/"

# read openslx config, especially servers given by SLX_KCL_SERVERS and SLX_CONFIG_SERVERS
if [ -z "${SLX_CONFIG_SERVERS}" ]; then
	echo "SLX_CONFIG_SERVERS is not set in /opt/openslx/config. Will only try the base servers from the cmdline."
	#[ -z "${SLX_KCL_SERVERS}" ] && SLX_KCL_SERVERS=$(read_from_cmdline "slxsrv")
fi

# read base slx servers from cmdline
DOWNLOAD_DEST="/run/addons"
mkdir -p "$DOWNLOAD_DEST" || { echo "Failed to create $DOWNLOAD_DEST"; exit 1; }

######################################################################################
#
#				DOWNLOAD ALL ADDONS
#
if [ $# -eq 0 ]; then
	if [ -z "${SLX_ADDONS}" ]; then
		echo "No addons configured. Nothing to do :-)."
	else
		for ADDON in ${SLX_ADDONS}; do
			# Use bg not --no-block so we can wait below
			systemctl start "download-slx-addon@$ADDON.service" &
		done
		echo "Waiting for addon downloads to finish"
		wait
	fi
	[ -n "$SLX_SPLASH" ] && splashtool --icon "/opt/openslx/icons/active/??-puzzle.ppm"
	exit 0
fi
##
# DOWNLOAD SINGLE ADDON
if [ $# -eq 1 ]; then
	ADDON="$1"
	ADDON_TARGET_PATH="${DOWNLOAD_DEST}/$(basename "$ADDON").sqfs"
	if [ -f "${SLX_BASE_PATH}/${ADDON}.sqfs" ]; then
		echo "Already downloaded, doing nothing"
		exit 0
	fi
	# XXX HACK
	# Select proper VMware version
	FILE="$ADDON"
	if [ "$ADDON" = "vmware" ]; then
		# check with the helper
		version="$( vmware-get-supported-version )"
		if [ "$version" = "legacy" ]; then
			FILE="${ADDON}-${version}"
		fi
		echo "Deciding to download flavor '$version' of $ADDON ($FILE) after checking CPU"
	fi
	# XXX
	if ! download "${SLX_BASE_PATH}/${FILE}.sqfs" "${ADDON_TARGET_PATH}"; then
		if [ "$ADDON" = "$FILE" ] || ! download "${SLX_BASE_PATH}/${ADDON}.sqfs" "${ADDON_TARGET_PATH}"; then
			slxlog --echo "addon-download" "Download of '${HTTP_BASE_PATH}/${FILE}.sqfs' failed. (${ADDON})"
		fi
		exit 1
	fi
fi

[ $# -gt 1 ] && { echo "$0 needs 0 or 1 arguments! $# given."; exit 1; }

exit 0