-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
install.sh
executable file
·295 lines (254 loc) · 11.8 KB
/
install.sh
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
#########################################################################
## ##
## ┏━╸┏━┓╻ ╻┏━╸┏━┓ ╺┳╸╻ ╻╻ ╻┏┳┓┏┓ ┏┓╻┏━┓╻╻ ┏━╸┏━┓ ##
## ┃ ┃ ┃┃┏┛┣╸ ┣┳┛ ┃ ┣━┫┃ ┃┃┃┃┣┻┓┃┗┫┣━┫┃┃ ┣╸ ┣┳┛ ##
## ┗━╸┗━┛┗┛ ┗━╸╹┗╸ ╹ ╹ ╹┗━┛╹ ╹┗━┛╹ ╹╹ ╹╹┗━╸┗━╸╹┗╸ ##
## — www.flogisoft.com — ##
## ##
############################################################################
## ##
## Cover thumbnailer — Installer ##
## ##
## Copyright (C) 2009 - 2024 Fabien Loison <flo at flogisoft dot com> ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
############################################################################
## ##
## VERSION : 0.10.2 (Sat Dec 14 18:29:51 CET 2024) ##
## WEB SITE : https://github.com/flozz/cover-thumbnailer ##
## ##
#########################################################################
SOFTWARE="Cover Thumbnailer"
DESC="Displays music album covers in Nautilus and more..."
LOGFILE="/tmp/cover-thumbnailer$1_$$.log"
_install() {
#Install the software
#$1 : The installation path if different of /
#Check if an older version is installed
if [ -z $1 ] ; then { #Only for --install
_check_for_old_version
} fi
#/usr/bin
mkdir -pv "$1"/usr/bin 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./cover-thumbnailer.py "$1"/usr/bin/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
chmod -v 755 "$1"/usr/bin/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./cover-thumbnailer-gui.py "$1"/usr/bin/cover-thumbnailer-gui 1>> $LOGFILE 2>> $LOGFILE || error=1
chmod -v 755 "$1"/usr/bin/cover-thumbnailer-gui 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/cover-thumbnailer/
mkdir -pv "$1"/usr/share/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -rv ./share/* "$1"/usr/share/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/man/man1
mkdir -pv "$1"/usr/share/man/man1 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./man/cover-thumbnailer.1 "$1"/usr/share/man/man1/ 1>> $LOGFILE 2>> $LOGFILE || error=1
gzip --best -f "$1"/usr/share/man/man1/cover-thumbnailer.1 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./man/cover-thumbnailer-gui.1 "$1"/usr/share/man/man1/ 1>> $LOGFILE 2>> $LOGFILE || error=1
gzip --best -f "$1"/usr/share/man/man1/cover-thumbnailer-gui.1 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/doc/cover-thumbnailer
mkdir -pv "$1"/usr/share/doc/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./README.md "$1"/usr/share/doc/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/locale/xx_XX/LC_MESSAGES
for file in `find ./locale -name "*.po"` ; do {
l10elang=`echo $file | sed -r 's#./locale/(.*).po#\1#g'`
mkdir -pv "$1"/usr/share/locale/$l10elang/LC_MESSAGES/ 1>> $LOGFILE 2>> $LOGFILE || error=1
msgfmt "$file" -o "$1"/usr/share/locale/$l10elang/LC_MESSAGES/cover-thumbnailer-gui.mo 1>> $LOGFILE 2>> $LOGFILE || error=1
} done
#/usr/share/applications
mkdir -pv "$1"/usr/share/applications/ 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./freedesktop/cover-thumbnailer-gui.desktop "$1"/usr/share/applications/cover-thumbnailer-gui.desktop 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/thumbnailers
mkdir -pv "$1"/usr/share/thumbnailers/ 1>> $LOGFILE 2>> $LOGFILE || error=1
cp -v ./freedesktop/cover.thumbnailer "$1"/usr/share/thumbnailers/cover.thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
#uninstall.sh
if [ -z $1 ] ; then {
cp ./install.sh /usr/share/cover-thumbnailer/uninstall.sh 1>> $LOGFILE 2>> $LOGFILE || error=1
chmod -v 755 /usr/share/cover-thumbnailer/uninstall.sh 1>> $LOGFILE 2>> $LOGFILE || error=1
} fi
if [ "$error" == "1" ] ; then {
echo "$_RED E:$_NORMAL An error occurred when installing $SOFTWARE"
echo "$_RED E:$_NORMAL See the log file for more informations."
echo "$_RED E:$_NORMAL $LOGFILE"
exit 20
} else {
echo " $_GREEN$SOFTWARE was successfully installed on your computer$_NORMAL"
rm $LOGFILE 1> /dev/null 2> /dev/null
} fi
}
_remove() {
#Remove the software
#/usr/share/applications
rm -fv /usr/share/applications/cover-thumbnailer-gui.desktop 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/cover-thumbnailer
rm -rfv /usr/share/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/doc
rm -rfv /usr/share/doc/cover-thumbnailer/ 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/man/man1
rm -vf /usr/share/man/man1/cover-thumbnailer.1.gz 1>> $LOGFILE 2>> $LOGFILE || error=1
rm -vf /usr/share/man/man1/cover-thumbnailer-gui.1.gz 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/locale/xx_XX/LC_MESSAGES/cover-thumbnailer-gui.mo
find /usr/share/locale/ \
-name cover-thumbnailer-gui.mo \
-exec rm -v '{}' ';' \
1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/bin
rm -vf /usr/bin/cover-thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
rm -vf /usr/bin/cover-thumbnailer-gui 1>> $LOGFILE 2>> $LOGFILE || error=1
#/usr/share/thumbnailers
rm -vf /usr/share/thumbnailers/cover.thumbnailer 1>> $LOGFILE 2>> $LOGFILE || error=1
if [ "$error" == "1" ] ; then {
echo "$_RED E:$_NORMAL An error occurred when removing $SOFTWARE"
echo "$_RED E:$_NORMAL See the log file for more informations."
echo "$_RED E:$_NORMAL $LOGFILE"
exit 20
} else {
echo " $_GREEN$SOFTWARE was successfully removed from your computer$_NORMAL"
rm $LOGFILE 1> /dev/null 2> /dev/null
} fi
}
_locale() {
#Extracts strings
mkdir -pv ./locale/
xgettext -k_ -kN_ \
-o ./locale/cover-thumbnailer-gui.pot \
./cover-thumbnailer-gui.py \
./share/cover-thumbnailer-gui.glade
for lcfile in $(find ./locale/ -name "*.po") ; do {
echo -n " * $lcfile"
msgmerge --update $lcfile ./locale/cover-thumbnailer-gui.pot
} done
}
_check_for_old_version() {
#Checks if an older version is installed, and try to remove.
echo " * Checking for old version..."
if [ -d /usr/share/cover-thumbnailer/ ] ; then { #Version >= 0.4
echo " Version 0.4 or newer found."
if [ -x /usr/share/cover-thumbnailer/uninstall.sh ] ; then {
/usr/share/cover-thumbnailer/uninstall.sh --remove 1>> $LOGFILE 2>> $LOGFILE || error=1
if [ "$error" == "1" ] ; then {
echo " E: An error occurred when removing installed version."
echo " E: See the log file for more informations."
echo " E: $LOGFILE"
exit 11
} else {
echo " * Old version successfully removed"
} fi
} else {
echo " E: Can't remove the installed version."
echo " E: Remove it manually and run this script again."
exit 10
} fi
} fi
}
_check_dep() {
#Checks dependencies
echo "$_BOLD * Checking dependencies...$_NORMAL"
echo -n " * Python 3 ............................ "
test -x /usr/bin/python3 && echo "$_GREEN[OK]$_NORMAL" || { echo "$_RED[Missing]$_NORMAL" ; error=1 ; }
echo -n " * Python Imaging Library (PIL) ........ "
$_PY <<< "$(echo -e "try: from PIL import Image\nexcept: import Image")" 1> /dev/null 2> /dev/null && echo "$_GREEN[OK]$_NORMAL" || { echo "$_RED[Missing]$_NORMAL" ; error=1 ; }
echo -n " * Python gi and GTK introspection ..... "
$_PY <<< "import gi ; gi.require_version('Gtk', '3.0') ; from gi.repository import Gtk" 1> /dev/null 2> /dev/null && echo "$_GREEN[OK]$_NORMAL" || { echo "$_RED[Missing]$_NORMAL" ; error=1 ; }
echo -n " * Python gettext support .............. "
$_PY <<< "import gettext" 1> /dev/null 2> /dev/null && echo "$_GREEN[OK]$_NORMAL" || { echo "$_RED[Missing]$_NORMAL" ; error=1 ; }
if [ "$error" == "1" ] ; then {
echo "$_RED E:$_NORMAL Some dependencies are missing."
exit 30
} fi
}
_check_build_dep() {
#Checks build dependencies
echo "$_BOLD * Checking build dependencies...$_NORMAL"
echo -n " * gettext ............................. "
test -x /usr/bin/xgettext && echo "$_GREEN[OK]$_NORMAL" || { echo "$_RED[Missing]$_NORMAL" ; error=1 ; }
if [ "$error" == "1" ] ; then {
echo "$_RED E:$_NORMAL Some build dependencies are missing."
exit 31
} fi
}
#Go to the script directory
cd "${0%/*}" 1> /dev/null 2> /dev/null
#Force English
export LANG=C
#Header
echo -e "$SOFTWARE - $DESC\n"
#Python
export _PY=/usr/bin/python3
#Action do to
if [ "$1" == "--install" ] || [ "$1" == "-i" ] ; then {
#Colors
_RED=$(echo -e "\033[1;31m")
_GREEN=$(echo -e "\033[1;32m")
_NORMAL=$(echo -e "\033[0m")
_BOLD=$(echo -e "\033[1m")
if [ "$(whoami)" == "root" ] ; then {
_check_build_dep
_check_dep
echo "$_BOLD * Installing $SOFTWARE...$_NORMAL"
_install
} else {
echo "$_BOLD * Installing $SOFTWARE...$_NORMAL"
echo "$_RED E:$_NORMAL Need to be root"
exit 1
} fi
} elif [ "$1" == "--package" ] || [ "$1" == "-p" ] ; then {
_check_build_dep
echo " * Packaging $SOFTWARE..."
mkdir -p "$2" 1> /dev/null 2> /dev/null #create the output directory if not exists
#Check if the directory is empty
if [ $(find "$2" | wc -l) != 1 ] ; then
echo "E: The destination folder '$2' is not empty..."
exit 5
fi
if [ -d "$2" ] ; then {
_install "$2"
} else {
echo " E: '$2' is not a directory"
exit 2
} fi
} elif [ "$1" == "--remove" ] || [ "$1" == "-r" ] ; then {
#Colors
_RED=$(echo -e "\033[1;31m")
_GREEN=$(echo -e "\033[1;32m")
_NORMAL=$(echo -e "\033[0m")
_BOLD=$(echo -e "\033[1m")
echo "$_BOLD * Removing $SOFTWARE...$_NORMAL"
if [ "$(whoami)" == "root" ] ; then {
_remove
} else {
echo "$_RED E:$_NORMAL Need to be root"
exit 1
} fi
} elif [ "$1" == "--locale" ] || [ "$1" == "-l" ] ; then {
#Colors
_RED=$(echo -e "\033[1;31m")
_GREEN=$(echo -e "\033[1;32m")
_NORMAL=$(echo -e "\033[0m")
_BOLD=$(echo -e "\033[1m")
echo "$_BOLD * Extracting strings for the translation template...$_NORMAL"
if [ -x /usr/bin/xgettext ] ; then {
_locale
} else {
echo "$_RED E:$_NORMAL Can't find xgettext... Please install gettext and try again."
exit 3
} fi
} else {
echo "Arguments:"
echo " --install : install $SOFTWARE on your computer."
echo " --package <path> : install $SOFTWARE in <path> (Useful for packaging)."
echo " NOTE: <path> with no slash ('/') at the end"
echo " --remove : remove $SOFTWARE from your computer."
echo " --locale : extract strings to for the translation template."
exit 4
} fi