blob: 1ec9695cd3029ed5daed22446985c08932bd0a74 (
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
|
#!/bin/bash
# author: grimi
# name: mime-archpkg
# require: sed, cat, basename, convert, rsvg-convert, gtk-update-icon-cache
declare MODE=usage
declare MYDIR=/usr/share/mime-archpkg
declare MYTHEME
declare -r NAME=application-x-archpkg
update() {
local file theme elem suf
local -i size
local -a taba tab
for file in "$MYDIR"/*.svgz; do
theme="/usr/share/icons/$(basename "$file"|sed 's/\.svgz//')"
if [[ ${MYTHEME} ]]; then
if [[ $(basename "$theme") != $MYTHEME ]]; then
continue
fi
fi
if [[ -f $theme/index.theme ]]; then
echo ">> Updating mimetype icons in $theme... <<"
taba=($(cat "$theme/index.theme"|grep "\[.*mimetypes"|sed 's/\[//; s/\]//'))
for elem in "${taba[@]}"; do
tab=($(echo $elem|sed 's/\//\n/'))
if [[ ${tab[0]/[0-9]/} != ${tab[0]} ]]; then
size=${tab[0]/x[0-9][0-9]*/}
if [[ ${tab[0]/@2x/} != ${tab[0]} ]]; then
size=$size*2
fi
elif [[ ${tab[1]/[0-9]/} != ${tab[1]} ]]; then
size=${tab[1]/x[0-9][0-9]*/}
if [[ ${tab[1]/@2x/} != ${tab[1]} ]]; then
size=$size*2
fi
elif [[ ${elem/scalable/} != ${elem} ]]; then
size=0
fi
if [[ $size ]]; then
if [[ $size -ne 0 ]]; then
if [[ -f $theme/$elem/package.svg ]]; then
suf=svg
else
suf=png
fi
convert -resize ${size}x${size} -background none "$file" /tmp/archpkg.$suf
install -m644 /tmp/archpkg.$suf "$theme/$elem/$NAME.$suf"
else
rsvg-convert -o /tmp/archpkg.svg -f svg "$file"
install -m644 /tmp/archpkg.svg "$theme/$elem/$NAME.svg"
fi
fi
done
if [[ -f $theme/icon-theme.cache ]]; then
gtk-update-icon-cache -q -f "$theme"
fi
fi
done
}
remove() {
local file theme
for file in "$MYDIR"/*.svgz; do
theme="/usr/share/icons/$(basename "$file"|sed 's/\.svgz//')"
if [[ -d $theme ]]; then
echo ">> Removing installed mimetype icons from $theme... <<"
find "$theme/" -type f -name $NAME.png -exec rm "{}" \;
find "$theme/" -type f -name $NAME.svg -exec rm "{}" \;
if [[ -f $theme/icon-theme.cache ]]; then
gtk-update-icon-cache -q -f "$theme"
fi
fi
done
}
usage() {
echo "USAGE: [-u] [-r] [-s <theme>]"
echo " -u: update archpkg mime icons"
echo " -r: remove archpkg mime icons"
echo " -s: update selected archpkg mime icons theme"
}
case "$1" in
-u) MODE=update ;;
-r) MODE=remove ;;
-s) if [[ $2 ]]; then MODE=update; MYTHEME="$2"; fi ;;
esac
if [[ $MODE != "usage" && $USER != "root" ]]; then
echo "root privileges needed!"
exit 1
fi
eval $MODE
|