Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/etcupdate/etcupdate.sh
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
# root trees that can later be used. It can also use a tarball as the | # root trees that can later be used. It can also use a tarball as the | ||||
# source of a new tree instead of building it from /usr/src. | # source of a new tree instead of building it from /usr/src. | ||||
# Global settings. These can be adjusted by config files and in some | # Global settings. These can be adjusted by config files and in some | ||||
# cases by command line options. | # cases by command line options. | ||||
# TODO: | # TODO: | ||||
# - automatable conflict resolution | # - automatable conflict resolution | ||||
# - a 'revert' command to make a file "stock" | |||||
usage() | usage() | ||||
{ | { | ||||
cat <<EOF | cat <<EOF | ||||
usage: etcupdate [-npBF] [-d workdir] [-r | -s source | -t tarball] | usage: etcupdate [-npBF] [-d workdir] [-r | -s source | -t tarball] | ||||
[-A patterns] [-D destdir] [-I patterns] [-L logfile] | [-A patterns] [-D destdir] [-I patterns] [-L logfile] | ||||
[-M options] | [-M options] | ||||
etcupdate build [-B] [-d workdir] [-s source] [-L logfile] [-M options] | etcupdate build [-B] [-d workdir] [-s source] [-L logfile] [-M options] | ||||
<tarball> | <tarball> | ||||
etcupdate diff [-d workdir] [-D destdir] [-I patterns] [-L logfile] | etcupdate diff [-d workdir] [-D destdir] [-I patterns] [-L logfile] | ||||
etcupdate extract [-B] [-d workdir] [-s source | -t tarball] [-L logfile] | etcupdate extract [-B] [-d workdir] [-s source | -t tarball] [-L logfile] | ||||
[-M options] | [-M options] | ||||
etcupdate resolve [-p] [-d workdir] [-D destdir] [-L logfile] | etcupdate resolve [-p] [-d workdir] [-D destdir] [-L logfile] | ||||
etcupdate revert [-d workdir] [-D destdir] [-L logfile] file ... | |||||
etcupdate status [-d workdir] [-D destdir] | etcupdate status [-d workdir] [-D destdir] | ||||
EOF | EOF | ||||
exit 1 | exit 1 | ||||
} | } | ||||
# Used to write a message prepended with '>>>' to the logfile. | # Used to write a message prepended with '>>>' to the logfile. | ||||
log() | log() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,327 Lines • ▼ Show 20 Lines | warn "Needs update: /etc/mail/aliases.db" \ | ||||
"(requires manual update via newaliases(1))" | "(requires manual update via newaliases(1))" | ||||
echo | echo | ||||
echo "Warnings:" | echo "Warnings:" | ||||
echo " Needs update: /etc/mail/aliases.db" \ | echo " Needs update: /etc/mail/aliases.db" \ | ||||
"(requires manual update via newaliases(1))" | "(requires manual update via newaliases(1))" | ||||
fi | fi | ||||
} | } | ||||
# Restore files to the stock version. Only files with a local change | |||||
# are restored from the stock version. | |||||
revert_cmd() | |||||
{ | |||||
local cmp file | |||||
if [ $# -eq 0 ]; then | |||||
usage | |||||
fi | |||||
for file; do | |||||
log "revert $file" | |||||
if ! [ -e $NEWTREE/$file ]; then | |||||
echo "File $file does not exist in the current tree." | |||||
exit 1 | |||||
fi | |||||
if [ -d $NEWTREE/$file ]; then | |||||
echo "File $file is a directory." | |||||
exit 1 | |||||
fi | |||||
compare $DESTDIR/$file $NEWTREE/$file | |||||
cmp=$? | |||||
if [ $cmp -eq $COMPARE_EQUAL ]; then | |||||
continue | |||||
fi | |||||
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 | |||||
echo "Failed to remove conflict " \ | |||||
"for $file". | |||||
fi | |||||
fi | |||||
fi | |||||
done | |||||
} | |||||
# Report a summary of the previous merge. Specifically, list any | # Report a summary of the previous merge. Specifically, list any | ||||
# remaining conflicts followed by any warnings from the previous | # remaining conflicts followed by any warnings from the previous | ||||
# update. | # update. | ||||
status_cmd() | status_cmd() | ||||
{ | { | ||||
if [ $# -ne 0 ]; then | if [ $# -ne 0 ]; then | ||||
usage | usage | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
# Determine which command we are executing. A command may be | # Determine which command we are executing. A command may be | ||||
# specified as the first word. If one is not specified then 'update' | # specified as the first word. If one is not specified then 'update' | ||||
# is assumed as the default command. | # is assumed as the default command. | ||||
command="update" | command="update" | ||||
if [ $# -gt 0 ]; then | if [ $# -gt 0 ]; then | ||||
case "$1" in | case "$1" in | ||||
build|diff|extract|status|resolve) | build|diff|extract|status|resolve|revert) | ||||
command="$1" | command="$1" | ||||
shift | shift | ||||
;; | ;; | ||||
-*) | -*) | ||||
# If first arg is an option, assume the | # If first arg is an option, assume the | ||||
# default command. | # default command. | ||||
;; | ;; | ||||
*) | *) | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | if [ -n "$rerun" -a -n "$tarball" ]; then | ||||
usage | usage | ||||
fi | fi | ||||
if [ -n "$rerun" -a -n "$preworld" ]; then | if [ -n "$rerun" -a -n "$preworld" ]; then | ||||
echo "Only one of -p or -r can be specified." | echo "Only one of -p or -r can be specified." | ||||
echo | echo | ||||
usage | usage | ||||
fi | fi | ||||
;; | ;; | ||||
build|diff|status) | build|diff|status|revert) | ||||
if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" -o \ | if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" -o \ | ||||
-n "$preworld" ]; then | -n "$preworld" ]; then | ||||
usage | usage | ||||
fi | fi | ||||
;; | ;; | ||||
resolve) | resolve) | ||||
if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" ]; then | if [ -n "$dryrun" -o -n "$rerun" -o -n "$tarball" ]; then | ||||
usage | usage | ||||
Show All 17 Lines | |||||
# Open the log file. Don't truncate it if doing a minor operation so | # 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. | # 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" | echo "Failed to create work directory $WORKDIR" | ||||
fi | fi | ||||
case $command in | case $command in | ||||
diff|resolve|status) | diff|resolve|revert|status) | ||||
exec 3>>$LOGFILE | exec 3>>$LOGFILE | ||||
;; | ;; | ||||
*) | *) | ||||
exec 3>$LOGFILE | exec 3>$LOGFILE | ||||
;; | ;; | ||||
esac | esac | ||||
${command}_cmd "$@" | ${command}_cmd "$@" |