summaryrefslogblamecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/vmchooser/data/linux/vm_installer
blob: 323ed0a4a71910235f9503437fcb0ab15e801788 (plain) (tree)
1
2
3
4
5
6
7
8







                        


                                            








                                                                














                                                                                                                    
 

                                                                                                                      
                              

                                                              




                                                                      

                                                                                     

                                                                         

















                                                                                                                                    


                                                                                                                                       
                                                                                                                                      
 


                                                                                                                          



                                                                   
 










































                                                                                                                                    
#!/bin/bash

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
		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

		echo "openslx praeinstaller: installing systemd service (resolution utility) to ${SERVICEDIR}/${SERVICERESOLUTION}."
		cat <<-THEREDOC > "$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
		THEREDOC


		[ ! -d /etc/systemd/system/graphical.target.wants ]	&& mkdir /etc/systemd/system/graphical.target.wants 2>/dev/null
		[ ! -d /etc/systemd/system/basic.target.wants ]		&& mkdir /etc/systemd/system/basic.target.wants 2>/dev/null
		[ ! -d /etc/systemd/system/shutdown.target.wants ]	&& mkdir /etc/systemd/system/shutdown.target.wants 2>/dev/null

		ln -s "${SERVICEDIR}"/"${SERVICEMOUNT}" /etc/systemd/system/graphical.target.wants/"${SERVICEMOUNT}"
		ln -s "${SERVICEDIR}"/"${SERVICEUMOUNT}" /etc/systemd/system/shutdown.target.wants/"${SERVICEUMOUNT}"
		ln -s "${SERVICEDIR}"/"${SERVICERESOLUTION}" /etc/systemd/system/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