summarylogtreecommitdiffstats
path: root/spotcommander.install
blob: 28106c3f35ef260999664220c6be8701f68bf69b (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
post_install()
{
	echo "Configuring PHP..."
	
	sed -i 's/;extension=curl.so/extension=curl.so/' /etc/php/php.ini
	sed -i 's/;extension=pdo_sqlite.so/extension=pdo_sqlite.so/' /etc/php/php.ini
	sed -i 's/;extension=posix.so/extension=posix.so/' /etc/php/php.ini
	sed -i 's/;extension=sqlite3.so/extension=sqlite3.so/' /etc/php/php.ini
	
	echo "Configuring Apache..."
	
	sed -i 's/LoadModule mpm_event_module modules\/mod_mpm_event.so/#LoadModule mpm_event_module modules\/mod_mpm_event.so/' /etc/httpd/conf/httpd.conf

	echo -e "\n# Start SpotCommander configuration" >> /etc/httpd/conf/httpd.conf
	echo "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so" >> /etc/httpd/conf/httpd.conf
	echo "LoadModule php5_module modules/libphp5.so" >> /etc/httpd/conf/httpd.conf
	echo "Include conf/extra/php5_module.conf" >> /etc/httpd/conf/httpd.conf
	echo "Include conf/extra/spotcommander.conf" >> /etc/httpd/conf/httpd.conf
	echo -e "# End SpotCommander configuration\n" >> /etc/httpd/conf/httpd.conf

	echo -e "Alias /spotcommander /usr/share/webapps/spotcommander\n\n<Directory \"/usr/share/webapps/spotcommander\">\nAllowOverride AuthConfig\nRequire all granted\n</Directory>" > /etc/httpd/conf/extra/spotcommander.conf

	systemctl restart httpd.service 1>/dev/null 2>&1

	systemctl enable httpd.service 1>/dev/null 2>&1
	
	echo "Creating symlink..."
	
	ln -s /usr/share/webapps/spotcommander/bin/spotcommander /usr/bin/spotcommander
	
	echo "Adding daemon to startup applications..."
	
	echo -e "[Desktop Entry]\nType=Application\nName=SpotCommander\nExec=spotcommander start" > /etc/xdg/autostart/spotcommander.desktop

echo "
 --------------------------------------------------------------
 | Installation complete!                                     |
 |                                                            |
 | YOU MUST NOW RE-LOGIN TO YOUR DESKTOP TO START THE DAEMON. |
 |                                                            |
 | You should then be able to control Spotify by going to:    |
 |                                                            |
 | http://this.computers.ip.address.or.hostname/spotcommander |
 --------------------------------------------------------------
"

}

pre_upgrade()
{
	spotcommander stop
	
	echo "Backing up playlists and library in case of upgrade..."
	
	cp -p /usr/share/webapps/spotcommander/db/playlists.db /tmp/spotcommander-playlists.db
	cp -p /usr/share/webapps/spotcommander/db/library.db /tmp/spotcommander-library.db

	echo "Backing up Spotify authorization in case of upgrade..."

	cp -p /usr/share/webapps/spotcommander/run/spotify.country /tmp/spotcommander-spotify.country
	cp -p /usr/share/webapps/spotcommander/run/spotify.token /tmp/spotcommander-spotify.token
	cp -p /usr/share/webapps/spotcommander/run/spotify.username /tmp/spotcommander-spotify.username
	
	echo "Backing up authentication configuration in case of upgrade..."
	
	cp -p /usr/share/webapps/spotcommander/.htaccess /tmp/spotcommander-htaccess
	cp -p /usr/share/webapps/spotcommander/.htpasswd /tmp/spotcommander-htpasswd
}

post_upgrade()
{	
	if [ -e /tmp/spotcommander-playlists.db ]; then
	
		echo "Restoring playlists..."

		cp -p /tmp/spotcommander-playlists.db /usr/share/webapps/spotcommander/db/playlists.db
	
	fi

	if [ -e /tmp/spotcommander-library.db ]; then
	
		echo "Restoring library..."

		cp -p /tmp/spotcommander-library.db /usr/share/webapps/spotcommander/db/library.db
	
	fi

	if [ -e /tmp/spotcommander-spotify.token ]; then

		echo "Restoring Spotify authorization..."

		cp -p /tmp/spotcommander-spotify.country /usr/share/webapps/spotcommander/run/spotify.country
		cp -p /tmp/spotcommander-spotify.token /usr/share/webapps/spotcommander/run/spotify.token
		cp -p /tmp/spotcommander-spotify.username /usr/share/webapps/spotcommander/run/spotify.username

	fi
	
	if [ -e /tmp/spotcommander-htaccess ]; then
	
		echo "Restoring authentication configuration..."

		cp -p /tmp/spotcommander-htaccess /usr/share/webapps/spotcommander/.htaccess
		cp -p /tmp/spotcommander-htpasswd /usr/share/webapps/spotcommander/.htpasswd
	
	fi

echo "
 --------------------------------------------------------------
 | Upgrade complete!                                          |
 |                                                            |
 | YOU MUST NOW RE-LOGIN TO YOUR DESKTOP TO START THE DAEMON. |
 |                                                            |
 | You should then be able to control Spotify by going to:    |
 |                                                            |
 | http://this.computers.ip.address.or.hostname/spotcommander |
 --------------------------------------------------------------
"

}

pre_remove()
{
	spotcommander stop
	
	echo "Deleting files..."
	
	rm -f /usr/share/webapps/spotcommander/run/daemon-user-*.socket
	rm /usr/bin/spotcommander
	rm /etc/httpd/conf/extra/spotcommander.conf
	rm /etc/xdg/autostart/spotcommander.desktop
	
	echo "Configuring Apache..."
	
	sed -i '/# Start SpotCommander configuration/,/# End SpotCommander configuration/d' /etc/httpd/conf/httpd.conf

	sed -i 's/#LoadModule mpm_event_module modules\/mod_mpm_event.so/LoadModule mpm_event_module modules\/mod_mpm_event.so/' /etc/httpd/conf/httpd.conf

	systemctl restart httpd.service 1>/dev/null 2>&1
	
	echo "Uninstallation complete!"
}