summarylogtreecommitdiffstats
path: root/splashtop-streamer.install
blob: 8e354d2e5c969a3c8bf02b8001ee6cab85210980 (plain)
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
pre_install() {

	if [ "$1" = "install" ]; then
	    echo "[Splashtop-Streamer] Install streamer"
	fi

	if [ "$1" = "upgrade" ]; then
	    echo "[Splashtop-Streamer] Upgrade streamer"
	fi

	if [ -f "/opt/splashtop-streamer/config/global.conf" ]; then
	    echo "[Splashtop-Streamer] Backup streamer settings"
	fi

}

post_install() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
	echo "[Splashtop-Streamer] Configure streamer"
    if [ ! -e "/etc/splashtop-streamer.conf" ]; then
        echo "LastConfigured=`date +%s`" > /etc/splashtop-streamer.conf
    fi
	if [ ! -d "/opt/splashtop-streamer/config/" ]; then
		mkdir /opt/splashtop-streamer/config/
	fi
	if [ ! -d "/opt/splashtop-streamer/dump/" ]; then
		mkdir /opt/splashtop-streamer/dump/
	fi
	if [ ! -d "/opt/splashtop-streamer/log/" ]; then
		mkdir /opt/splashtop-streamer/log/
	fi
	chmod a=rwx /opt/splashtop-streamer/config

	if [ ! -f "/usr/bin/splashtop-streamer" ]; then
		echo "[Splashtop-Streamer] Install user binary link"
		ln -s /opt/splashtop-streamer/script/splashtop-streamer /usr/bin/splashtop-streamer
	fi

	#
	# WORKAROUND
	# In Ubuntu 20.04 MATE Desktop Environment, the desktop entry for "Splashtop Streamer"
	# cannot be found in brisk-menu immediately after installed the .deb.
	# Append an new line to /usr/share/applications/com.splashtop.streamer.desktop
	# to trigger the brisk-menu to show "Splashtop Streamer" immediately.
	#
	echo "" >> /usr/share/applications/com.splashtop.streamer.desktop

	if [ -e /etc/gdm3/custom.conf ];then
		if grep -Fq "#WaylandEnable=false" /etc/gdm/custom.conf; then
			REBOOT_REQUIRED="1"
		fi
		sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf
	fi

	# Allow GDM3 in wayland mode to save screeshot to disk, reboot is required
	GDM_SETTINGS_AUTO_PATCH="0" # Experimental - disabled for now
	if [ "$GDM_SETTINGS_AUTO_PATCH" = "1" ]; then
		REBOOT_REQUIRED="1"
		echo "[Splashtop-Streamer] Enable gdm to save file to disk for screenshot in wayland mode"
		/opt/splashtop-streamer/script/gdm-disable-save-to-disk.sh false || true
	fi

	if [ -d /usr/lib/systemd/system/ ]; then
		echo "[Splashtop-Streamer] Install streamer service"
		ln -s /usr/lib/systemd/system/SRStreamer.service /etc/systemd/system/SRStreamer.service
	fi

	if [ -f "/etc/systemd/system/SRStreamer.service" ]; then
		echo "[Splashtop-Streamer] Start streamer service"
		systemctl daemon-reload
		systemctl restart SRStreamer.service
		systemctl enable /usr/lib/systemd/system/SRStreamer.service
	fi

	if [ "$REBOOT_REQUIRED" = "1" ]; then
		echo "[SplashtopStreamer]: =============================="
		echo "[SplashtopStreamer]: Please reboot to apply changes"
		echo "[SplashtopStreamer]: =============================="
	fi


	update-desktop-database -q
}

pre_upgrade() {
	ver2=$(pacman -Q splashtop-streamer 2>&1 |grep -i -c -E "splashtop-streamer (2\.[0-9]\.)")
	if [[ "$ver2" -ne 0 ]];
	then
	echo "Cleaning up old install"
	if [ -f "/etc/systemd/system/SRStreamer.service" ]; then
		echo "[Splashtop-Streamer] Stop streamer service"
	    systemctl disable SRStreamer.service
		echo "[Splashtop-Streamer] Remove streamer service"
	    rm /usr/lib/systemd/system/SRStreamer.service
	    systemctl daemon-reload
		pidof SRFeature | xargs kill -9
		if [ "$(pgrep -f 'SRStreamer.pyc' | wc -w)" != 0 ]; then
			pgrep -f SRStreamer.pyc | xargs kill -9
		fi
	fi
	if [ -e /etc/pam.d/common-session ]; then
		sed -i '/session optional    pam_splashtop.so/d' /etc/pam.d/common-session
		if [ -f "/usr/lib/x86_64-linux-gnu/security/pam_splashtop.so" ]; then
			echo "[Splashtop-Streamer] Remove PAM module, as not needed."
			rm /usr/lib/x86_64-linux-gnu/security/pam_splashtop.so
		fi
	fi
    find /home -type f | grep /.config/autostart/com.splashtop.streamer.desktop | xargs rm -f
	cp /opt/splashtop-streamer/config/global.conf /tmp/streamerconf
    rm /usr/bin/splashtop-streamer
	rm -rf /opt/splashtop-streamer
	mkdir -p /opt/splashtop-streamer/config/
	mv /tmp/streamerconf /opt/splashtop-streamer/config/global.conf
	chmod a=rwx /opt/splashtop-streamer/config

fi
	pre_install
}

post_upgrade() {
	post_install
}

pre_remove() {

	if [ "$1" = "remove" ]; then
		if [ -f /tmp/sru ]; then
			rm /tmp/sru
		fi
		if [ -f "/opt/splashtop-streamer/SRUtility" ]; then
			cp /opt/splashtop-streamer/SRUtility /tmp/sru
		fi
	fi

	if [ -f "/etc/systemd/system/SRStreamer.service" ]; then
		echo "[Splashtop-Streamer] Stop streamer service"
		systemctl stop SRStreamer.service
		echo "[Splashtop-Streamer] Disable streamer service"
		systemctl disable SRStreamer.service
		echo "[Splashtop-Streamer] Remove streamer service"
		rm /usr/lib/systemd/system/SRStreamer.service
		systemctl daemon-reload
		# Kill SRStreamer processes, ignore error here
		killall -q -9 SRStreamer || true
	fi

	GDM_SETTINGS_AUTO_PATCH="0" # Experimental - disabled for now
	if [ "$GDM_SETTINGS_AUTO_PATCH" = "1" ]; then
		echo "[Splashtop-Streamer] Disable gdm to save file to disk"
		/opt/splashtop-streamer/script/gdm-disable-save-to-disk.sh true || true
	fi

}

post_remove() {
	gtk-update-icon-cache -q -t -f usr/share/icons/hicolor
		if [ -d "/opt/splashtop-streamer/config/" ]; then
			echo "[Splashtop-Streamer] Remove streamer settings"
			if [ -f /tmp/sru ]; then
				/tmp/sru -remove
				rm /tmp/sru
			fi

			rm -rf /opt/splashtop-streamer/config/global.conf
			rm -rf /opt/splashtop-streamer/config/region.json
		fi

    find /home -type f | grep /.config/autostart/com.splashtop.streamer.desktop | xargs rm -f
	rm /usr/bin/splashtop-streamer
	rm -rf /opt/splashtop-streamer
	rm /etc/splashtop-streamer.conf

	update-desktop-database -q
}