diff --git a/usr.sbin/etcupdate/etcupdate.sh b/usr.sbin/etcupdate/etcupdate.sh --- a/usr.sbin/etcupdate/etcupdate.sh +++ b/usr.sbin/etcupdate/etcupdate.sh @@ -94,8 +94,8 @@ # file with " " prepended. warn() { - echo -n " " >> $WARNINGS - echo "$@" >> $WARNINGS + echo -n " " >> "$WARNINGS" + echo "$@" >> "$WARNINGS" } # Output a horizontal rule using the passed-in character. Matches the @@ -112,7 +112,7 @@ # $1 - file pathname. file_type() { - stat -f "%HT" $1 | tr "[:upper:]" "[:lower:]" + stat -f "%HT" "$1" | tr "[:upper:]" "[:lower:]" } # Returns true (0) if a file exists @@ -120,7 +120,7 @@ # $1 - file pathname. exists() { - [ -e $1 -o -L $1 ] + [ -e "$1" -o -L "$1" ] } # Returns true (0) if a file should be ignored, false otherwise. @@ -134,7 +134,7 @@ for pattern in $IGNORE_FILES; do set +o noglob case $1 in - $pattern) + "$pattern") return 0 ;; esac @@ -146,7 +146,7 @@ # files once in that case. case $1 in /.cshrc|/.profile) - if [ ${DESTDIR}$1 -ef ${DESTDIR}/root$1 ]; then + if [ "${DESTDIR}$1" -ef "${DESTDIR}/root$1" ]; then return 0 fi ;; @@ -169,7 +169,7 @@ for pattern in $ALWAYS_INSTALL; do set +o noglob case $1 in - $pattern) + "$pattern") return 0 ;; esac @@ -190,8 +190,8 @@ if [ -n "$noroot" ]; then make="$make -DNO_ROOT" - metatmp=`mktemp $WORKDIR/etcupdate-XXXXXXX` - : > $metatmp + metatmp=$(mktemp "$WORKDIR/etcupdate-XXXXXXX") + : > "$metatmp" trap "rm -f $metatmp; trap '' EXIT; return 1" INT trap "rm -f $metatmp" EXIT else @@ -203,42 +203,42 @@ exec >&3 2>&1 - mkdir -p $1/usr/obj - destdir=`realpath $1` + mkdir -p "${1}/usr/obj" + destdir=$(realpath "$1") if [ -n "$preworld" ]; then # Build a limited tree that only contains files that are # crucial to installworld. for file in $PREWORLD_FILES; do - name=$(basename $file) - mkdir -p $1/etc || return 1 - cp -p $SRCDIR/$file $1/etc/$name || return 1 + name=$(basename "$file") + mkdir -p "$1"/etc || return 1 + cp -p "$SRCDIR/$file" "$1/etc/$name" || return 1 done - elif ! [ -n "$nobuild" ]; then - (cd $SRCDIR; $make DESTDIR=$destdir distrib-dirs && + elif [ -z "$nobuild" ]; then + (cd "$SRCDIR"; $make DESTDIR="$destdir" distrib-dirs && MAKEOBJDIRPREFIX=$destdir/usr/obj $make _obj SUBDIR_OVERRIDE=etc && MAKEOBJDIRPREFIX=$destdir/usr/obj $make everything SUBDIR_OVERRIDE=etc && - MAKEOBJDIRPREFIX=$destdir/usr/obj $make DESTDIR=$destdir distribution) || \ + MAKEOBJDIRPREFIX=$destdir/usr/obj $make DESTDIR="$destdir" distribution) || \ return 1 else - (cd $SRCDIR; $make DESTDIR=$destdir distrib-dirs && - $make DESTDIR=$destdir distribution) || return 1 + (cd "$SRCDIR"; $make DESTDIR="$destdir" distrib-dirs && + $make DESTDIR="$destdir" distribution) || return 1 fi - chflags -R noschg $1 || return 1 - rm -rf $1/usr/obj || return 1 + chflags -R noschg "$1" || return 1 + rm -rf "$1/usr/obj" || return 1 # Purge auto-generated files. Only the source files need to # be updated after which these files are regenerated. autogenfiles="./etc/*.db ./etc/passwd ./var/db/services.db" - (cd $1 && printf '%s\n' $autogenfiles >> $metatmp && \ - rm -f $autogenfiles) || return 1 + (cd "$1" && printf '%s\n' "$autogenfiles" >> "$metatmp" && \ + rm -f "$autogenfiles") || return 1 # Remove empty files. These just clutter the output of 'diff'. - (cd $1 && find . -type f -size 0 -delete -print >> $metatmp) || \ + (cd "$1" && find . -type f -size 0 -delete -print >> "$metatmp") || \ return 1 # Trim empty directories. - (cd $1 && find . -depth -type d -empty -delete -print >> $metatmp) || \ + (cd "$1" && find . -depth -type d -empty -delete -print >> "$metatmp") || \ return 1 if [ -n "$noroot" ]; then @@ -252,13 +252,13 @@ # and its children explicitly for simplicity rather than # building up that list (and in practice only ./usr/obj itself # will be in the METALOG since nothing is installed there). - echo '#METALOG#' >> $metatmp || return 1 - cat $1/METALOG >> $metatmp || return 1 + echo '#METALOG#' >> "$metatmp" || return 1 + cat "$1/METALOG" >> "$metatmp" || return 1 awk '/^#METALOG#$/ { metalog = 1; next } { f=$1; gsub(/\/\/+/, "/", f) } !metalog { rm[f] = 1; next } !rm[f] && f !~ /^\.\/usr\/obj(\/|$)/ { print }' \ - $metatmp > $1/METALOG || return 1 + "$metatmp" > "$1/METALOG" || return 1 fi return 0 @@ -279,16 +279,16 @@ if [ -n "$preworld" ]; then files="$PREWORLD_FILES" fi - if ! (mkdir -p $1 && tar xf $tarball -C $1 $files) \ + if ! (mkdir -p "$1" && tar xf "$tarball" -C "$1" "$files") \ >&3 2>&1; then echo "Failed to extract new tree." - remove_tree $1 + remove_tree "$1" exit 1 fi else - if ! build_tree $1; then + if ! build_tree "$1"; then echo "Failed to build new tree." - remove_tree $1 + remove_tree "$1" exit 1 fi fi @@ -300,12 +300,12 @@ remove_tree() { - rm -rf $1 >&3 2>&1 - if [ -e $1 ]; then - chflags -R noschg $1 >&3 2>&1 - rm -rf $1 >&3 2>&1 + rm -rf "$1" >&3 2>&1 + if [ -e "$1" ]; then + chflags -R noschg "$1" >&3 2>&1 + rm -rf "$1" >&3 2>&1 fi - [ ! -e $1 ] + [ ! -e "$1" ] } # Return values for compare() @@ -334,27 +334,27 @@ # If the first node doesn't exist, then check for the second # node. Note that -e will fail for a symbolic link that # points to a missing target. - if ! exists $1; then - if exists $2; then + if ! exists "$1"; then + if exists "$2"; then return $COMPARE_ONLYSECOND else return $COMPARE_EQUAL fi - elif ! exists $2; then + elif ! exists "$2"; then return $COMPARE_ONLYFIRST fi # If the two nodes are different file types fail. - first=`stat -f "%Hp" $1` - second=`stat -f "%Hp" $2` + first=$(stat -f "%Hp" "$1") + second=$(stat -f "%Hp" "$2") if [ "$first" != "$second" ]; then return $COMPARE_DIFFTYPE fi # If both are symlinks, compare the link values. - if [ -L $1 ]; then - first=`readlink $1` - second=`readlink $2` + if [ -L "$1" ]; then + first=$(readlink "$1") + second=$(readlink "$2") if [ "$first" = "$second" ]; then return $COMPARE_EQUAL else @@ -363,8 +363,8 @@ fi # If both are files, compare the file contents. - if [ -f $1 ]; then - if cmp -s $1 $2; then + if [ -f "$1" ]; then + if cmp -s "$1" "$2"; then return $COMPARE_EQUAL else return $COMPARE_DIFFFILES @@ -384,7 +384,7 @@ fbsdid_only() { - diff -qI '\$FreeBSD.*\$' $1 $2 >/dev/null 2>&1 + diff -qI '\$FreeBSD.*\$' "$1" "$2" >/dev/null 2>&1 } # This is a wrapper around compare that will return COMPARE_EQUAL if @@ -398,11 +398,11 @@ { local cmp - compare $1 $2 + compare "$1" "$2" cmp=$? if [ -n "$FREEBSD_ID" -a "$cmp" -eq $COMPARE_DIFFFILES ] && \ - fbsdid_only $1 $2; then + fbsdid_only "$1" "$2"; then return $COMPARE_EQUAL fi @@ -416,7 +416,7 @@ { local contents - contents=`ls -A $1` + contents=$(ls -A "$1") [ -z "$contents" ] } @@ -431,20 +431,20 @@ { local contents file - if ! [ -d $1 -a -d $2 ]; then + if ! [ -d "$1" -a -d "$2" ]; then return 1 fi # Ignore files that are present in the second directory but not # in the first. - contents=`ls -A $1` + contents=$(ls -A "$1") for file in $contents; do - if ! compare $1/$file $2/$file; then + if ! compare "$1/$file" "$2/$file"; then return 1 fi - if [ -d $1/$file ]; then - if ! dir_subset $1/$file $2/$file; then + if [ -d "$1/$file" ]; then + if ! dir_subset "$1/$file" "$2/$file"; then return 1 fi fi @@ -463,11 +463,11 @@ { if [ -n "$dryrun" ]; then - dir_subset $DESTDIR/$1 $OLDTREE/$1 + dir_subset "$DESTDIR/$1" "$OLDTREE/$1" return fi - empty_dir $DESTDIR/$1 + empty_dir "$DESTDIR/$1" } # Output a diff of two directory entries with the same relative name @@ -490,30 +490,30 @@ diffargs="" fi - compare_fbsdid $1/$3 $2/$3 + compare_fbsdid "$1/$3" "$2/$3" case $? in - $COMPARE_EQUAL) + "$COMPARE_EQUAL") ;; - $COMPARE_ONLYFIRST) + "$COMPARE_ONLYFIRST") echo echo "Removed: $3" echo ;; - $COMPARE_ONLYSECOND) + "$COMPARE_ONLYSECOND") echo echo "Added: $3" echo ;; - $COMPARE_DIFFTYPE) - first=`file_type $1/$3` - second=`file_type $2/$3` + "$COMPARE_DIFFTYPE") + first=$(file_type "$1/$3") + second=$(file_type "$2/$3") echo echo "Node changed from a $first to a $second: $3" echo ;; - $COMPARE_DIFFLINKS) - first=`readlink $1/$file` - second=`readlink $2/$file` + "$COMPARE_DIFFLINKS") + first=$(readlink "$1/$file") + second=$(readlink "$2/$file") echo echo "Link changed: $file" rule "=" @@ -521,10 +521,10 @@ echo "+$second" echo ;; - $COMPARE_DIFFFILES) + "$COMPARE_DIFFFILES") echo "Index: $3" rule "=" - diff -u $diffargs -L "$3 ($4)" $1/$3 -L "$3 ($5)" $2/$3 + diff -u "$diffargs" -L "$3 ($4)" "$1/$3" -L "$3 ($5)" "$2/$3" ;; esac } @@ -543,9 +543,9 @@ # If /etc/localtime exists and is not a symlink and /var/db/zoneinfo # exists, run tzsetup -r to refresh /etc/localtime. - if [ -f ${DESTDIR}/etc/localtime -a \ - ! -L ${DESTDIR}/etc/localtime ]; then - if [ -f ${DESTDIR}/var/db/zoneinfo ]; then + if [ -f "${DESTDIR}/etc/localtime" -a \ + ! -L "${DESTDIR}/etc/localtime" ]; then + if [ -f "${DESTDIR}/var/db/zoneinfo" ]; then if [ -n "${DESTDIR}" ]; then args="-C ${DESTDIR}" else @@ -553,7 +553,7 @@ fi log "tzsetup -r ${args}" if [ -z "$dryrun" ]; then - tzsetup -r ${args} >&3 2>&1 + tzsetup -r "${args}" >&3 2>&1 fi else warn "Needs update: /etc/localtime (required" \ @@ -573,46 +573,46 @@ { local args dir - dir=`dirname $3` + dir=$(dirname "$3") # Nothing to do if the parent directory exists. This also # catches the degenerate cases when the path is just a simple # filename. - if [ -d ${2}$dir ]; then + if [ -d "${2}$dir" ]; then return 0 fi # If non-directory file exists with the desired directory # name, then fail. - if exists ${2}$dir; then + if exists "${2}$dir"; then # If this is a dryrun and we are installing the # directory in the DESTDIR and the file in the DESTDIR # matches the file in the old tree, then fake success # to quiet spurious warnings. if [ -n "$dryrun" -a "$2" = "$DESTDIR" ]; then - if compare $OLDTREE/$dir $DESTDIR/$dir; then + if compare "$OLDTREE/$dir" "$DESTDIR/$dir"; then return 0 fi fi - args=`file_type ${2}$dir` + args=$(file_type "${2}$dir") warn "Directory mismatch: ${2}$dir ($args)" return 1 fi # Ensure the parent directory of the directory is present # first. - if ! install_dirs $1 "$2" $dir; then + if ! install_dirs "$1" "$2" "$dir"; then return 1 fi # Format attributes from template directory as install(1) # arguments. - args=`stat -f "-o %Su -g %Sg -m %0Mp%0Lp" $1/$dir` + args=$(stat -f "-o %Su -g %Sg -m %0Mp%0Lp" "$1/$dir") log "install -d $args ${2}$dir" if [ -z "$dryrun" ]; then - install -d $args ${2}$dir >&3 2>&1 + install -d "$args" "${2}$dir" >&3 2>&1 fi return 0 } @@ -638,19 +638,19 @@ /usr/share/certs/trusted/* | /usr/share/certs/untrusted/*) log "certctl rehash" if [ -z "$dryrun" ]; then - env DESTDIR=${DESTDIR} certctl rehash >&3 2>&1 + env DESTDIR="${DESTDIR}" certctl rehash >&3 2>&1 fi ;; /etc/login.conf) log "cap_mkdb ${DESTDIR}$1" if [ -z "$dryrun" ]; then - cap_mkdb ${DESTDIR}$1 >&3 2>&1 + cap_mkdb "${DESTDIR}$1" >&3 2>&1 fi ;; /etc/master.passwd) log "pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1" if [ -z "$dryrun" ]; then - pwd_mkdb -p -d $DESTDIR/etc ${DESTDIR}$1 \ + pwd_mkdb -p -d "$DESTDIR/etc" "${DESTDIR}$1" \ >&3 2>&1 fi ;; @@ -669,8 +669,8 @@ log "services_mkdb -q -o $DESTDIR/var/db/services.db" \ "${DESTDIR}$1" if [ -z "$dryrun" ]; then - services_mkdb -q -o $DESTDIR/var/db/services.db \ - ${DESTDIR}$1 >&3 2>&1 + services_mkdb -q -o "$DESTDIR"/var/db/services.db \ + "${DESTDIR}$1" >&3 2>&1 fi ;; esac @@ -683,14 +683,14 @@ install_new() { - if ! install_dirs $NEWTREE "$DESTDIR" $1; then + if ! install_dirs "$NEWTREE" "$DESTDIR" "$1"; then return 1 fi log "cp -Rp ${NEWTREE}$1 ${DESTDIR}$1" if [ -z "$dryrun" ]; then - cp -Rp ${NEWTREE}$1 ${DESTDIR}$1 >&3 2>&1 + cp -Rp "${NEWTREE}$1" "${DESTDIR}$1" >&3 2>&1 fi - post_install_file $1 + post_install_file "$1" return 0 } @@ -704,14 +704,14 @@ # This should always be present since the file is already # there (it caused a conflict). However, it doesn't hurt to # just be safe. - if ! install_dirs $NEWTREE "$DESTDIR" $1; then + if ! install_dirs "$NEWTREE" "$DESTDIR" "$1"; then return 1 fi # Use cat rather than cp to preserve metadata log "cat ${CONFLICTS}$1 > ${DESTDIR}$1" - cat ${CONFLICTS}$1 > ${DESTDIR}$1 2>&3 - post_install_file $1 + cat "${CONFLICTS}$1" > "${DESTDIR}$1" 2>&3 + post_install_file "$1" return 0 } @@ -726,11 +726,11 @@ return fi - install_dirs $NEWTREE $CONFLICTS $1 + install_dirs "$NEWTREE" "$CONFLICTS" "$1" diff --changed-group-format='<<<<<<< (local) %<======= %>>>>>>>> (stock) -' $DESTDIR/$1 $NEWTREE/$1 > $CONFLICTS/$1 +' "$DESTDIR/$1" "$NEWTREE/$1" > "$CONFLICTS/$1" } # Remove the "old" version of a file. @@ -740,7 +740,7 @@ { log "rm -f ${DESTDIR}$1" if [ -z "$dryrun" ]; then - rm -f ${DESTDIR}$1 >&3 2>&1 + rm -f "${DESTDIR}$1" >&3 2>&1 fi echo " D $1" } @@ -757,11 +757,11 @@ # from a directory to a non-directory). If the directory # isn't empty, then fail. This will be reported as a warning # later. - if [ -d $DESTDIR/$1 ]; then - if empty_destdir $1; then + if [ -d "$DESTDIR/$1" ]; then + if empty_destdir "$1"; then log "rmdir ${DESTDIR}$1" if [ -z "$dryrun" ]; then - rmdir ${DESTDIR}$1 >&3 2>&1 + rmdir "${DESTDIR}$1" >&3 2>&1 fi else return 1 @@ -770,10 +770,10 @@ # If both the old and new files are regular files, leave the # existing file. This avoids breaking hard links for /.cshrc # and /.profile. Otherwise, explicitly remove the old file. - elif ! [ -f ${DESTDIR}$1 -a -f ${NEWTREE}$1 ]; then + elif ! [ -f "${DESTDIR}$1" -a -f "${NEWTREE}$1" ]; then log "rm -f ${DESTDIR}$1" if [ -z "$dryrun" ]; then - rm -f ${DESTDIR}$1 >&3 2>&1 + rm -f "${DESTDIR}$1" >&3 2>&1 fi fi @@ -781,13 +781,13 @@ # been removed, but don't do anything else for now. The # directory will be installed if needed when new files within # that directory are installed. - if [ -d $NEWTREE/$1 ]; then - if empty_dir $NEWTREE/$1; then + if [ -d "$NEWTREE/$1" ]; then + if empty_dir "$NEWTREE/$1"; then echo " D $file" else echo " U $file" fi - elif install_new $1; then + elif install_new "$1"; then echo " U $file" fi return 0 @@ -806,8 +806,8 @@ # updated. Otherwise, if either file has more than one # FreeBSD ID string, just punt and let the user handle the # conflict manually. - new=`grep -c '\$FreeBSD.*\$' ${NEWTREE}$1` - dest=`grep -c '\$FreeBSD.*\$' ${DESTDIR}$1` + new=$(grep -c '\$FreeBSD.*\$' "${NEWTREE}$1") + dest=$(grep -c '\$FreeBSD.*\$' "${DESTDIR}$1") if [ "$dest" -eq 0 ]; then return 0 fi @@ -817,8 +817,8 @@ # If the FreeBSD ID string in the new file matches the FreeBSD ID # string in the local file, there is nothing to do. - new=`grep '\$FreeBSD.*\$' ${NEWTREE}$1` - dest=`grep '\$FreeBSD.*\$' ${DESTDIR}$1` + new=$(grep '\$FreeBSD.*\$' "${NEWTREE}$1") + dest=$(grep '\$FreeBSD.*\$' "${DESTDIR}$1") if [ "$new" = "$dest" ]; then return 0 fi @@ -828,26 +828,26 @@ # of the file. Second, append the FreeBSD ID string line from # the new version. Finally, append all the lines after the # FreeBSD ID string from the local version of the file. - file=`mktemp $WORKDIR/etcupdate-XXXXXXX` - awk '/\$FreeBSD.*\$/ { exit } { print }' ${DESTDIR}$1 >> $file - awk '/\$FreeBSD.*\$/ { print }' ${NEWTREE}$1 >> $file + file=$(mktemp "$WORKDIR/etcupdate-XXXXXXX") + awk '/\$FreeBSD.*\$/ { exit } { print }' "${DESTDIR}$1" >> "$file" + awk '/\$FreeBSD.*\$/ { print }' "${NEWTREE}$1" >> "$file" awk '/\$FreeBSD.*\$/ { ok = 1; next } { if (ok) print }' \ - ${DESTDIR}$1 >> $file + "${DESTDIR}$1" >> "$file" # As an extra sanity check, fail the attempt if the updated # version of the file has any differences aside from the # FreeBSD ID string. - if ! fbsdid_only ${DESTDIR}$1 $file; then - rm -f $file + if ! fbsdid_only "${DESTDIR}$1" "$file"; then + rm -f "$file" return 1 fi log "cp $file ${DESTDIR}$1" if [ -z "$dryrun" ]; then - cp $file ${DESTDIR}$1 >&3 2>&1 + cp "$file" "${DESTDIR}$1" >&3 2>&1 fi - rm -f $file - post_install_file $1 + rm -f "$file" + post_install_file "$1" echo " M $1" return 0 } @@ -863,7 +863,7 @@ local res # Try the merge to see if there is a conflict. - diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > /dev/null 2>&3 + diff3 -E -m "${DESTDIR}$1" "${OLDTREE}$1" "${NEWTREE}$1" > /dev/null 2>&3 res=$? case $res in 0) @@ -872,23 +872,23 @@ log "diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1" if [ -z "$dryrun" ]; then temp=$(mktemp -t etcupdate) - diff3 -E -m ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > ${temp} + diff3 -E -m "${DESTDIR}$1" "${OLDTREE}$1" "${NEWTREE}$1" > "${temp}" # Use "cat >" to preserve metadata. - cat ${temp} > ${DESTDIR}$1 - rm -f ${temp} + cat "${temp}" > "${DESTDIR}$1" + rm -f "${temp}" fi - post_install_file $1 + post_install_file "$1" echo " M $1" ;; 1) # Conflicts, save a version with conflict markers in # the conflicts directory. if [ -z "$dryrun" ]; then - install_dirs $NEWTREE $CONFLICTS $1 + install_dirs "$NEWTREE" "$CONFLICTS" "$1" log "diff3 -m ${DESTDIR}$1 ${CONFLICTS}$1" diff3 -m -L "yours" -L "original" -L "new" \ - ${DESTDIR}$1 ${OLDTREE}$1 ${NEWTREE}$1 > \ - ${CONFLICTS}$1 + "${DESTDIR}$1" "${OLDTREE}$1" "${NEWTREE}$1" > \ + "${CONFLICTS}$1" fi echo " C $1" ;; @@ -904,7 +904,7 @@ has_conflicts() { - egrep -q '^(<{7}|\|{7}|={7}|>{7}) ' $CONFLICTS/$1 + egrep -q '^(<{7}|\|{7}|={7}|>{7}) ' "$CONFLICTS/$1" } # Attempt to resolve a conflict. The user is prompted to choose an @@ -925,7 +925,7 @@ # Only display the resolved command if the file # doesn't contain any conflicts. echo -n "Select: (p) postpone, (df) diff-full, (e) edit," - if ! has_conflicts $1; then + if ! has_conflicts "$1"; then echo -n " (r) resolved," fi echo @@ -933,10 +933,10 @@ read command case $command in df) - diff -u ${DESTDIR}$1 ${CONFLICTS}$1 + diff -u "${DESTDIR}$1" "${CONFLICTS}$1" ;; e) - $EDITOR ${CONFLICTS}$1 + $EDITOR "${CONFLICTS}$1" ;; h) cat </dev/null 2>&1 + rmdir "${DESTDIR}$dir" >/dev/null 2>&1 fi echo " D $dir" else @@ -1079,12 +1079,12 @@ local cmp dest file new newdestcmp old file=$1 - if ignore $file; then + if ignore "$file"; then log "IGNORE: modified file $file" return fi - compare $OLDTREE/$file $NEWTREE/$file + compare "$OLDTREE/$file" "$NEWTREE/$file" cmp=$? if [ $cmp -eq $COMPARE_EQUAL ]; then return @@ -1094,7 +1094,7 @@ panic "Changed file now missing" fi - compare $NEWTREE/$file $DESTDIR/$file + compare "$NEWTREE/$file" "$DESTDIR/$file" newdestcmp=$? if [ $newdestcmp -eq $COMPARE_EQUAL ]; then return @@ -1104,8 +1104,8 @@ # file is a change in the FreeBSD ID string and -F is # specified, just install the new file. if [ -n "$FREEBSD_ID" -a $newdestcmp -eq $COMPARE_DIFFFILES ] && \ - fbsdid_only $NEWTREE/$file $DESTDIR/$file; then - if update_unmodified $file; then + fbsdid_only "$NEWTREE/$file" "$DESTDIR/$file"; then + if update_unmodified "$file"; then return else panic "Updating FreeBSD ID string failed" @@ -1115,8 +1115,8 @@ # If the local file is the same as the old file, install the # new file. If -F is specified and the only local change is # in the FreeBSD ID string, then install the new file as well. - if compare_fbsdid $OLDTREE/$file $DESTDIR/$file; then - if update_unmodified $file; then + if compare_fbsdid "$OLDTREE/$file" "$DESTDIR/$file"; then + if update_unmodified "$file"; then return fi fi @@ -1125,10 +1125,10 @@ if [ $newdestcmp -eq $COMPARE_ONLYFIRST ]; then # If the removed file matches an ALWAYS_INSTALL glob, # then just install the new version of the file. - if always_install $file; then + if always_install "$file"; then log "ALWAYS: adding $file" - if ! [ -d $NEWTREE/$file ]; then - if install_new $file; then + if ! [ -d "$NEWTREE/$file" ]; then + if install_new "$file"; then echo " A $file" fi fi @@ -1139,23 +1139,23 @@ # file is a change in the FreeBSD ID string and -F is # specified, don't warn. if [ -n "$FREEBSD_ID" -a $cmp -eq $COMPARE_DIFFFILES ] && \ - fbsdid_only $OLDTREE/$file $NEWTREE/$file; then + fbsdid_only "$OLDTREE/$file" "$NEWTREE/$file"; then return fi case $cmp in - $COMPARE_DIFFTYPE) - old=`file_type $OLDTREE/$file` - new=`file_type $NEWTREE/$file` + "$COMPARE_DIFFTYPE") + old=$(file_type "$OLDTREE/$file") + new=$(file_type "$NEWTREE/$file") warn "Remove mismatch: $file ($old became $new)" ;; - $COMPARE_DIFFLINKS) - old=`readlink $OLDTREE/$file` - new=`readlink $NEWTREE/$file` + "$COMPARE_DIFFLINKS") + old=$(readlink "$OLDTREE/$file") + new=$(readlink "$NEWTREE/$file") warn \ "Removed link changed: $file (\"$old\" became \"$new\")" ;; - $COMPARE_DIFFFILES) + "$COMPARE_DIFFFILES") warn "Removed file changed: $file" ;; esac @@ -1166,9 +1166,9 @@ # file if it matches an ALWAYS_INSTALL glob. If the update # attempt fails, then fall through to the normal case so a # warning is generated. - if always_install $file; then + if always_install "$file"; then log "ALWAYS: updating $file" - if update_unmodified $file; then + if update_unmodified "$file"; then return fi fi @@ -1177,8 +1177,8 @@ # change in the FreeBSD ID string and -F is specified, just # update the FreeBSD ID string in the local file. if [ -n "$FREEBSD_ID" -a $cmp -eq $COMPARE_DIFFFILES ] && \ - fbsdid_only $OLDTREE/$file $NEWTREE/$file; then - if update_freebsdid $file; then + fbsdid_only "$OLDTREE/$file" "$NEWTREE/$file"; then + if update_freebsdid "$file"; then continue fi fi @@ -1189,15 +1189,15 @@ # dest files. if [ $cmp -eq $COMPARE_DIFFTYPE ]; then case $newdestcmp in - $COMPARE_DIFFLINKS) - new=`readlink $NEWTREE/$file` - dest=`readlink $DESTDIR/$file` + "$COMPARE_DIFFLINKS") + new=$(readlink "$NEWTREE/$file") + dest=$(readlink "$DESTDIR/$file") warn \ "New link conflict: $file (\"$new\" vs \"$dest\")" return ;; - $COMPARE_DIFFFILES) - new_conflict $file + "$COMPARE_DIFFFILES") + new_conflict "$file" echo " C $file" return ;; @@ -1207,28 +1207,28 @@ # and new trees, but it is a different type in # DESTDIR, then just warn. if [ $newdestcmp -eq $COMPARE_DIFFTYPE ]; then - new=`file_type $NEWTREE/$file` - dest=`file_type $DESTDIR/$file` + new=$(file_type "$NEWTREE/$file") + dest=$(file_type "$DESTDIR/$file") warn "Modified mismatch: $file ($new vs $dest)" return fi fi case $cmp in - $COMPARE_DIFFTYPE) - old=`file_type $OLDTREE/$file` - new=`file_type $NEWTREE/$file` - dest=`file_type $DESTDIR/$file` + "$COMPARE_DIFFTYPE") + old=$(file_type "$OLDTREE/$file") + new=$(file_type "$NEWTREE/$file") + dest=$(file_type "$DESTDIR/$file") warn "Modified $dest changed: $file ($old became $new)" ;; - $COMPARE_DIFFLINKS) - old=`readlink $OLDTREE/$file` - new=`readlink $NEWTREE/$file` + "$COMPARE_DIFFLINKS") + old=$(readlink "$OLDTREE/$file") + new=$(readlink "$NEWTREE/$file") warn \ "Modified link changed: $file (\"$old\" became \"$new\")" ;; - $COMPARE_DIFFFILES) - merge_file $file + "$COMPARE_DIFFFILES") + merge_file "$file" ;; esac } @@ -1245,26 +1245,26 @@ local cmp dest file new file=$1 - if ignore $file; then + if ignore "$file"; then log "IGNORE: added file $file" return fi - compare $DESTDIR/$file $NEWTREE/$file + compare "$DESTDIR/$file" "$NEWTREE/$file" cmp=$? case $cmp in - $COMPARE_EQUAL) + "$COMPARE_EQUAL") return ;; - $COMPARE_ONLYFIRST) + "$COMPARE_ONLYFIRST") panic "Added file now missing" ;; - $COMPARE_ONLYSECOND) + "$COMPARE_ONLYSECOND") # Ignore new directories. They will be # created as needed when non-directory nodes # are installed. - if ! [ -d $NEWTREE/$file ]; then - if install_new $file; then + if ! [ -d "$NEWTREE/$file" ]; then + if install_new "$file"; then echo " A $file" fi fi @@ -1277,32 +1277,32 @@ # file if it matches an ALWAYS_INSTALL glob. If the update # attempt fails, then fall through to the normal case so a # warning is generated. - if always_install $file; then + if always_install "$file"; then log "ALWAYS: updating $file" - if update_unmodified $file; then + if update_unmodified "$file"; then return fi fi case $cmp in - $COMPARE_DIFFTYPE) - new=`file_type $NEWTREE/$file` - dest=`file_type $DESTDIR/$file` + "$COMPARE_DIFFTYPE") + new=$(file_type "$NEWTREE/$file") + dest=$(file_type "$DESTDIR/$file") warn "New file mismatch: $file ($new vs $dest)" ;; - $COMPARE_DIFFLINKS) - new=`readlink $NEWTREE/$file` - dest=`readlink $DESTDIR/$file` + "$COMPARE_DIFFLINKS") + new=$(readlink "$NEWTREE/$file") + dest=$(readlink "$DESTDIR/$file") warn "New link conflict: $file (\"$new\" vs \"$dest\")" ;; - $COMPARE_DIFFFILES) + "$COMPARE_DIFFFILES") # If the only change in the new file versus # the destination file is a change in the # FreeBSD ID string and -F is specified, just # install the new file. if [ -n "$FREEBSD_ID" ] && \ - fbsdid_only $NEWTREE/$file $DESTDIR/$file; then - if update_unmodified $file; then + fbsdid_only "$NEWTREE/$file" "$DESTDIR/$file"; then + if update_unmodified "$file"; then return else panic \ @@ -1310,7 +1310,7 @@ fi fi - new_conflict $file + new_conflict "$file" echo " C $file" ;; esac @@ -1332,14 +1332,14 @@ log "build command: $1" # Create a temporary directory to hold the tree - dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + dir=$(mktemp -d "$WORKDIR/etcupdate-XXXXXXX") if [ $? -ne 0 ]; then echo "Unable to create temporary directory." exit 1 fi - if ! build_tree $dir; then + if ! build_tree "$dir"; then echo "Failed to build tree." - remove_tree $dir + remove_tree "$dir" exit 1 fi if [ -n "$noroot" ]; then @@ -1347,12 +1347,12 @@ else tartree=. fi - if ! tar cfj $1 -C $dir $tartree >&3 2>&1; then + if ! tar cfj "$1" -C "$dir" "$tartree" >&3 2>&1; then echo "Failed to create tarball." - remove_tree $dir + remove_tree "$dir" exit 1 fi - remove_tree $dir + remove_tree "$dir" } # Output a diff comparing the tree at DESTDIR to the current @@ -1367,19 +1367,19 @@ fi # Requires an unmodified tree to diff against. - if ! [ -d $NEWTREE ]; then + if ! [ -d "$NEWTREE" ]; then echo "Reference tree to diff against unavailable." exit 1 fi # Unfortunately, diff alone does not quite provide the right # level of options that we want, so improvise. - for file in `(cd $NEWTREE; find .) | sed -e 's/^\.//'`; do - if ignore $file; then + for file in `(cd "$NEWTREE" || exit; find .) | sed -e 's/^\.//'`; do + if ignore "$file"; then continue fi - diffnode $NEWTREE "$DESTDIR" $file "stock" "local" + diffnode "$NEWTREE" "$DESTDIR" "$file" "stock" "local" done } @@ -1400,25 +1400,25 @@ log "extract command: tarball=$tarball" # Create a temporary directory to hold the tree - dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + dir=$(mktemp -d "$WORKDIR/etcupdate-XXXXXXX") if [ $? -ne 0 ]; then echo "Unable to create temporary directory." exit 1 fi - extract_tree $dir + extract_tree "$dir" - if [ -d $NEWTREE ]; then - if ! remove_tree $NEWTREE; then + if [ -d "$NEWTREE" ]; then + if ! remove_tree "$NEWTREE"; then echo "Unable to remove current tree." - remove_tree $dir + remove_tree "$dir" exit 1 fi fi - if ! mv $dir $NEWTREE >&3 2>&1; then + if ! mv "$dir" "$NEWTREE" >&3 2>&1; then echo "Unable to rename temp tree to current tree." - remove_tree $dir + remove_tree "$dir" exit 1 fi } @@ -1432,18 +1432,18 @@ usage fi - if ! [ -d $CONFLICTS ]; then + if ! [ -d "$CONFLICTS" ]; then return fi - if ! [ -d $NEWTREE ]; then + if ! [ -d "$NEWTREE" ]; then echo "The current tree is not present to resolve conflicts." exit 1 fi - conflicts=`(cd $CONFLICTS; find . ! -type d) | sed -e 's/^\.//'` + conflicts=`(cd "$CONFLICTS" || exit; find . ! -type d) | sed -e 's/^\.//'` for file in $conflicts; do - resolve_conflict $file + resolve_conflict "$file" done if [ -n "$NEWALIAS_WARN" ]; then @@ -1469,26 +1469,26 @@ for file; do log "revert $file" - if ! [ -e $NEWTREE/$file ]; then + if ! [ -e "$NEWTREE/$file" ]; then echo "File $file does not exist in the current tree." exit 1 fi - if [ -d $NEWTREE/$file ]; then + if [ -d "$NEWTREE/$file" ]; then echo "File $file is a directory." exit 1 fi - compare $DESTDIR/$file $NEWTREE/$file + compare "$DESTDIR/$file" "$NEWTREE/$file" cmp=$? if [ $cmp -eq $COMPARE_EQUAL ]; then continue fi - if update_unmodified $file; then + if update_unmodified "$file"; then # If this file had a conflict, clean up the # conflict. - if [ -e $CONFLICTS/$file ]; then - if ! rm $CONFLICTS/$file >&3 2>&1; then + if [ -e "$CONFLICTS/$file" ]; then + if ! rm "$CONFLICTS/$file" >&3 2>&1; then echo "Failed to remove conflict " \ "for $file". fi @@ -1507,12 +1507,12 @@ usage fi - if [ -d $CONFLICTS ]; then - (cd $CONFLICTS; find . ! -type d) | sed -e 's/^\./ C /' + if [ -d "$CONFLICTS" ]; then + (cd "$CONFLICTS" || exit; find . ! -type d) | sed -e 's/^\./ C /' fi - if [ -s $WARNINGS ]; then + if [ -s "$WARNINGS" ]; then echo "Warnings:" - cat $WARNINGS + cat "$WARNINGS" fi } @@ -1529,7 +1529,7 @@ log "update command: rerun=$rerun tarball=$tarball preworld=$preworld" - if [ `id -u` -ne 0 ]; then + if [ $(id -u) -ne 0 ]; then echo "Must be root to update a tree." exit 1 fi @@ -1541,11 +1541,11 @@ # a rerun? # Trim the conflicts tree. Whine if there is anything left. - if [ -e $CONFLICTS ]; then - find -d $CONFLICTS -type d -empty -delete >&3 2>&1 - rmdir $CONFLICTS >&3 2>&1 + if [ -e "$CONFLICTS" ]; then + find -d "$CONFLICTS" -type d -empty -delete >&3 2>&1 + rmdir "$CONFLICTS" >&3 2>&1 fi - if [ -d $CONFLICTS ]; then + if [ -d "$CONFLICTS" ]; then echo "Conflicts remain from previous update, aborting." exit 1 fi @@ -1558,14 +1558,14 @@ # trees are only rotated after a successful update to # avoid races if an update command is interrupted # before it completes. - dir=`mktemp -d $WORKDIR/etcupdate-XXXXXXX` + dir=$(mktemp -d "$WORKDIR"/etcupdate-XXXXXXX) if [ $? -ne 0 ]; then echo "Unable to create temporary directory." exit 1 fi # Populate the new tree. - extract_tree $dir + extract_tree "$dir" # Compare the new tree against the previous tree. For # the preworld case OLDTREE already points to the @@ -1576,7 +1576,7 @@ NEWTREE=$dir fi - if ! [ -d $OLDTREE ]; then + if ! [ -d "$OLDTREE" ]; then cat < $WORKDIR/old.files - (cd $NEWTREE; find .) | sed -e 's/^\.//' | sort > $WORKDIR/new.files + (cd "$OLDTREE" || exit; find .) | sed -e 's/^\.//' | sort > "$WORKDIR/old.files" + (cd "$NEWTREE" || exit; find .) | sed -e 's/^\.//' | sort > "$WORKDIR/new.files" # Split the files up into three groups using comm. - comm -23 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/removed.files - comm -13 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/added.files - comm -12 $WORKDIR/old.files $WORKDIR/new.files > $WORKDIR/both.files + comm -23 "$WORKDIR/old.files" "$WORKDIR/new.files" > "$WORKDIR/removed.files" + comm -13 "$WORKDIR/old.files" "$WORKDIR/new.files" > "$WORKDIR/added.files" + comm -12 "$WORKDIR/old.files" "$WORKDIR/new.files" > "$WORKDIR/both.files" # Initialize conflicts and warnings handling. - rm -f $WARNINGS - mkdir -p $CONFLICTS + rm -f "$WARNINGS" + mkdir -p "$CONFLICTS" # Ignore removed files for the pre-world case. A pre-world # update uses a stripped-down tree. if [ -n "$preworld" ]; then - > $WORKDIR/removed.files + > "$WORKDIR/removed.files" fi # The order for the following sections is important. In the @@ -1617,27 +1617,27 @@ # into a directory if possible before the new files are added. # First, handle removed files. - for file in `cat $WORKDIR/removed.files`; do - handle_removed_file $file + for file in $(cat "$WORKDIR/removed.files"); do + handle_removed_file "$file" done # For the directory pass, reverse sort the list to effect a # depth-first traversal. This is needed to ensure that if a # directory with subdirectories is removed, the entire # directory is removed if there are no local modifications. - for file in `sort -r $WORKDIR/removed.files`; do - handle_removed_directory $file + for file in $(sort -r "$WORKDIR/removed.files"); do + handle_removed_directory "$file" done # Second, handle files that exist in both the old and new # trees. - for file in `cat $WORKDIR/both.files`; do - handle_modified_file $file + for file in $(cat "$WORKDIR/both.files"); do + handle_modified_file "$file" done # Finally, handle newly added files. - for file in `cat $WORKDIR/added.files`; do - handle_added_file $file + for file in $(cat "$WORKDIR/added.files"); do + handle_added_file "$file" done if [ -n "$NEWALIAS_WARN" ]; then @@ -1648,9 +1648,9 @@ # Run any special one-off commands after an update has completed. post_update - if [ -s $WARNINGS ]; then + if [ -s "$WARNINGS" ]; then echo "Warnings:" - cat $WARNINGS + cat "$WARNINGS" fi # If this was a dryrun, remove the temporary tree if we built @@ -1660,7 +1660,7 @@ if [ -n "$rerun" ]; then panic "Should not have a temporary directory" fi - remove_tree $dir + remove_tree "$dir" fi return fi @@ -1680,12 +1680,12 @@ panic "Old tree should be unchanged" fi - if ! remove_tree $old; then + if ! remove_tree "$old"; then echo "Unable to remove previous old tree." exit 1 fi - if ! mv $OLDTREE $old >&3 2>&1; then + if ! mv "$OLDTREE" "$old" >&3 2>&1; then echo "Unable to rename old tree." exit 1 fi @@ -1693,17 +1693,17 @@ # Rotate the new tree. Remove a previous pre-world # tree if it exists. - if [ -d $new ]; then + if [ -d "$new" ]; then if [ -z "$preworld" ]; then panic "New tree should be rotated to old" fi - if ! remove_tree $new; then + if ! remove_tree "$new"; then echo "Unable to remove previous pre-world tree." exit 1 fi fi - if ! mv $NEWTREE $new >&3 2>&1; then + if ! mv "$NEWTREE" "$new" >&3 2>&1; then echo "Unable to rename current tree." exit 1 fi @@ -1935,17 +1935,17 @@ # Open the log file. Don't truncate it if doing a minor operation so # that a minor operation doesn't lose log info from a major operation. -if ! mkdir -p $WORKDIR 2>/dev/null; then +if ! mkdir -p "$WORKDIR" 2>/dev/null; then echo "Failed to create work directory $WORKDIR" fi case $command in diff|resolve|revert|status) - exec 3>>$LOGFILE + exec 3>>"$LOGFILE" ;; *) - exec 3>$LOGFILE + exec 3>"$LOGFILE" ;; esac -${command}_cmd "$@" +"${command}"_cmd "$@"