3 # Update all out-of-date config in all current projects and add missing bits
5 # If one or more project names are given, just update those instead
7 # update-all-config [--dry-run] [projname]...
15 [ "$1" != "--force" -a "$1" != "-f" ] ||
{ force
=1; shift; }
16 [ "$1" != "--dry-run" -a "$1" != "-n" ] ||
{ dryrun
=1; shift; }
17 case "$1" in -*) echo "Invalid options: $1" >&2; exit 1;; esac
20 printf '%s\n' "$(basename "$0"): refusing to run as root -- bad things would happen"
27 drwxmode
='ug+rwx,o+rx'
31 if [ -z "$cfg_owning_group" ]; then
32 if [ -z "$force" ]; then
33 echo "No owning_group set, refusing to run without --force" >&2
45 ls -ldH "$1" | cut
-d ' ' -f 1
49 ls -ldH "$1" |
awk '{print $4}'
54 [ -n "$hdr" ] ||
{ hdr
=1; [ -z "$wrote" ] ||
echo ""; echo "$proj:"; }
61 oldperm
="$(get_perm "$1")"
62 [ -n "$dryrun" ] ||
chmod $dmode "$1" 2>/dev
/null || result
=$?
63 pmsg
"$1/:" "$oldperm" '->' "$dperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
68 oldperm
="$(get_perm "$1")"
69 if [ -n "$wall" ]; then
72 scratch
="${oldperm#????????}"
73 newperm
="drwxrwxr${scratch%?}x"
75 [ -n "$dryrun" ] ||
[ "$oldperm" = "$newperm" ] ||
chmod $drwxmode "$1" 2>/dev
/null || result
=$?
76 pmsg
"$1/:" "$oldperm" '->' "$newperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
81 oldperm
="$(get_perm "$1")"
82 scratch
="${oldperm#??}"
83 newperm
="dr${scratch%???????}xr"
84 scratch
="${scratch#???}"
85 newperm
="$newperm${scratch%????}xr"
86 scratch
="${scratch#???}"
87 newperm
="$newperm${scratch%?}x"
88 [ -n "$dryrun" ] ||
[ "$oldperm" = "$newperm" ] ||
chmod a
+rx
"$1" 2>/dev
/null || result
=$?
89 pmsg
"$1/:" "$oldperm" '->' "$newperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
94 oldgrp
="$(get_grp "$1")"
95 [ -n "$dryrun" ] || chgrp
"$cfg_owning_group" "$1" 2>/dev
/null || result
=$?
97 ! [ -d "$1" ] || isdir
='/'
98 pmsg
"$1$isdir:" group
"$oldgrp" '->' "$cfg_owning_group" ${result:+FAILED!} ${dryrun:+(dryrun)}
103 oldperm
="$(get_perm "$1")"
105 [ "$oldperm" = "$fperm" ] ||
{ msg
=1; [ -n "$dryrun" ]; } ||
chmod $fmode "$1" 2>/dev
/null || result
=$?
106 [ -z "$msg" ] || pmsg
"$1:" "$oldperm" '->' "$fperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
111 oldperm
="$(get_perm "$1")"
112 scratch
="${oldperm#??}"
113 newperm
="-r${scratch%??????}"
114 scratch
="${scratch#???}"
115 newperm
="${newperm}r${scratch%???}"
116 scratch
="${scratch#???}"
117 newperm
="${newperm}r$scratch"
118 [ -n "$dryrun" ] ||
[ "$oldperm" = "$newperm" ] ||
chmod a
+r
"$1" 2>/dev
/null || result
=$?
119 pmsg
"$1:" "$oldperm" '->' "$newperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
124 oldperm
="$(get_perm "$1")"
125 newperm
="${oldperm%???????}-"
126 scratch
="${oldperm#????}"
127 newperm
="${newperm}${scratch%????}-"
128 scratch
="${scratch#???}"
129 newperm
="${newperm}${scratch%?}-"
130 [ -n "$dryrun" ] ||
[ "$oldperm" = "$newperm" ] ||
chmod a-x
"$1" 2>/dev
/null || result
=$?
131 pmsg
"$1:" "$oldperm" '->' "$newperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
136 oldperm
="$(get_perm "$1")"
137 newperm
="${oldperm%???????}x"
138 scratch
="${oldperm#????}"
139 newperm
="${newperm}${scratch%????}x"
140 scratch
="${scratch#???}"
141 newperm
="${newperm}${scratch%?}x"
142 [ -n "$dryrun" ] ||
[ "$oldperm" = "$newperm" ] ||
chmod a
+x
"$1" 2>/dev
/null || result
=$?
143 pmsg
"$1:" "$oldperm" '->' "$newperm" ${result:+FAILED!} ${dryrun:+(dryrun)}
148 [ -n "$dryrun" ] || mkdir
"$1" 2>/dev
/null ||
[ -d "$1" ] || result
=1
149 pmsg
"$1/:" created
${result:+FAILED!} ${dryrun:+(dryrun)}
155 if [ -n "$dryrun" ] && ! [ -e config
]; then
158 configlist
="$(git config --list --file config)"
159 [ -z "$configlist" ] || configlist
="$configlist$nl"
164 while read -r _item
; do
165 case "$_item" in "$1"=*)
166 printf '%s' "${_item#*=}"
176 case "$1" in 1|
[Tt
][Rr
][Uu
][Ee
]|
[Yy
][Ee
][Ss
]|
[Oo
][Nn
]) return 0; esac
181 case "$1" in 0|
[Ff
][Aa
][Ll
][Ss
][Ee
]|
[Nn
][Oo
]|
[Oo
][Ff
][Ff
]) return 0; esac
186 isbooltrue
"$1" || isboolfalse
"$1" ||
return 1
192 [ "$1" != "--unset" ] ||
{ unset=1; shift; _x
="$1"; shift; msg
="$*"; set -- "$_x"; }
196 oldval
="$(configitem "$item")" || existsnot
=1
199 [ -n "$existsnot" -o -z "$unset" ] ||
[ $
(printf '%s' "$configlist" |
grep "^${item%%.*}\.[^.][^.]*=" | wc -l) -ne 1 ] || { ccmd="remove-section"; arg="${item%%.*}"; }
200 [ -n "$dryrun" ] || [ -n "$unset" -a -n "$existsnot" ] || git config --file config ${unset:+--$ccmd} "$arg" "$@
" 2>/dev/null || result=1
201 if [ -n "$existsnot" ]; then
202 [ -n "$unset" ] || pmsg "config
$item:" created "\"$
*\"" ${result:+FAILED!} ${dryrun:+(dryrun)}
204 if [ -n "$unset" ]; then
205 pmsg "config
$item:" removed $msg "\"$oldval\"" ${result:+FAILED!} ${dryrun:+(dryrun)}
207 pmsg "config
$item:" "\"$oldval\"" '->' "\"$
*\"" ${result:+FAILED!} ${dryrun:+(dryrun)}
212 mkdirs='refs info hooks ctags htmlcache bundles reflogs objects objects/info'
213 mkfiles='config info/lastactivity'
214 fixdpermsdirs='. refs info ctags htmlcache bundles reflogs objects objects/info'
215 fixdpermsrwx='refs objects'
216 fixfpermsfiles='HEAD config description packed-refs README.html info/lastactivity'
217 fixfpermsfiles="$fixfpermsfiles info
/alternates info
/http-alternates info
/packs
"
218 fixfpermsdirs='ctags'
220 boolvars='gitweb.statusupdates'
221 falsevars='core.ignorecase receive.denynonfastforwards'
222 false0vars='gc.auto receive.autogc'
223 truevars='receive.updateserverinfo repack.writebitmaps transfer.fsckobjects'
225 base="${cfg_reporoot%/}"
226 cmd='cut -d : -f 1 < "$cfg_chroot/etc
/group
" | grep -v ^_repo'
227 [ $# -eq 0 ] || cmd='printf "%s
\n" "$@
"'
230 while read -r proj; do
231 proj="${proj#$base/}"
233 projdir="$base/$proj.git
"
234 [ -d "$projdir" ] || { echo "$proj: does not exist
-- skipping
"; continue; }
235 is_git_dir "$projdir" || { echo "$proj: is not a .git directory
-- skipping
"; continue; }
236 ! [ -e "$projdir/.noconfig
" ] || { echo "$proj: found .noconfig
-- skipping
"; continue; }
240 for mdir in $mkdirs; do
241 if ! [ -d "$mdir" ]; then
242 if [ -e "$mdir" ]; then
243 echo "$proj: bypassing project
, exists but not directory
: $mdir" >&2
250 [ -z "$bad" ] || continue
251 while read -r fixdir; do
252 [ -z "$fixdir" ] || change_dperm "$fixdir"
254 $(find $fixdpermsdirs -xdev -maxdepth 0 -type d \! -perm $dmode -print 2>/dev/null)
256 while read -r fixdir; do
257 [ -z "$fixdir" ] || change_dpermrwx "$fixdir"
259 $(find $fixdpermsrwx -xdev -type d \! -perm -$drwxmode -print 2>/dev/null)
261 while read -r fixdir; do
262 [ -z "$fixdir" ] || change_dpermrx "$fixdir"
264 $(find . -xdev -type d \! -perm -a+rx -print)
266 for mkfile in $mkfiles; do
267 if [ -e "$mkfile" ]; then
268 if ! [ -f "$mkfile" ]; then
269 echo "$proj: bypassing project
, exists but not
file: $mkfile" >&2
275 [ -n "$dryrun" ] || { >"$mkfile"; } 2>/dev/null || result=1
276 pmsg "$mkfile:" created ${result:+FAILED!} ${dryrun:+(dryrun)}
279 [ -z "$bad" ] || continue
280 [ -n "$dryrun" ] || change_fperm config
282 cmplvl="$
(configitem core.compression ||
:)"
286 "-1"|"0"|"1"|"2"|"3"|"4"|"6"|"7"|"8"|"9")
287 pmsg "WARNING
: suboptimal core.compression value left unchanged
: \"$cmplvl\""
290 pmsg "WARNING
: replacing invalid core.compression value
"
294 [ -n "$cmplvl" ] || do_config core.compression 5
295 grpshr="$
(configitem core.sharedrepository ||
:)"
296 if [ -z "$grpshr" ] || isboolfalse "$grpshr"; then
297 do_config core.sharedrepository 1
298 elif ! isbooltrue "$grpshr"; then
299 pmsg "WARNING
: odd core.sharedrepository value left unchanged
: \"$grpshr\""
301 if isbooltrue "$
(configitem core.bare ||
:)"; then
303 if laru="$
(configitem core.logallrefupdates
)"; then
304 if isbool "$laru"; then
306 isboolfalse "$laru" || \
307 pmsg "WARNING
: core.logallrefupdates is true
(left unchanged
)"
309 pmsg "WARNING
: replacing non-boolean core.logallrefupdates value
"
312 [ -z "$setlaru" ] || do_config core.logallrefupdates false
314 pmsg "WARNING
: core.bare is not true
(left unchanged
)"
316 case "$
(configitem receive.denydeletecurrent ||
:)" in [Ww][Aa][Rr][Nn]) :;; *)
317 do_config receive.denydeletecurrent warn
319 for bvar in $boolvars; do
320 ! old="$
(configitem
"$bvar")" || isbool "$old" || do_config --unset "$bvar" "(not a boolean
)"
322 for fvar in $falsevars; do
323 old="$
(configitem
"$fvar" ||
:)"
324 isboolfalse "$old" || do_config "$fvar" false
326 for fvar in $false0vars; do
327 old="$
(configitem
"$fvar" ||
:)"
328 isboolfalse "$old" || do_config "$fvar" 0
330 for tvar in $truevars; do
331 old="$
(configitem
"$tvar" ||
:)"
332 isbooltrue "$old" || do_config "$tvar" true
334 if [ -n "$cfg_owning_group" ]; then
335 while read -r fixgrp; do
336 [ -z "$fixgrp" ] || change_group "$fixgrp"
338 $(find . -xdev \( -type d -o -type f \) \! -group $cfg_owning_group -print)
341 for fixfile in $fixfpermsfiles; do
342 if [ -e "$fixfile" ]; then
343 if ! [ -f "$fixfile" ]; then
344 echo "$proj: bypassing project
, exists but not
file: $fixfile" >&2
348 change_fperm "$fixfile"
351 [ -z "$bad" ] || continue
352 for fixfile in $(find $fixfpermsdirs -xdev -type f \! -perm $fmode -print 2>/dev/null); do
353 change_fperm "$fixfile"
355 while read -r fixfileread; do
356 [ -z "$fixfileread" ] || change_fpermr "$fixfileread"
358 $(find . -xdev -type f \! -perm -a+r -print)
360 while read -r fixfilenox; do
361 [ -z "$fixfilenox" ] || change_fpermnox "$fixfilenox"
363 $(find . -xdev -type d \( -path ./hooks -o -path ./mob/hooks \) -prune -o -type f -perm +a+x -print)
365 while read -r fixfilex; do
366 #case "$fixfilex" in ""|*.sample) :;; *) change_fpermx "$fixfilex"; esac
369 $(! [ -d hooks ] || find hooks -xdev -type f \! -perm -a+x -print
370 ! [ -d mob/hooks ] || find mob/hooks -xdev -type f \! -perm -a+x -print)
372 bu="$
(configitem gitweb.baseurl ||
:)"
373 [ -n "$bu" -o -e .nofetch ] || pmsg "WARNING
: gitweb.baseurl is empty and .nofetch does not exist
"
374 [ -z "$bu" -o ! -e .nofetch ] || pmsg "WARNING
: .nofetch exists but gitweb.baseurl is not empty
"