-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchkinst
executable file
·241 lines (233 loc) · 7.42 KB
/
chkinst
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
#!/bin/bash
#
## @file chkinst
## @brief Check if installed files differ from those in current directory
## @author Ronald Joe Record (rr at ronrecord dot com)
## @copyright Copyright (c) 2014, Ronald Joe Record, all rights reserved.
## @date Written 8-Mar-2014
## @version 1.0.1
##
## Note: this script assumes the files in your git repository are named the
## same as their installed counterparts except for a '.sh' suffix
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the Software or the use or other dealings in
# the Software.
#
[ "${PICROOT}" ] || PICROOT=/Volumes/Seagate_8TB/Pictures/Work
## @fn usage()
## @brief Display command line usage options
## @param none
##
## Exit the program after displaying the usage message and example invocations
usage() {
printf "\nUsage: chkinst [-u] [-a] [-d] [-f] [-i] [-n] [-w wallpaper_dir]"
printf "\nWhere:"
printf "\n\t-u displays this usage message"
printf "\n\t-a indicates report on all files, not just those installed"
printf "\n\t-d indicates display output of a diff between files"
printf "\n\t-f indicates force update of installed file(s)"
printf "\n\t-i indicates prompt for update of installed file(s)"
printf "\n\t-n indicates tell me what you would copy without doing it"
printf "\n\t-w dir specifies the installation dir for wallpaper utils\n"
exit 1
}
## @fn update()
## @brief Update installed version of file with that in current directory
## @param param1 first argument is file in current directory
## @param param2 second argument is installed version of file
update() {
printf "\nCopying $1 to $2\n"
[ "$TELL" ] || cp "$1" "$2"
}
## @fn differ()
## @brief Display diff of specified files and update if needed
## @param param1 first argument is file in current directory
## @param param2 second argument is installed version of file
differ() {
echo "$1 differs from installed version $2"
echo ""
[ "$DIFF" ] && {
diff "$1" "$2"
echo ""
}
[ "$UPD" ] && {
REFORCE=
FOUND=
for cmd in $DIFFER
do
[ "$1" = "$cmd" ] && {
FOUND=1
break
}
done
[ "$FOUND" ] && {
echo "Looks like you need to update one of your customized files."
echo "$1 is on your list of files to prompt before installing."
[ "$FORCE" ] && {
FORCE=
REFORCE=1
}
}
if [ "$FORCE" ]
then
update "$1" "$2"
else
while true
do
read -p "Do you want to install the new version ? (y/n) " yn
case $yn in
[Yy]* ) update "$1" "$2"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
[ "$REFORCE" ] && FORCE=1
fi
}
}
## @fn check()
## @brief Checks if two files differ by more than specified number of lines
## @param param1 first argument is file in current directory
## @param param2 second argument is installed version of file
check() {
dnum=`diff "$1" "$2" | wc -l`
[ $dnum -ne $3 ] && differ "$1" "$2"
}
ALL=
DIFF=
TELL=
UPD=
FORCE=
# Wallpapers utilities installation location
WDIR="${PICROOT}/Wallhaven"
# List of installed files which differ from those in my git repo due to
# tailoring for my own use. These will not get force installed without first
# prompting you if you really want to.
DIFFER="bash_aliases bash_profile bashrc mkreadme.sh mkwmv.sh \
Wallpapers/wb.sh Wallpapers/wh.sh"
while getopts adfinuw: flag; do
case $flag in
a)
ALL=1
;;
d)
DIFF=1
;;
i)
UPD=1
;;
f)
UPD=1
FORCE=1
;;
n)
TELL=1
;;
w)
WDIR="$OPTARG"
;;
u)
usage
;;
esac
done
shift $(( OPTIND - 1 ))
for i in * Utils/* Wallpapers/*.sh IFTTT/* scripts/*
do
# Skip directories
[ -d "$i" ] && continue
# Strip any .sh suffix and Utils, IFTTT, or Wallpapers/ prefix
k=`echo $i | sed -e "s/\.sh$//" -e "s/Wallpapers\///" -e "s/Utils\///"`
j=`echo $k | sed -e "s/IFTTT\///"`
# Scripts can be either commands or startup configuration files in $HOME
case "$i" in
bash_aliases|bash_profile|bashrc|dircolors|vimrc)
if [ -f "$HOME/.$i" ]
then
inst="$HOME/.$i"
else
inst=
fi
;;
IFTTT/*)
inst=`type -p "$j"`
[ "$inst" ] || inst="${HOME}/bin/$j"
;;
Utils/*)
[ -f "/usr/local/share/bash/$j" ] && inst="/usr/local/share/bash/$j"
;;
Wallpapers/*)
inst=`type -p "$j"`
[ "$inst" ] || {
[ -f "${WDIR}/$j" ] && inst="${WDIR}/$j"
}
;;
INSTALL)
continue
;;
*)
inst=`type -p "$j"`
;;
esac
[ "$inst" ] || {
[ "$ALL" ] && {
echo "$i does not appear to be installed. Skipping."
echo ""
}
continue
}
# Special cases as the installed version may have configuration changes.
# The 3rd argument to the check() function is the number of lines the
# installed script can differ before we report it differs. This number
# will differ from system to system so change it for your purposes. To
# determine what the number should be, run the command:
# diff $i $inst | wc -l
# where $i is the source file and $inst is the installed version.
# This functionality is mostly for me, the maintainer and distributor.
#
case "$i" in
# I have heavily modified Bash startup files for work.
bash_aliases)
check "$i" "$inst" 121
;;
bash_profile)
check "$i" "$inst" 8
;;
bashrc)
check "$i" "$inst" 58
;;
gethue.sh)
check "$i" "$inst" 6
;;
IFTTT/ifttt.sh)
check "$i" "$inst" 4
;;
Wallpapers/wh.sh)
check "$i" "$inst" 8
;;
Wallpapers/wb.sh)
check "$i" "$inst" 8
;;
mkreadme.sh|mkwmv.sh)
check "$i" "$inst" 12
;;
*)
cmp -s "$i" "$inst" || differ "$i" "$inst"
;;
esac
done