Normalize release commit-ish I

This commit is contained in:
2023-06-02 09:50:25 -04:00
parent 0e4496d2d4
commit ed198150b7
2 changed files with 46 additions and 28 deletions

View File

@@ -65,8 +65,8 @@ init() {
if [[ -e "/etc/os-release" ]]; then if [[ -e "/etc/os-release" ]]; then
source "/etc/os-release" source "/etc/os-release"
else else
err "/etc/os-release not found" echo "/etc/os-release not found"
err "Your OS is unsupported" echo "Your OS is unsupported"
printHelp printHelp
exit 1 exit 1
fi fi
@@ -364,7 +364,7 @@ getImageBuilder() {
declare url="$1" declare url="$1"
if [[ -f "$IB_ARCHIVE" ]]; then if [[ -f "$IB_ARCHIVE" ]]; then
if askOK "$IB_ARCHIVE exists. Re-download?"; then if askOk "$IB_ARCHIVE exists. Re-download?"; then
rm -f "$IB_ARCHIVE" rm -f "$IB_ARCHIVE"
else else
return 0 return 0
@@ -543,45 +543,40 @@ fromSource() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"
declare src_url="https://github.com/openwrt/openwrt.git" declare src_url="https://github.com/openwrt/openwrt.git"
declare seed_file="$SOURCEDIR/.config" declare seed_file="$GITWORKTREEDIR/.config"
declare pkg kopt opt commit seed_file wt_cmd declare pkg kopt opt commit seed_file wt_cmd
declare -a make_opts config_opts declare -a make_opts config_opts
echo "Building from source is under development" echo "Building from source is under development"
# Update source code # Update source code
if [[ ! -d "$GITDIR" ]]; then if [[ ! -d "$GITSRCDIR" ]]; then
mkdir -p "$GITDIR" mkdir -p "$GITSRCDIR"
git clone "$src_url" "$GITDIR" git clone "$src_url" "$GITSRCDIR"
fi fi
git -C "$GITDIR" pull git -C "$GITSRCDIR" pull
wt_cmd=(git -C "$GITDIR" wt_cmd=(git -C "$GITSRCDIR"
worktree add worktree add
--force --force
--detach --detach
"$SOURCEDIR") "$GITWORKTREEDIR")
if [[ $RELEASE == "snapshot" ]]; then if [[ $RELEASE == "snapshot" ]]; then
execute "${wt_cmd[@]}" master execute "${wt_cmd[@]}" master
elif [[ $RELEASE == openwrt-*.* ]]; then
execute "${wt_cmd[@]}" "origin/$RELEASE"
else else
# Split version into components execute "${wt_cmd[@]}" "origin/$RELEASE"
IFS="." read -ra version <<< "$RELEASE"
# Only use major/minor release for branch
execute "${wt_cmd[@]}" "origin/openwrt-${version[0]}.${version[1]}"
fi fi
# Print commit information # Print commit information
commit=$(git -C "$SOURCEDIR" rev-parse HEAD) commit=$(git -C "$GITWORKTREEDIR" rev-parse HEAD)
echo "Current commit hash: $commit" echo "Current commit hash: $commit"
(( DEBUG )) && git -C "$SOURCEDIR" log -1 (( DEBUG )) && git -C "$GITWORKTREEDIR" log -1
(( DEBUG )) && git -C "$SOURCEDIR" describe (( DEBUG )) && git -C "$GITWORKTREEDIR" describe
# Enter worktree # Enter worktree
pushd "$SOURCEDIR" || return 1 pushd "$GITWORKTREEDIR" || return 1
# Update package feed # Update package feed
./scripts/feeds update -i -f && ./scripts/feeds update -i -f &&
@@ -753,22 +748,44 @@ main() {
# Store profile settings in P_ARR # Store profile settings in P_ARR
declare -gn P_ARR="$profile" declare -gn P_ARR="$profile"
# release precedence: user input>profile>env>hardcode # Release precedence: user input>profile>env>hardcode
declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}" declare -g RELEASE="${USER_RELEASE:=${P_ARR[release]:=$RELEASE}}"
# Normalize release commit-ish
if (( FROM_SOURCE )); then
debug "Passing '$RELEASE' commit-ish to git worktree"
else
case "$RELEASE" in
[0-9][0-9].[0-9][0-9].*) # semantic versioning (default)
;;
v[0-9][0-9].[0-9][0-9].*) # tags
RELEASE="${RELEASE#v}"
;;
snapshot|latest|main|master)
RELEASE="snapshot"
;;
*)
echo "Error: Invalid release version format"
echo "Use semantic version, tag, or 'snapshot'"
exit 1
;;
esac
fi
declare -g BUILDDIR="$BUILDROOT/src/$profile/$RELEASE" declare -g BUILDDIR="$BUILDROOT/src/$profile/$RELEASE"
declare -g BINDIR="$BUILDROOT/bin/$profile/$RELEASE" declare -g BINDIR="$BUILDROOT/bin/$profile/$RELEASE"
declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}" declare -g FILESYSTEM="${P_ARR[filesystem]:="squashfs"}"
declare -g TARGET="${P_ARR[target]}" declare -g TARGET="${P_ARR[target]}"
declare -g PROFILE="${P_ARR[profile]}" declare -g PROFILE="${P_ARR[profile]}"
declare -g PACKAGES="${P_ARR[packages]:-}" declare -g PACKAGES="${P_ARR[packages]:-}"
declare -g SOURCEDIR="$BUILDROOT/src/$profile/$RELEASE-src" declare -g GITSRCDIR="$BUILDROOT/src/openwrt"
declare -g GITDIR="$BUILDROOT/src/openwrt" declare -g GITWORKTREEDIR="$BUILDROOT/src/$profile/$RELEASE-src"
if (( RESET )); then if (( RESET )); then
if (( FROM_SOURCE )); then if (( FROM_SOURCE )); then
[[ -d $SOURCEDIR ]] && askOk "Remove $SOURCEDIR?" [[ -d $GITWORKTREEDIR ]] && askOk "Remove $GITWORKTREEDIR?"
execute git worktree remove --force "$SOURCEDIR" execute git worktree remove --force "$GITWORKTREEDIR"
execute rm -rf "$SOURCEDIR" execute rm -rf "$GITWORKTREEDIR"
elif [[ -d $BUILDDIR ]] && askOk "Remove $BUILDDIR?"; then elif [[ -d $BUILDDIR ]] && askOk "Remove $BUILDDIR?"; then
execute rm -rf "$BUILDDIR" execute rm -rf "$BUILDDIR"
fi fi
@@ -805,8 +822,8 @@ main() {
ALIAS (\$profile, \$P_ARR -- should match)=$profile, ${!P_ARR} ALIAS (\$profile, \$P_ARR -- should match)=$profile, ${!P_ARR}
BUILDROOT=$BUILDROOT BUILDROOT=$BUILDROOT
BUILDDIR=$BUILDDIR BUILDDIR=$BUILDDIR
GITDIR=$GITDIR GITSRCDIR=$GITSRCDIR
SOURCEDIR=$SOURCEDIR GITWORKTREEDIR=$GITWORKTREEDIR
BINDIR=$BINDIR BINDIR=$BINDIR
TARGET=$TARGET TARGET=$TARGET
PROFILE=$PROFILE PROFILE=$PROFILE

View File

@@ -121,6 +121,7 @@ r4s['packages']="\
ethtool \ ethtool \
ca-bundle \ ca-bundle \
-libustream-wolfssl" -libustream-wolfssl"
# The following are source mode only
r4s['kopts']="\ r4s['kopts']="\
CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \ CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y \
CONFIG_BTRFS_PROGS_ZSTD=y \ CONFIG_BTRFS_PROGS_ZSTD=y \