From a0afbf86eb509e5e7ea2b60dcfb82940342ac84b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 8 Jan 2018 16:22:28 +0100 Subject: [PATCH] saving uncommitted changes in /etc prior to emerge run --- .etckeeper | 1 + cron.daily/etckeeper | 15 ++------------ etckeeper/commit.d/20store-metadata | 1 + etckeeper/commit.d/50vcs-commit | 23 +++++++++++++++++---- etckeeper/daily | 17 +++++++++++++++ etckeeper/etckeeper.conf | 14 +++++++------ etckeeper/list-installed.d/50list-installed | 6 ++++++ etckeeper/pre-commit.d/20warn-problem-files | 6 +++--- etckeeper/pre-commit.d/30store-metadata | 15 +++----------- etckeeper/update-ignore.d/01update-ignore | 6 +++++- 10 files changed, 65 insertions(+), 39 deletions(-) create mode 120000 etckeeper/commit.d/20store-metadata create mode 100755 etckeeper/daily diff --git a/.etckeeper b/.etckeeper index 8d3ef0d..2688d8b 100755 --- a/.etckeeper +++ b/.etckeeper @@ -308,6 +308,7 @@ maybe chmod 0755 'etckeeper/commit.d/30hg-addremove' maybe chmod 0755 'etckeeper/commit.d/50vcs-commit' maybe chmod 0755 'etckeeper/commit.d/99push' maybe chmod 0644 'etckeeper/commit.d/README' +maybe chmod 0755 'etckeeper/daily' maybe chmod 0644 'etckeeper/etckeeper.conf' maybe chmod 0755 'etckeeper/init.d' maybe chmod 0755 'etckeeper/init.d/10restore-metadata' diff --git a/cron.daily/etckeeper b/cron.daily/etckeeper index 5255691..eb74401 100755 --- a/cron.daily/etckeeper +++ b/cron.daily/etckeeper @@ -1,19 +1,8 @@ #!/bin/sh set -e -if [ -x /usr/bin/etckeeper ] && [ -e /etc/etckeeper/etckeeper.conf ]; then +if [ -e /etc/etckeeper/daily ] && [ -e /etc/etckeeper/etckeeper.conf ]; then . /etc/etckeeper/etckeeper.conf if [ "$AVOID_DAILY_AUTOCOMMITS" != "1" ]; then - # avoid autocommit if an install run is in progress - lockfile=/var/cache/etckeeper/packagelist.pre-install - if [ -e "$lockfile" ] && [ -n "$(find "$lockfile" -mtime +1)" ]; then - rm -f "$lockfile" # stale - fi - if [ ! -e "$lockfile" ]; then - AVOID_SPECIAL_FILE_WARNING=1 - export AVOID_SPECIAL_FILE_WARNING - if etckeeper unclean; then - etckeeper commit "daily autocommit" >/dev/null - fi - fi + /etc/etckeeper/daily fi fi diff --git a/etckeeper/commit.d/20store-metadata b/etckeeper/commit.d/20store-metadata new file mode 120000 index 0000000..5698d64 --- /dev/null +++ b/etckeeper/commit.d/20store-metadata @@ -0,0 +1 @@ +../pre-commit.d/30store-metadata \ No newline at end of file diff --git a/etckeeper/commit.d/50vcs-commit b/etckeeper/commit.d/50vcs-commit index 7c6173f..55f0db2 100755 --- a/etckeeper/commit.d/50vcs-commit +++ b/etckeeper/commit.d/50vcs-commit @@ -28,6 +28,7 @@ if [ -n "$dnsdomainname" ]; then hostname="$hostname.$dnsdomainname" fi +ORIG_USER=$USER USER= if [ -n "$SUDO_USER" ]; then USER="$SUDO_USER" @@ -43,7 +44,7 @@ if [ "$VCS" = git ] && [ -d .git ]; then if [ -n "$USER" ]; then # Use user.name and user.email from the gitconfig belonging # to the user who became root. - USER_HOME="$(perl -e 'print ((getpwnam(shift()))[7])' "$USER")" + USER_HOME="$(getent passwd "$USER" | cut -d: -f6)" if [ -n "$USER_HOME" ] && [ -e "$USER_HOME/.gitconfig" ]; then if [ -z "$GIT_AUTHOR_NAME" ]; then GIT_AUTHOR_NAME="$(git config -f "$USER_HOME/.gitconfig" user.name)" || true @@ -54,11 +55,23 @@ if [ "$VCS" = git ] && [ -d .git ]; then export GIT_AUTHOR_EMAIL fi fi - if [ -z "$GIT_COMMITTER_EMAIL" ]; then - GIT_COMMITER_EMAIL="$(git config --global user.email)" || true - export GIT_COMMITER_EMAIL + if [ -z "$GIT_AUTHOR_NAME" ] || [ -z "$GIT_AUTHOR_EMAIL" ]; then + if [ -n "$USER_HOME" ] && [ -e "$USER_HOME/.config/git/config" ]; then + if [ -z "$GIT_AUTHOR_NAME" ]; then + GIT_AUTHOR_NAME="$(git config -f "$USER_HOME/.config/git/config" user.name)" || true + export GIT_AUTHOR_NAME + fi + if [ -z "$GIT_AUTHOR_EMAIL" ]; then + GIT_AUTHOR_EMAIL="$(git config -f "$USER_HOME/.config/git/config" user.email)" || true + export GIT_AUTHOR_EMAIL + fi + fi fi + if [ -z "$GIT_COMMITTER_EMAIL" ]; then + GIT_COMMITTER_EMAIL="$(git config --global user.email)" || true + export GIT_COMMITTER_EMAIL + fi if [ -z "$GIT_AUTHOR_NAME" ]; then GIT_AUTHOR_NAME="$USER" export GIT_AUTHOR_NAME @@ -95,6 +108,8 @@ elif [ "$VCS" = bzr ] && [ -d .bzr ]; then if [ -z "$EMAIL" ] && [ -n "$USER" ]; then EMAIL="$USER <$USER@$hostname>" export EMAIL + else + bzr whoami >/dev/null 2>&1 || export EMAIL="$ORIG_USER <$ORIG_USER@$hostname>" fi if [ -n "$logfile" ]; then bzr commit $BZR_COMMIT_OPTIONS -F "$logfile" diff --git a/etckeeper/daily b/etckeeper/daily new file mode 100755 index 0000000..f98c6ad --- /dev/null +++ b/etckeeper/daily @@ -0,0 +1,17 @@ +#!/bin/sh +# Script that can be run daily to autocommit /etc changes. +set -e +if [ -x /usr/bin/etckeeper ] && [ -e /etc/etckeeper/etckeeper.conf ]; then + # avoid autocommit if an install run is in progress + lockfile=/var/cache/etckeeper/packagelist.pre-install + if [ -e "$lockfile" ] && [ -n "$(find "$lockfile" -mtime +1)" ]; then + rm -f "$lockfile" # stale + fi + if [ ! -e "$lockfile" ]; then + AVOID_SPECIAL_FILE_WARNING=1 + export AVOID_SPECIAL_FILE_WARNING + if etckeeper unclean; then + etckeeper commit "daily autocommit" >/dev/null + fi + fi +fi diff --git a/etckeeper/etckeeper.conf b/etckeeper/etckeeper.conf index 0a9c88b..eddfa04 100644 --- a/etckeeper/etckeeper.conf +++ b/etckeeper/etckeeper.conf @@ -16,12 +16,14 @@ BZR_COMMIT_OPTIONS="" # Options passed to darcs record when run by etckeeper. DARCS_COMMIT_OPTIONS="-a" -# Uncomment to avoid etckeeper committing existing changes -# to /etc automatically once per day. +# Etckeeper includes both a cron job and a systemd timer, which each +# can commit exiting changes to /etc automatically once per day. +# To enable the systemd timer, run: systemctl enable etckeeper.timer +# The cron job is enabled by default; to disable it, uncomment this next line. #AVOID_DAILY_AUTOCOMMITS=1 # Uncomment the following to avoid special file warning -# (the option is enabled automatically by cronjob regardless). +# (the option is enabled automatically for daily autocommits regardless). #AVOID_SPECIAL_FILE_WARNING=1 # Uncomment to avoid etckeeper committing existing changes to @@ -30,16 +32,16 @@ DARCS_COMMIT_OPTIONS="-a" #AVOID_COMMIT_BEFORE_INSTALL=1 # The high-level package manager that's being used. -# (apt, pacman-g2, yum, dnf, zypper etc) +# (apt, pacman, pacman-g2, yum, dnf, zypper, apk etc) #HIGHLEVEL_PACKAGE_MANAGER=apt -# Gentoo specific: +# Gentoo specific: # For portage this is emerge # For paludis this is cave HIGHLEVEL_PACKAGE_MANAGER=emerge # The low-level package manager that's being used. -# (dpkg, rpm, pacman, pacman-g2, etc) +# (dpkg, rpm, pacman, pacmatic, pacman-g2, apk etc) #LOWLEVEL_PACKAGE_MANAGER=dpkg # Gentoo specific: diff --git a/etckeeper/list-installed.d/50list-installed b/etckeeper/list-installed.d/50list-installed index 91718d4..2db838d 100755 --- a/etckeeper/list-installed.d/50list-installed +++ b/etckeeper/list-installed.d/50list-installed @@ -17,6 +17,12 @@ else rpm -qa --qf "%|epoch?{%{epoch}}:{0}|:%{name}-%{version}-%{release}.%{arch}\n" | sort elif [ "$LOWLEVEL_PACKAGE_MANAGER" = pacman ]; then pacman -Q + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = pacmatic ]; then + pacmatic -Q + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = pkgng ]; then + pkg info -E "*" + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = apk ]; then + apk info -v | sort elif [ "$LOWLEVEL_PACKAGE_MANAGER" = qlist ]; then qlist -ICv elif [ "$LOWLEVEL_PACKAGE_MANAGER" = cave ]; then diff --git a/etckeeper/pre-commit.d/20warn-problem-files b/etckeeper/pre-commit.d/20warn-problem-files index f28d5ac..6bd5c2b 100755 --- a/etckeeper/pre-commit.d/20warn-problem-files +++ b/etckeeper/pre-commit.d/20warn-problem-files @@ -2,7 +2,7 @@ set -e exclude_internal () { - egrep -v '(^|/)(.git|.hg|.bzr|_darcs)/' + egrep -v '(^|/)(\.git|\.hg|\.bzr|_darcs)/' } if [ "$VCS" = bzr ] || [ "$VCS" = darcs ]; then @@ -12,8 +12,8 @@ elif [ "$VCS" = hg ]; then special=$(find . ! -type d ! -type f ! -type l | exclude_internal) || true hardlinks=$(find . -type f ! -links 1 -exec hg status {} \; | exclude_internal ) || true elif [ "$VCS" = git ]; then - special=$(find . ! -type d ! -type f ! -type l -exec git ls-files --exclude-standard --cached --others {} \; | exclude_internal) || true - hardlinks=$(find . -type f ! -links 1 -exec git ls-files --exclude-standard --cached --others {} \; | exclude_internal) || true + special=$(find . ! -type d ! -type f ! -type l -exec git ls-files --exclude-standard --cached --others {} + | exclude_internal) || true + hardlinks=$(find . -type f ! -links 1 -exec git ls-files --exclude-standard --cached --others {} + | exclude_internal) || true else special="" fi diff --git a/etckeeper/pre-commit.d/30store-metadata b/etckeeper/pre-commit.d/30store-metadata index edec06b..6d7d4b1 100755 --- a/etckeeper/pre-commit.d/30store-metadata +++ b/etckeeper/pre-commit.d/30store-metadata @@ -1,18 +1,9 @@ #!/bin/sh set -e -# Filters out UNKNOWN users and groups, prints a warning on stderr. -filter_unknown() { - CMD=$1 - while read line; do - # if the first n chars of $line equal "$CMD UNKNOWN "... - if [ "$(printf %.$((9+${#CMD}))s "$line")" = "$CMD UNKNOWN " ]; then - echo Bad "$2" for "$line" >&2 - else - echo "$line" - fi - done -} +# Make sure sort always sorts in same order. +LANG=C +export LANG filter_ignore() { case "$VCS" in diff --git a/etckeeper/update-ignore.d/01update-ignore b/etckeeper/update-ignore.d/01update-ignore index 88243ea..53afbde 100755 --- a/etckeeper/update-ignore.d/01update-ignore +++ b/etckeeper/update-ignore.d/01update-ignore @@ -93,12 +93,16 @@ writefile () { comment "new and old versions of conffiles, stored by apt/rpm" ignore "*.rpm*" nl - elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" -o "$LOWLEVEL_PACKAGE_MANAGER" = "pacman" ]; then + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "pacman-g2" -o "$LOWLEVEL_PACKAGE_MANAGER" = "pacman" -o "$LOWLEVEL_PACKAGE_MANAGER" = "pacmatic" ]; then comment "new and old versions of conffiles, stored by pacman" ignore "*.pacnew" ignore "*.pacorig" ignore "*.pacsave" nl + elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "apk" ]; then + comment "new versions of conffiles, stored by apk" + ignore "*.apk-new" + nl elif [ "$LOWLEVEL_PACKAGE_MANAGER" = "qlist" -o "$LOWLEVEL_PACKAGE_MANAGER" = "cave" ]; then comment "new and old versions of conffiles, stored by emerge" ignore "._cfg*" -- 2.39.5