-
Notifications
You must be signed in to change notification settings - Fork 11
/
clean-locales
87 lines (71 loc) · 2.24 KB
/
clean-locales
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
#!/bin/bash
#----------------------------------------------------------------------------------
# Project Name - $HOME/ShellPlugins/Clean_Unused_Locales
# Started On - Wed 1 Nov 11:29:18 GMT 2017
# Last Change - Sun 18 Mar 14:29:35 GMT 2018
# Author E-Mail - [email protected]
# Author GitHub - https://github.com/terminalforlife
#----------------------------------------------------------------------------------
_VERSION_="2018-03-18"
XERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; exit 1; }
ERR(){ printf "[L%0.4d] ERROR: %s\n" "$1" "$2" 1>&2; }
USAGE(){
while read -r; do
printf "%s\n" "$REPLY"
done <<-EOF
CLEAN-LOCALES ($_VERSION_)
Written by terminalforlife ([email protected])
Remove some unnecessary non-English localizations.
SYNTAX: clean-locales [OPTS]
OPTS: --help|-h|-? - Displays this help information.
--version|-v - Output only the version datestamp.
--quiet|-q - Runs in quiet mode. Errors still output.
--debug|-D - Enables the built-in bash debugging.
FILES: Files in /usr/share/locale will be deleted, except:
en_GB
en_US
locale.alias
EOF
}
while [ "$1" ]; do
case "$1" in
--help|-h|-\?)
USAGE; exit 0 ;;
--version|-v)
printf "%s\n" "$_VERSION_"
exit 0 ;;
--quiet|-q)
BEQUIET="true" ;;
--debug|-D)
DEBUGME="true" ;;
*)
XERR "$LINENO" "Incorrect argument(s) specified." ;;
esac
shift
done
[ "$BEQUIET" == "true" ] && exec 1> /dev/null
[ "$DEBUGME" == "true" ] && set -x
if [ -x /bin/rm ]; then
if ! [ -d /usr/share/locale ]; then
XERR "$LINENO" "Directory missing: /usr/share/locale"
fi
for DIR in /usr/share/locale/*; {
if ! [[ "$DIR" =~ (en_GB|en_US|locale\.alias) ]]; then
printf "DELETING: $DIR "
if [ -e /dev/null ]; then
if /bin/rm -rf "$DIR" &> /dev/null; then
printf "[OK]\n"
else
printf "[ERROR]\n"
fi
else
XERR "$LINENO" "Unable to find: /dev/null"
fi
else
printf "SKIPPING: %s\n" "$DIR"
fi
}
else
XERR "$LINENO" "Dependency '/bin/rm' not met."
fi
# vim: noexpandtab colorcolumn=84 tabstop=8 noswapfile nobackup