-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinstall.sh
executable file
·145 lines (124 loc) · 3.37 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
#!/bin/bash
# Default install all variants for user only
iconsDir=$HOME/.local/share/icons
iconsVariants=$(ls | grep "Flatery-" | grep -v "wallpapers" | cut -f 2- -d "-")
installWallpapers=false
wallpapersDir=$HOME/.local/share/backgrounds
badVariant=false
function show_valid_variants {
echo "Valid variants are : $iconsVariants"
}
function show_help {
cat << EOF
Usage : ./install.sh [-hgw] [-v variant]
Install the given variants of the icon theme, with or without wallpapers, locally or globally.
Default behavior is all variants, locally, no wallpapers.
Note that if a version of the to be installed variant exist in the install directory, it will first be removed.
-h Display this help
-w Install with wallpapers
-g Install globally (needs root privileges)
-v Install only the given variants, e.g. -v "Mint Orange"
Special values are "none" and "all".
If the option is absent, all variants are installed.
Exit status:
0 if OK,
1 if a selected variant does not exist (low severity, more of a warning),
2 if write permissions to install directory are missing (more serious),
3 if wrong arguments are given (e.g. -v without a value).
EOF
}
# Parsing options
while getopts ":hgwv:" opt; do
case ${opt} in
h )
# Display help and exit
show_help
exit 0
;;
g )
# Install globally
iconsDir=/usr/share/icons
wallpapersDir=/usr/share/backgrounds
;;
v )
# Install only user selected variant(s)
case "$OPTARG" in
all )
# Keep the full list
;;
none )
# Don't install any variant
iconsVariants=""
;;
* )
# All other cases, use specified
iconsVariants="$OPTARG"
;;
esac
;;
w )
# Install wallpaper(s)
installWallpapers=true
;;
? )
# Wrong usage
echo "Invalid option -$OPTARG"
echo
show_help
exit 3
;;
esac
done
# Check if any variant is selected
if [[ -z $iconsVariants ]]; then
echo "No icons will be installed."
else
# Automatically create directory if the iconsDir does not exists. only if installing it non-globally
# But check if we're installing it globally!
if [[ "$iconsDir" == "/usr/share/icons" ]]; then
# Check write permissions
if [[ ! -w $iconsDir ]]; then
echo "Can't write to $iconsDir"
exit 2
fi
else
# Automatically create iconsDir directory (aka. ~/.local/share/icons) if not exists
mkdir -p "$iconsDir"
fi
# Install icons variants
echo "Installing icons into $iconsDir"
for variant in $iconsVariants; do
if [[ -d "Flatery-$variant" ]]; then
echo " Installing variant $variant"
rm -rf $iconsDir/$variant
cp -r Flatery-$variant $iconsDir
else
echo " Skipping variant $variant (doesn't exist)"
badVariant=true
fi
done
fi
# Check if wallpapers are selected for install
if $installWallpapers; then
# Also check for wallpapers directory. see if user home directory wallpapersDir exists
if [[ "$wallpapersDir" == "/usr/share/backgrounds" ]]; then
# Check write permissions
if [[ ! -w $wallpapersDir ]]; then
echo "Can't write to $wallpapersDir"
exit 2
fi
else
# Automatically create wallpapersDir directory (aka. ~/.local/share/backgrounds) if not exists
mkdir -p "$wallpapersDir"
fi
# Install wallpapers
echo "Installing wallpapers into $wallpapersDir"
rm -rf $wallpapersDir/Flatery-wallpapers
cp -r Flatery-wallpapers $wallpapersDir
fi
# Exit with appropriate code
if $badVariant; then
exit 1
else
exit 0
fi