summarylogtreecommitdiffstats
path: root/ffplayout.install
blob: a8671ce352e2af824c05a5f1c61fb6d3d566f8cd (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
post_install() {

	systemctl unmask ffplayout.service >/dev/null || true
	systemctl --system daemon-reload >/dev/null || true

	sysUser="ffpu"
	IP=$(ip route get 1.2.3.4 | awk '{if($7 !~ /^[[:space:]]*$/) print $7}')

	if [ -f /run/.containerenv ] || [ -f /run/.dockerenv ] || [ -f /.dockerenv ] || [ -f /.dockerinit ]; then
		sysUser="root"
	fi

	if [ ! $(id -u $sysUser 2>/dev/null || echo -1) -ge 0 ]; then
		useradd -m --system $sysUser || adduser --system --create-home $sysUser >/dev/null || adduser --system --home "/home/$sysUser" $sysUser
	fi

	if [ ! -d "/usr/share/ffplayout/db" ]; then
		mkdir "/usr/share/ffplayout/db"
		mkdir -p "/var/lib/ffplayout/playlists"
		mkdir -p "/var/lib/ffplayout/tv-media"

		/usr/bin/ffplayout -d "${IP}:8787" \
			-u admin \
			-p admin \
			-m ffplayout@example.org \
			--shared-storage

		chown -R ${sysUser}: "/usr/share/ffplayout"
		chown -R ${sysUser}: "/var/lib/ffplayout"
	else
		chown -R ${sysUser}: "/usr/share/ffplayout"
		chown -R ${sysUser}: "/var/lib/ffplayout"
	fi

	if [ ! -d "/var/log/ffplayout" ]; then
		mkdir "/var/log/ffplayout"

		chown ${sysUser}: "/var/log/ffplayout"
	else
		chown ${sysUser}: "/var/log/ffplayout"
	fi

	tab="   "
	echo -e "1. Activate systemd service:"
	echo -e "   $ systemctl enable --now ffplayout"
	echo -e "2. Use a reverse proxy for SSL, Port is 8787."
	echo -e "3. Login with your browser, address without proxy would be: http://${IP}:8787, \n${tab}the default account is \"admin\" and the password is \"admin\"."
	echo -e "4. Default location for playlists and media files are: /var/lib/ffplayout/."
	echo -e "5. If you want to change the default global settings:"
	echo -e "   $ sudo rm -v /usr/share/ffplayout/db/*"
	echo -e "   $ sudo -u ffpu ffplayout -i -d \"${IP}:8787\""

}

post_upgrade() {
	post_install
}

pre_remove() {

	if [ -d /run/systemd/system ]; then
		for service in $(systemctl list-units --type service --all --no-legend --plain | grep 'ffplayout' | awk '{print $1}'); do
			systemctl stop "$service" >/dev/null || true
		done
	fi

}

post_remove() {

	systemctl --system daemon-reload >/dev/null || true
	systemctl unmask ffplayout.service >/dev/null || true

	sysUser="ffpu"

	if [ $(id -u $sysUser 2>/dev/null || echo -1) -ge 0 ]; then
		userdel -r -f $sysUser
	fi

	rm -rf /var/log/ffplayout

}