-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweak
executable file
·102 lines (93 loc) · 2.48 KB
/
tweak
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
#!/bin/sh
# tweak - Automated tweaks management
#
# A part of confman (https://github.com/ianayl/confman)
TWEAKDIR="$HOME/etc/tweaks"
usage () {
>&2 echo "Usage: tweak [options] [tweak]
\t-i\tinstalls selected tweak
\t-r\tremoves selected tweak
\t-q\tlists all tweaks
\t-p\tlists installed tweaks
\t-a\tassisted prompt to help install tweaks one by one
\t-h\tbrings up this help message"
exit
}
install () {
if [ "$(grep $1 $TWEAKDIR/.installed)" ]
then
echo "Selected tweak $1 already installed! Are you sure you want to install again?"
printf "(NOTE: tweak does not automatically uninstall for you) [y/n] "
read confirmation_selection
case $confirmation_selection in
y|Y) ;;
*) exit 1 ;;
esac
fi
if [ ! -e "$TWEAKDIR/$1/install.sh" ]
then
echo "Tweak: Selected tweak $1 does not exist."
exit 1
fi
TWEAKDIR=$TWEAKDIR $TWEAKDIR/$1/install.sh $1
echo $1 >> $TWEAKDIR/.installed
}
remove () {
if [ ! -e "$TWEAKDIR/$1/remove.sh" ]
then
if [ ! -e "$TWEAKDIR/$1/install.sh" ]
then
echo "Tweak: Selected tweak $1 does not exist."
else
echo "Tweak: Selected tweak $1 does not have an uninstall method."
fi
exit 1
fi
# make sure .installed is there so grep doesn't error
touch .installed
if [ -z "$(grep $1 $TWEAKDIR/.installed)" ]
then
echo "Selected tweak $1 not installed! Are you sure you want to proceed anyway?"
printf "(NOTE: COULD BE DANGEROUS!) [y/n] "
read confirmation_selection
case $confirmation_selection in
y|Y) ;;
*) exit 1 ;;
esac
fi
TWEAKDIR=$TWEAKDIR $TWEAKDIR/$1/remove.sh $1
sed -i "/^$1\$/d" $TWEAKDIR/.installed
}
query () {
current_dir=$PWD
cd $TWEAKDIR
ls
cd $current_dir
}
installed () {
cat $TWEAKDIR/.installed
}
automatic () {
for tweak in $TWEAKDIR/*/; do
[ -d "$tweak" ] || continue
tweak=$(basename $tweak)
[ "$(grep $tweak $TWEAKDIR/.installed)" ] && continue
printf "Install tweak $tweak? [y/n] "
read confirmation_selection
case $confirmation_selection in
y|Y) ;;
*) echo "Skipped tweak $tweak" && continue ;;
esac
install "$tweak"
done
}
[ "$1" ] || usage
case $1 in
-i) install $2 ;;
-r) remove $2 ;;
-q) query ;;
-p) installed ;;
-a) automatic ;;
*) usage ;;
esac
sac