summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/vm_installer
blob: 240c0a27bcbfc1c32c4206b8a1de103cab154df0 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash

# set -x

PS=$(which ps)
GREP=$(which grep)
LOGGER=$(which logger)
MKDIR=$(which mkdir)
MOUNT=$(which mount)
MOUNTDIR=/mnt/diskmount/
SERVICEMOUNT=openslx-mount.service
SERVICEUMOUNT=openslx-umount.service
SERVICERESOLUTION=openslx-resolution.service

# systemd erkennen
case $(${PS} --pid 1 -o comm h) in
	systemd) echo "openslx praeinstaller: systemd detected."
		if [ -d /etc/systemd/system ]; then
			SERVICEDIR=/etc/systemd/system/
		else
			SERVICEDIR=/usr/lib/systemd/system/
		fi

		if [ -L "${SERVICEDIR}/graphical.target.wants/${SERVICEMOUNT}" ] \
				|| [ -L "${SERVICEDIR}/graphical.target.wants/${SERVICEUMOUNT}" ] \
				|| [ -L "${SERVICEDIR}/graphical.target.wants/${SERVICERESOLUTION}" ]; then
			while [ "$RESCRIPT" != "y" ] && [ "$RESCRIPT" != "n" ]; do
				RESCRIPTDEF=y
				read -e -p "There seems to an older install. Delete (y/n, Default is $RESCRIPTDEF, Ctrl-C to exit): " RESCRIPT
				RESCRIPT="${RESCRIPT:-$RESCRIPTDEF}"
			done
		fi

		if [ "${RESCRIPT}" == "y" ]; then
			# Just unlink stuff...
			echo "Deleting old links..."
			unlink "${SERVICEDIR}/graphical.target.wants/${SERVICEMOUNT}" 2>/dev/null
			unlink "${SERVICEDIR}/shutdown.target.wants/${SERVICEUMOUNT}" 2>/dev/null
			unlink "${SERVICEDIR}/basic.target.wants/${SERVICERESOLUTION}" 2>/dev/null
		fi

		echo "openslx praeinstaller: installing systemd service (mounter) to ${SERVICEDIR}/${SERVICEMOUNT}."
		cat <<-HEREDOC > "$SERVICEDIR"/"$SERVICEMOUNT"
			[Unit]
			Description=openSLX share mounter
			After=basic.target
			
			[Service]
			Type=oneshot
			ExecStartPre=${MKDIR} -p /mnt/diskmount
			ExecStartPre=-${MOUNT} /dev/fd1 /mnt/diskmount
			ExecStart=${LOGGER} "openslx service file: mounter started."
			ExecStart=${MOUNTDIR}/linux/mnt_shares
			ExecStart=${LOGGER} "openslx service file: done."
			RemainAfterExit=yes
		HEREDOC

		echo "openslx praeinstaller: installing systemd service (umounter) to ${SERVICEDIR}/${SERVICEUMOUNT}."
		cat <<-THEREDOC > "$SERVICEDIR"/"${SERVICEUMOUNT}"
			[Unit]
			Description=openSLX resolution utility
			Before=shutdown.target 
			
			[Service]
			Type=oneshot
			ExecStartPre=${MKDIR} -p /mnt/diskmount
			ExecStartPre=-${MOUNT} /dev/fd1 /mnt/diskmount
			ExecStart=${LOGGER} "openslx service file: umounter started."
			ExecStart=${MOUNTDIR}/linux/umount
			ExecStart=${LOGGER} "openslx service file: done."
			RemainAfterExit=no
		THEREDOC

# This bloc was meant for a resolution setting alternative via xorg.conf.d. As this did not work on time, it's
# just commented for now due to programmer's laziness, who was too lazy to store it elsewhere.
#		echo
#		echo "openslx praeinstaller: Which resolution script to install?"
#		echo
#		echo "There are two possibilies:"
#		echo ""
#		echo '1)	A script which waits until the xserver started, then checks for possible'
#		echo '	modelines (writes one if no sufficient modeline is detected, and waits for'
#		echo '	some time afterwards whether resolution changes again (eg. via display manager'
#		echo '	or such stuff. Fairly stable no more XSetup/Xreset patching.'
#		echo
#		echo '2)	Just a screen configuration dropped to xorg.conf.d, which restricts'
#		echo '	possible screen resolutions to just one. This may give trouble when screen,'
#		echo '	monitor etc. are hard-wired elsewhere (xorg.conf, xorg.conf.d).'
#		echo
#
#		while [ "$RESCRIPT" != "1" ] && [ "$RESCRIPT" != "2" ]; do
#			RESCRIPTDEF=1
#			read -e -p "Well, which one do you choose? (1/2, Default is $RESCRIPTDEF): " RESCRIPT
#			RESCRIPT="${RESCRIPT:-$RESCRIPTDEF}"
#		done
#
#		case $RESCRIPT in
#			1)	echo "openslx praeinstaller: installing systemd service (resolution utility) to ${SERVICEDIR}/${SERVICERESOLUTION}."
				echo "openslx praeinstaller: installing systemd service (resolution utility) to ${SERVICEDIR}/${SERVICERESOLUTION}."
				cat <<-SOMEWHEREDOC > "$SERVICEDIR"/"${SERVICERESOLUTION}"
				[Unit]
				Description=openSLX resolution utility
				After=display-manager.service

				[Service]
				Type=oneshot
				ExecStartPre=${MKDIR} -p /mnt/diskmount
				ExecStartPre=-${MOUNT} /dev/fd1 /mnt/diskmount
				ExecStart=${LOGGER} "openslx service file: resolution utility started."
				ExecStart=${MOUNTDIR}/linux/resolution
				ExecStart=${LOGGER} "openslx service file: done."
				RemainAfterExit=yes
				SOMEWHEREDOC
#				;;
#			2)	echo "openslx praeinstaller: installing systemd service (xorg.conf.d entry) to ${SERVICEDIR}/${SERVICERESOLUTION}."
#				cat <<-THEREDOC > "$SERVICEDIR"/"${SERVICERESOLUTION}"
#				[Unit]
#				Description=openSLX xorg.conf.d entry
#				Before=display-manager.service
#				[Service]
#				Type=oneshot
#				ExecStartPre=${MKDIR} -p /mnt/diskmount
#				ExecStartPre=-${MOUNT} /dev/fd1 /mnt/diskmount
#				ExecStart=${LOGGER} "openslx service file: resolution utility started."
#				ExecStart=${MOUNTDIR}/linux/xorgconf
#				ExecStart=${LOGGER} "openslx service file: done."
#				RemainAfterExit=yes
#				THEREDOC
#				;;
#			*)	echo "openslx praeinstaller: This should not have happened: RESCRIPT ($RESCRIPT) not set!"
#				exit 1
#				;;
#esac

		[ ! -d "$SERVICEDIR"/graphical.target.wants ]	&& mkdir "$SERVICEDIR"/graphical.target.wants 2>/dev/null
		[ ! -d "$SERVICEDIR"/basic.target.wants ]	&& mkdir "$SERVICEDIR"/basic.target.wants 2>/dev/null
		[ ! -d "$SERVICEDIR"/shutdown.target.wants ]	&& mkdir "$SERVICEDIR"/shutdown.target.wants 2>/dev/null

		ln -s "${SERVICEDIR}"/"${SERVICEMOUNT}" "$SERVICEDIR"/graphical.target.wants/"${SERVICEMOUNT}"
		ln -s "${SERVICEDIR}"/"${SERVICEUMOUNT}" "$SERVICEDIR"/shutdown.target.wants/"${SERVICEUMOUNT}"
		ln -s "${SERVICEDIR}"/"${SERVICERESOLUTION}" "$SERVICEDIR"/basic.target.wants/"${SERVICERESOLUTION}"

		echo "openslx praeinstaller: doing systemd reload."
		systemctl daemon-reload
		;;

	init)	echo "openslx praeinstaller: init(V) detected."
		SERVICEDIR=/etc/init.d/
		[ ! -d "${SERVICEDIR}" ] && { echo "openslx praeinstaller: No init directory $SERVICEDIR found, exiting."; exit 1; }
		SERVICEFILE=openslx-scriptinstall
		echo "openslx praeinstaller: installing init service file to ${SERVICEDIR}/${SERVICEFILE}."
		cat <<-THEREDOC > "${SERVICEDIR}"/"${SERVICEFILE}"
			#!/bin/sh -e
			### BEGIN INIT INFO
			# Provides: openSLX_scriptinstaller
			# Required-Start: 2 3 4 5
			# Required-Stop: 0 1 6
			# Default-Start: 2 3 4 5
			# Default-Stop: 0 1 6
			# X-Interactive: false
			# Short-Description: openSLX script package starter.
			### END INIT INFO
			#
			# Starts via Xsetup patching the openSLX script package
			# to correct screen resolution and mount network shares
			# when Xsetup is started.
			
			case "\$1" in
				start)  ${LOGGER} "openslx init file: started."
					${MKDIR} -p /mnt/diskmount
				        ${MOUNT} | ${GREP} -q /mnt/diskmount || ${MOUNT} /dev/fd1 /mnt/diskmount
				        ${MOUNTDIR}/linux/vm_runtime
					${LOGGER} "openslx init file: done."
				        ;;
				stop|restart|force-reload) exit 0 ;;
				*)      echo "Usage: $0 {start}" >&2; exit 1 ;;
			esac
		THEREDOC
		chmod +x "${SERVICEDIR}"/"${SERVICEFILE}"
		echo "openslx praeinstaller: enabling ${SERVICEFILE}."
		update-rc.d "${SERVICEFILE}" defaults
		;;
	*)	echo "openslx praeinstaller: Could not determine mother-of-all-processes (not systemd, not init)."
		echo "openslx praeinstaller: Giving up, exiting."
		exit 1
esac

exit 0