Last active
November 9, 2023 13:18
-
-
Save jow-/af887fbba30b8503e4059472c2e0ab65 to your computer and use it in GitHub Desktop.
Update OpenWrt Git packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
MAKEFILE=$1 | |
COMMIT=${2:-HEAD} | |
TOPDIR=$3 | |
MAKE=$(which gmake) || MAKE=$(which make) | |
FIND=$(which gfind) || FIND=$(which find) | |
[ -x "$MAKE" ] || { | |
echo "Unable to locate `make` executable" >&2 | |
exit 1 | |
} | |
[ -x "$FIND" ] || { | |
echo "Unable to locate `find` executable" >&2 | |
exit 1 | |
} | |
[ -e "$MAKEFILE" ] || { | |
MAKEFILE=$("$FIND" "${TOPDIR:-.}/package/" -type f -path "*/$MAKEFILE/Makefile" | head -n1) | |
} | |
[ -f "$MAKEFILE" ] || { | |
echo "Usage: $0 <path/to/Makefile> [target commit] [path/to/buildroot/topdir]" | |
exit 1 | |
} | |
grep -sq BuildPackage "$MAKEFILE" || { | |
echo "The file '$MAKEFILE' does not appear to be an OpenWrt package Makefile." >&2 | |
exit 1 | |
} | |
[ -n "$TOPDIR" ] || { | |
TOPDIR=$(cd "$(dirname "$MAKEFILE")"; pwd) | |
while [ "$TOPDIR" != "/" ]; do | |
TOPDIR=$(dirname "$TOPDIR") | |
[ -f "$TOPDIR/rules.mk" ] && break | |
done | |
[ -f "$TOPDIR/rules.mk" ] || { | |
echo "Unable to determine buildroot directory." >&2 | |
exit 1 | |
} | |
} | |
export TOPDIR | |
eval $( | |
"$MAKE" --no-print-directory -C "$(dirname "$MAKEFILE")" \ | |
var.PKG_NAME \ | |
var.PKG_RELEASE \ | |
var.PKG_SOURCE_PROTO \ | |
var.PKG_SOURCE_URL \ | |
var.PKG_SOURCE_DATE \ | |
var.PKG_SOURCE_VERSION \ | |
var.PKG_MIRROR_HASH | |
) | |
case "$PKG_SOURCE_PROTO:$PKG_SOURCE_URL" in | |
git:http://*|git:https://*|git:git://*|git:file:*) | |
: | |
;; | |
*) | |
echo "Unsupported combination of source protocol ('$PKG_SOURCE_PROTO') and url ('$PKG_SOURCE_URL')." >&2 | |
exit 1 | |
;; | |
esac | |
TEMP_GIT_DIR= | |
for signal in INT TERM EXIT; do | |
trap ' | |
[ -d "$TEMP_GIT_DIR" ] && rm -rf "$TEMP_GIT_DIR"; | |
git -C "$(dirname "$MAKEFILE")" checkout --quiet "$(basename "$MAKEFILE")" | |
' $signal | |
done | |
TEMP_GIT_DIR=$(mktemp -d) || { | |
echo "Unable to create temporary Git directory." >&2 | |
exit 1 | |
} | |
git clone --bare "$PKG_SOURCE_URL" "$TEMP_GIT_DIR" || { | |
echo "Unable to clone Git repository '$PKG_SOURCE_URL'." >&2 | |
exit 1 | |
} | |
GIT_LOG="$(git -C "$TEMP_GIT_DIR" log \ | |
--reverse --no-merges \ | |
--format="%h %s" \ | |
"$PKG_SOURCE_VERSION..$COMMIT" \ | |
)" || { | |
echo "Unable to determine changes from commit '$PKG_SOURCE_VERSION' to '$COMMIT'." >&2 | |
exit 1 | |
} | |
GIT_DATE_COMMIT=$(git -C "$TEMP_GIT_DIR" log \ | |
-1 --format='%cd %H' \ | |
--date='format:%Y-%m-%d' \ | |
"$COMMIT" \ | |
) || { | |
echo "Unable to determine target commit ID and date." >&2 | |
exit 1 | |
} | |
sed -i -r \ | |
-e "/PKG_SOURCE_VERSION/s#\<$PKG_SOURCE_VERSION\>#${GIT_DATE_COMMIT#* }#" \ | |
-e "/PKG_SOURCE_DATE/s#\<$PKG_SOURCE_DATE\>#${GIT_DATE_COMMIT% *}#" \ | |
"$MAKEFILE" | |
if [ -n "$PKG_RELEASE" ] && [ "$PKG_RELEASE" != "1" ]; then | |
sed -i -r \ | |
-e "/PKG_RELEASE/s#\<$PKG_RELEASE\>#1#" \ | |
"$MAKEFILE" | |
fi | |
eval $( | |
"$MAKE" --no-print-directory -C "$(dirname "$MAKEFILE")" \ | |
var.PKG_SOURCE | |
) | |
"$MAKE" -C "$(dirname "$MAKEFILE")" download || { | |
echo "Unable to download and pack updated Git sources." >&2 | |
exit 1 | |
} | |
DL_HASH=$(sha256sum "$TOPDIR/dl/$PKG_SOURCE") || { | |
echo "Unable to determine archive checksum." >&2 | |
exit 1 | |
} | |
sed -i -r \ | |
-e "/PKG_MIRROR_HASH/s#\<$PKG_MIRROR_HASH\>#${DL_HASH%% *}#" \ | |
"$MAKEFILE" | |
git -C "$(dirname "$MAKEFILE")" commit \ | |
--signoff --no-edit \ | |
--message "$PKG_NAME: update to Git $COMMIT (${GIT_DATE_COMMIT% *})" \ | |
--message "$GIT_LOG" \ | |
"$(basename "$MAKEFILE")" | |
"$MAKE" --no-print-directory -C "$(dirname "$MAKEFILE")" check || { | |
echo "WARNING: Package check failed for updated Makefile!" | |
exit 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jow@j7:~/devel/openwrt.git$ ./update-to-git-head.sh ucode | |
Cloning into bare repository '/tmp/tmp.ZCdTQSy6nm'... | |
remote: Enumerating objects: 4699, done. | |
remote: Counting objects: 100% (1329/1329), done. | |
remote: Compressing objects: 100% (388/388), done. | |
remote: Total 4699 (delta 947), reused 1247 (delta 923), pack-reused 3370 | |
Receiving objects: 100% (4699/4699), 2.97 MiB | 15.46 MiB/s, done. | |
Resolving deltas: 100% (3052/3052), done. | |
gmake: Entering directory '/home/jow/devel/openwrt.git/package/utils/ucode' | |
mkdir -p /home/jow/devel/openwrt.git/dl | |
SHELL= flock /home/jow/devel/openwrt.git/tmp/.ucode-2023-11-07-a6e75e02.tar.xz.flock -c ' /home/jow/devel/openwrt.git/scripts/download.pl "/home/jow/devel/openwrt.git/dl" "ucode-2023-11-07-a6e75e02.tar.xz" "f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe" "" || ( /home/jow/devel/openwrt.git/scripts/dl_github_archive.py --dl-dir="/home/jow/devel/openwrt.git/dl" --url="https://github.com/jow-/ucode.git" --version="a6e75e02528e36f3610a7f0073453018336def2e" --subdir="ucode-2023-11-07-a6e75e02" --source="ucode-2023-11-07-a6e75e02.tar.xz" --hash="f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe" --submodules || ( echo "Checking out files from the git repository..."; mkdir -p /home/jow/devel/openwrt.git/tmp/dl && cd /home/jow/devel/openwrt.git/tmp/dl && rm -rf ucode-2023-11-07-a6e75e02 && [ \! -d ucode-2023-11-07-a6e75e02 ] && git clone https://github.com/jow-/ucode.git ucode-2023-11-07-a6e75e02 && (cd ucode-2023-11-07-a6e75e02 && git checkout a6e75e02528e36f3610a7f0073453018336def2e && git submodule update --init --recursive -- ) && echo "Packing checkout..." && export TAR_TIMESTAMP=`cd ucode-2023-11-07-a6e75e02 && git log -1 --format='\''@%ct'\''` && rm -rf ucode-2023-11-07-a6e75e02/.git && tar --numeric-owner --owner=0 --group=0 --mode=a-s --sort=name ${TAR_TIMESTAMP:+--mtime="$TAR_TIMESTAMP"} -c ucode-2023-11-07-a6e75e02 | xz -zc -7e > /home/jow/devel/openwrt.git/tmp/dl/ucode-2023-11-07-a6e75e02.tar.xz && mv /home/jow/devel/openwrt.git/tmp/dl/ucode-2023-11-07-a6e75e02.tar.xz /home/jow/devel/openwrt.git/dl/ && rm -rf ucode-2023-11-07-a6e75e02; ); ) ' | |
Hash of the local file ucode-2023-11-07-a6e75e02.tar.xz does not match (file: e1a0f98ba865ed5911d5db3bfca55a2f1b825992bf5f7c7e324928d9412d7ae2, requested: f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe) - deleting download. | |
ucode-2023-11-07-a6e75e02.tar.xz: Download from https://github.com/jow-/ucode.git failed | |
ucode-2023-11-07-a6e75e02.tar.xz: Wrong hash (probably caused by .gitattributes), expecting f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe, got e1a0f98ba865ed5911d5db3bfca55a2f1b825992bf5f7c7e324928d9412d7ae2 | |
Checking out files from the git repository... | |
Cloning into 'ucode-2023-11-07-a6e75e02'... | |
remote: Enumerating objects: 4699, done. | |
remote: Counting objects: 100% (1329/1329), done. | |
remote: Compressing objects: 100% (388/388), done. | |
remote: Total 4699 (delta 947), reused 1247 (delta 923), pack-reused 3370 | |
Receiving objects: 100% (4699/4699), 2.97 MiB | 10.18 MiB/s, done. | |
Resolving deltas: 100% (3052/3052), done. | |
Note: switching to 'a6e75e02528e36f3610a7f0073453018336def2e'. | |
You are in 'detached HEAD' state. You can look around, make experimental | |
changes and commit them, and you can discard any commits you make in this | |
state without impacting any branches by switching back to a branch. | |
If you want to create a new branch to retain commits you create, you may | |
do so (now or later) by using -c with the switch command. Example: | |
git switch -c <new-branch-name> | |
Or undo this operation with: | |
git switch - | |
Turn off this advice by setting config variable advice.detachedHead to false | |
HEAD is now at a6e75e0 Merge pull request #180 from jow-/uloop-interval-signal-support | |
Packing checkout... | |
gmake: Leaving directory '/home/jow/devel/openwrt.git/package/utils/ucode' | |
[main c730d0f871] ucode: update to Git HEAD (2023-11-07) | |
1 file changed, 3 insertions(+), 3 deletions(-) | |
jow@j7:~/devel/openwrt.git$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jow@j7:~/devel/openwrt.git$ git log -1 -p | |
commit c730d0f8710c8ff653efd2fd00fa71acceea643f (HEAD -> main) | |
Author: Jo-Philipp Wich <[email protected]> | |
Date: Thu Nov 9 12:17:11 2023 +0100 | |
ucode: update to Git HEAD (2023-11-07) | |
0352a33 uloop: support new interval and signal APIs | |
1468cc4 syntax: don't treat `as` and `from` as reserved keywords | |
Signed-off-by: Jo-Philipp Wich <[email protected]> | |
diff --git a/package/utils/ucode/Makefile b/package/utils/ucode/Makefile | |
index b62633492a..067e56e02d 100644 | |
--- a/package/utils/ucode/Makefile | |
+++ b/package/utils/ucode/Makefile | |
@@ -12,9 +12,9 @@ PKG_RELEASE:=1 | |
PKG_SOURCE_PROTO:=git | |
PKG_SOURCE_URL=https://github.com/jow-/ucode.git | |
-PKG_SOURCE_DATE:=2023-11-02 | |
-PKG_SOURCE_VERSION:=cfb24ea4f12131dcefe4f1ede2f51d3d16b88dec | |
-PKG_MIRROR_HASH:=f515a23ab438f92be5788c42b9f614a82e670de2df1c01cd63143cdc77fa24fe | |
+PKG_SOURCE_DATE:=2023-11-07 | |
+PKG_SOURCE_VERSION:=a6e75e02528e36f3610a7f0073453018336def2e | |
+PKG_MIRROR_HASH:=e1a0f98ba865ed5911d5db3bfca55a2f1b825992bf5f7c7e324928d9412d7ae2 | |
PKG_MAINTAINER:=Jo-Philipp Wich <[email protected]> | |
PKG_LICENSE:=ISC | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment