Skip to content

Commit 29a5e34

Browse files
committed
update updater
1 parent 1361098 commit 29a5e34

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

tools/update.sh

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/bin/sh
2-
# shellcheck disable=SC2181
3-
42
# https://github.com/nakamochi/sysupdates
53
# pull changes from a remote git repo and run the "apply" script.
64
# commits are expected to be signed by gpg keys with a sufficient
@@ -35,17 +33,18 @@ date > "$LOGFILE"
3533

3634
# fetch updates from remote
3735
cd "$REPODIR" || exit 1
38-
{
39-
echo "Fetching updates from $REMOTE_URL, branch $BRANCH"
40-
git remote set-url origin "$REMOTE_URL"
41-
git fetch origin # in case the refspec is unknown locally yet
42-
git reset --hard HEAD # remove local changes
43-
git clean -fd # force-delete untracked files
44-
git checkout "$BRANCH"
45-
git pull --verify-signatures
46-
} >> "$LOGFILE" 2>&1
47-
if [ $? -ne 0 ]; then
48-
echo "ERROR: git pull failed"
36+
if ! {
37+
echo "Fetching updates from $REMOTE_URL, branch $BRANCH" &&
38+
git remote set-url origin "$REMOTE_URL" &&
39+
git fetch origin && # in case the refspec is unknown locally yet
40+
git reset --hard HEAD && # remove local changes
41+
git clean -fd && # force-delete untracked files
42+
git checkout "$BRANCH" &&
43+
git pull --rebase --verify-signatures &&
44+
git submodule sync --recursive &&
45+
git submodule update --init --recursive
46+
} >> "$LOGFILE" 2>&1 ; then
47+
echo "ERROR: repository update failed"
4948
cat "$LOGFILE"
5049
exit 1
5150
fi
@@ -57,4 +56,16 @@ if ! ./apply.sh >> "$LOGFILE" 2>&1; then
5756
echo "ERROR: apply failed"
5857
cat "$LOGFILE"
5958
exit 1
59+
else
60+
# read commit from $REPODIR even if apply.sh changed CWD; write atomically and log failures
61+
if hash="$(git -C "$REPODIR" rev-parse --short=12 HEAD 2>>"$LOGFILE")"; then
62+
tmp=/etc/sysupdates-applied.$$
63+
printf '%s\n' "$hash" > "$tmp" &&
64+
chmod 0644 "$tmp" &&
65+
mv -f "$tmp" /etc/sysupdates-applied
66+
else
67+
echo "ERROR: unable to determine current git commit" >> "$LOGFILE"
68+
cat "$LOGFILE"
69+
exit 1
70+
fi
6071
fi

0 commit comments

Comments
 (0)