Improve execute()

This commit is contained in:
2024-05-21 17:45:25 -04:00
parent 8bb770bc3e
commit 8bea538b1f

View File

@@ -550,25 +550,19 @@ fromSource() {
declare src_url="https://github.com/openwrt/openwrt.git" declare src_url="https://github.com/openwrt/openwrt.git"
declare seed_file="$GITWORKTREEDIR/.config" declare seed_file="$GITWORKTREEDIR/.config"
declare pkg config commit seed_file wt_cmd wt_commit description declare pkg config commit seed_file wt_commit description
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 "$GITSRCDIR" ]]; then if [[ ! -d "$GITSRCDIR" ]]; then
mkdir -p "$GITSRCDIR" execute mkdir -p "$GITSRCDIR"
git clone "$src_url" "$GITSRCDIR" execute git clone "$src_url" "$GITSRCDIR"
fi fi
git -C "$GITSRCDIR" pull git -C "$GITSRCDIR" pull
wt_cmd=(git -C "$GITSRCDIR"
worktree add
--force
--detach
"$GITWORKTREEDIR")
# Generate commitish for git worktree # Generate commitish for git worktree
case "$RELEASE" in case "$RELEASE" in
snapshot) snapshot)
@@ -589,9 +583,12 @@ fromSource() {
;; ;;
esac esac
[[ -d "$GITWORKTREEDIR" ]] && execute rm -rf "$GITWORKTREEDIR" # overwrite worktree changes if [[ -d "$GITWORKTREEDIR" ]]; then
execute git -C "$GITWORKTREEDIR" checkout "$wt_commit"
execute "${wt_cmd[@]}" "$wt_commit" execute git -C "$GITWORKTREEDIR" pull
else
execute git -C "$GITSRCDIR" worktree add --force --detach "$GITWORKTREEDIR" "$wt_commit"
fi
# Print commit information # Print commit information
commit=$(git -C "$GITWORKTREEDIR" rev-parse HEAD) commit=$(git -C "$GITWORKTREEDIR" rev-parse HEAD)
@@ -608,7 +605,7 @@ fromSource() {
fi fi
# Enter worktree # Enter worktree
pushd "$GITWORKTREEDIR" || return 1 execute pushd "$GITWORKTREEDIR" || return 1
# Update package feed # Update package feed
./scripts/feeds update -i -f && ./scripts/feeds update -i -f &&
@@ -639,7 +636,7 @@ fromSource() {
done done
# Only compile selected fs # Only compile selected fs
sed -i '/CONFIG_TARGET_ROOTFS_/d' "$seed_file" execute sed -i '/CONFIG_TARGET_ROOTFS_/d' "$seed_file"
config_opts+=("CONFIG_TARGET_PER_DEVICE_ROOTFS=n") config_opts+=("CONFIG_TARGET_PER_DEVICE_ROOTFS=n")
if [[ $FILESYSTEM == "squashfs" ]]; then if [[ $FILESYSTEM == "squashfs" ]]; then
config_opts+=("CONFIG_TARGET_ROOTFS_EXT4FS=n") config_opts+=("CONFIG_TARGET_ROOTFS_EXT4FS=n")
@@ -650,7 +647,7 @@ fromSource() {
fi fi
# Only compile selected target image # Only compile selected target image
sed -i '/CONFIG_TARGET_DEVICE_/d' "$seed_file" execute sed -i '/CONFIG_TARGET_DEVICE_/d' "$seed_file"
config_opts+=("CONFIG_TARGET_MULTI_PROFILE=n") config_opts+=("CONFIG_TARGET_MULTI_PROFILE=n")
config_opts+=("CONFIG_TARGET_PROFILE=DEVICE_$DEVICE") config_opts+=("CONFIG_TARGET_PROFILE=DEVICE_$DEVICE")
config_opts+=("CONFIG_TARGET_${TARGET//\//_}_DEVICE_$DEVICE=y") config_opts+=("CONFIG_TARGET_${TARGET//\//_}_DEVICE_$DEVICE=y")
@@ -731,9 +728,11 @@ load() {
[[ -f $source_file ]] && source "$source_file" [[ -f $source_file ]] && source "$source_file"
} }
execute() { execute() {
declare cmd="$*" if debug "$*"; then
debug "$cmd" || cmd+=" &>/dev/null" "$@"
eval "${cmd[*]}" else
"$@" &>/dev/null
fi
} }