Сравнить коммиты
6 Коммитов
8dc558a6d5
...
395263ee66
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 395263ee66 | |||
| bdc4ff67e7 | |||
| 1d078a30e0 | |||
| 0d8502bfac | |||
| a44254bcc9 | |||
| dcf9aaee84 |
107
openwrtbuilder
107
openwrtbuilder
@@ -7,6 +7,7 @@
|
|||||||
# Set default release
|
# Set default release
|
||||||
: "${RELEASE:="23.05.5"}"
|
: "${RELEASE:="23.05.5"}"
|
||||||
|
|
||||||
|
# @internal
|
||||||
print_help() {
|
print_help() {
|
||||||
debug "${FUNCNAME[0]}"
|
debug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
@@ -46,6 +47,7 @@ print_help() {
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @internal
|
||||||
init() {
|
init() {
|
||||||
debug "${FUNCNAME[0]}"
|
debug "${FUNCNAME[0]}"
|
||||||
declare -g ID RPM_MGR SCRIPT_DIR DL_TOOL
|
declare -g ID RPM_MGR SCRIPT_DIR DL_TOOL
|
||||||
@@ -83,19 +85,18 @@ init() {
|
|||||||
raspbian) ID="debian" ;;
|
raspbian) ID="debian" ;;
|
||||||
*)
|
*)
|
||||||
echo "Autodetecting distro, this may be unreliable"
|
echo "Autodetecting distro, this may be unreliable"
|
||||||
if command -v dnf &>/dev/null; then
|
for cmd in dnf yum apt pacman; do
|
||||||
ID="fedora"
|
if command -v "$cmd" &>/dev/null; then
|
||||||
RPM_MGR="dnf"
|
case "$cmd" in
|
||||||
elif command -v yum &>/dev/null; then
|
dnf) ID="fedora"; RPM_MGR="dnf" ;;
|
||||||
ID="centos"
|
yum) ID="centos"; RPM_MGR="yum" ;;
|
||||||
RPM_MGR="yum"
|
apt) ID="ubuntu" ;;
|
||||||
elif command -v apt &>/dev/null; then
|
pacman) ID="arch" ;;
|
||||||
ID="ubuntu"
|
esac
|
||||||
elif command -v pacman &>/dev/null; then
|
break
|
||||||
ID="arch"
|
fi
|
||||||
else
|
done
|
||||||
return 1
|
[[ -z $ID ]] && return 1
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -119,6 +120,7 @@ init() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description Arguments
|
||||||
parse_input() {
|
parse_input() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
debug "${FUNCNAME[0]}" "$*"
|
||||||
declare -ga PROFILES
|
declare -ga PROFILES
|
||||||
@@ -143,10 +145,7 @@ parse_input() {
|
|||||||
--verbose) VERBOSE=1 ;;
|
--verbose) VERBOSE=1 ;;
|
||||||
--debug|-d) echo "Debugging on"; DEBUG=1 ;;
|
--debug|-d) echo "Debugging on"; DEBUG=1 ;;
|
||||||
--help|-h) print_help; exit 0 ;;
|
--help|-h) print_help; exit 0 ;;
|
||||||
--)
|
--) shift; break ;;
|
||||||
shift
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
@@ -156,6 +155,7 @@ parse_input() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description Install build dependencies on major distros
|
||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
debug "${FUNCNAME[0]}"
|
debug "${FUNCNAME[0]}"
|
||||||
local -a pkg_list
|
local -a pkg_list
|
||||||
@@ -319,6 +319,7 @@ install_dependencies() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description Acquires the OpenWRT Image Builder
|
||||||
get_imagebuilder() {
|
get_imagebuilder() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
debug "${FUNCNAME[0]}" "$*"
|
||||||
local -a url_file_pairs=("$@")
|
local -a url_file_pairs=("$@")
|
||||||
@@ -461,6 +462,9 @@ ssh_upgrade() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description Builds OpenWRT from source code using the the default buildbot as base
|
||||||
|
# This enables the use of kernel config options in profiles
|
||||||
|
# @arg $1 string .config seed URL
|
||||||
from_source() {
|
from_source() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
debug "${FUNCNAME[0]}" "$*"
|
||||||
local seed_url="$1"
|
local seed_url="$1"
|
||||||
@@ -519,16 +523,16 @@ from_source() {
|
|||||||
|
|
||||||
# Enter worktree
|
# Enter worktree
|
||||||
execute pushd "$WORKTREE_DIR" || return 1
|
execute pushd "$WORKTREE_DIR" || return 1
|
||||||
|
|
||||||
|
# Cleanup build environment
|
||||||
|
((VERBOSE)) && make_opts+=("V=s")
|
||||||
|
execute make "${make_opts[@]}" "-j1" distclean # TODO 'dirclean' has a bug that triggers menuconfig
|
||||||
|
|
||||||
# Update package feed
|
# Update package feed
|
||||||
./scripts/feeds update -i -f &&
|
./scripts/feeds update -i -f &&
|
||||||
./scripts/feeds update -a -f &&
|
./scripts/feeds update -a -f &&
|
||||||
./scripts/feeds install -a -f
|
./scripts/feeds install -a -f
|
||||||
|
|
||||||
# Cleanup build environment
|
|
||||||
((VERBOSE)) && make_opts+=("V=s")
|
|
||||||
execute make "${make_opts[@]}" "-j1" distclean # TODO 'dirclean' has a bug that triggers menuconfig
|
|
||||||
|
|
||||||
# Grab the release seed config
|
# Grab the release seed config
|
||||||
if ! execute "$DL_TOOL" "-o" "$seed_file" "$seed_url"; then
|
if ! execute "$DL_TOOL" "-o" "$seed_file" "$seed_url"; then
|
||||||
echo "Could not obtain $seed_file from $seed_url"
|
echo "Could not obtain $seed_file from $seed_url"
|
||||||
@@ -597,7 +601,7 @@ from_source() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
popd || return 1
|
execute popd || return 1
|
||||||
|
|
||||||
# Symlink output images to root of BIN_DIR (match Image Builder)
|
# Symlink output images to root of BIN_DIR (match Image Builder)
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
@@ -609,7 +613,34 @@ from_source() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generic helpers
|
# @description Backs up a file to a chosen directory using its timestamp
|
||||||
|
# @arg $1 string File to backup
|
||||||
|
# @arg $2 string Directory to backup to
|
||||||
|
backup() {
|
||||||
|
debug "${FUNCNAME[0]}" "$*"
|
||||||
|
local file="$1" dir="$2"
|
||||||
|
local creation_date base_name backup_file
|
||||||
|
|
||||||
|
[[ -f $file ]] || { debug "File not found: $file"; return 1; }
|
||||||
|
[[ -d $dir ]] || execute mkdir -p "$dir" || { debug "Failed to create directory: $dir"; return 1; }
|
||||||
|
|
||||||
|
if creation_date=$(stat -c %w "$file" 2>/dev/null || stat -c %y "$file" 2>/dev/null) && \
|
||||||
|
[[ $creation_date != "-" && -n $creation_date ]] && \
|
||||||
|
creation_date=$(date -d "$creation_date" +%y%m%d%H%M 2>/dev/null); then
|
||||||
|
debug "Creation date: $creation_date"
|
||||||
|
else
|
||||||
|
creation_date="unknown"
|
||||||
|
debug "Unable to determine creation date, using 'unknown'"
|
||||||
|
fi
|
||||||
|
|
||||||
|
base_name="${file##*/}"
|
||||||
|
backup_file="$dir/$creation_date-$base_name"
|
||||||
|
|
||||||
|
[[ -f $backup_file ]] || execute cp --archive "$file" "$backup_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# @section Helper functions
|
||||||
|
# @internal
|
||||||
debug() { ((DEBUG)) && echo "Debug: $*"; }
|
debug() { ((DEBUG)) && echo "Debug: $*"; }
|
||||||
ask_ok() {
|
ask_ok() {
|
||||||
((YES)) && return
|
((YES)) && return
|
||||||
@@ -619,7 +650,6 @@ ask_ok() {
|
|||||||
[[ "$r" =~ ^(yes|y)$ ]]
|
[[ "$r" =~ ^(yes|y)$ ]]
|
||||||
}
|
}
|
||||||
extract() {
|
extract() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
|
||||||
local archive="$1"
|
local archive="$1"
|
||||||
local out_dir="$2"
|
local out_dir="$2"
|
||||||
if ! execute tar -axf "$archive" -C "$out_dir" --strip-components 1; then
|
if ! execute tar -axf "$archive" -C "$out_dir" --strip-components 1; then
|
||||||
@@ -627,32 +657,15 @@ extract() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
backup_image() {
|
|
||||||
debug "${FUNCNAME[0]} $*"
|
|
||||||
local file="$1" dir="$2" count=1
|
|
||||||
[[ -f $file ]] || return 1
|
|
||||||
local creation_date
|
|
||||||
creation_date=$(stat -c %w "$file" 2>/dev/null || stat -c %y "$file" | cut -d' ' -f1)
|
|
||||||
creation_date=${creation_date:-unknown} # Default to "unknown" if no creation date
|
|
||||||
[[ "$creation_date" == "-" ]] && creation_date="unknown"
|
|
||||||
local base_name; base_name=$(basename "$file")
|
|
||||||
execute mkdir -p "$dir"
|
|
||||||
while [[ -e "$dir/$creation_date-$base_name.bk.$count" ]]; do ((count++)); done
|
|
||||||
execute mv "$file" "$dir/$creation_date-$base_name.bk.$count"
|
|
||||||
}
|
|
||||||
verify() {
|
verify() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
local file_to_check="$1" sum_file="$2"
|
||||||
local file_to_check="$1"
|
|
||||||
local sumfile="$2"
|
|
||||||
local checksum
|
local checksum
|
||||||
|
|
||||||
command -v sha256sum &>/dev/null || return 1
|
command -v sha256sum &>/dev/null || return 1
|
||||||
[[ -f $sumfile && -f $file_to_check ]] || return 1
|
[[ -f $sum_file && -f $file_to_check ]] || return 1
|
||||||
checksum=$(grep "${file_to_check##*/}" "$sumfile" | cut -f1 -d' ')
|
checksum=$(grep "${file_to_check##*/}" "$sum_file" | cut -f1 -d' ')
|
||||||
echo -n "$checksum $file_to_check" | sha256sum --check --status
|
echo -n "$checksum $file_to_check" | sha256sum --check --status
|
||||||
}
|
}
|
||||||
load() {
|
load() {
|
||||||
debug "${FUNCNAME[0]}" "$*"
|
|
||||||
local source_file="$1"
|
local source_file="$1"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
[[ -f $source_file ]] && source "$source_file"
|
[[ -f $source_file ]] && source "$source_file"
|
||||||
@@ -665,6 +678,8 @@ execute() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# @description The openwrtbuilder main function
|
||||||
|
# @internal
|
||||||
main() {
|
main() {
|
||||||
debug "${FUNCNAME[0]}"
|
debug "${FUNCNAME[0]}"
|
||||||
|
|
||||||
@@ -749,12 +764,12 @@ main() {
|
|||||||
local seed_url="$url_prefix/config.buildinfo"
|
local seed_url="$url_prefix/config.buildinfo"
|
||||||
|
|
||||||
if ((FROM_SOURCE)); then
|
if ((FROM_SOURCE)); then
|
||||||
declare -g SYSUPGRADEIMGGZ="$BIN_DIR/targets/$img_fname-sysupgrade.img.gz"
|
declare -g SYSUPGRADEIMGGZ="$BIN_DIR/targets/$TARGET/$img_fname-sysupgrade.img.gz"
|
||||||
else
|
else
|
||||||
declare -g SYSUPGRADEIMGGZ="$BUILD_DIR/$img_fname-sysupgrade.img.gz"
|
declare -g SYSUPGRADEIMGGZ="$BUILD_DIR/$img_fname-sysupgrade.img.gz"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
backup_image "$SYSUPGRADEIMGGZ" "$BACKUP_DIR/$profile/$RELEASE"
|
backup "$SYSUPGRADEIMGGZ" "$BACKUP_DIR/$profile/$RELEASE"
|
||||||
|
|
||||||
if ((RESET)); then
|
if ((RESET)); then
|
||||||
if ((FROM_SOURCE)); then
|
if ((FROM_SOURCE)); then
|
||||||
|
|||||||
1
profiles
1
profiles
@@ -18,6 +18,7 @@ declare -Ag r4s=(
|
|||||||
kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \
|
kmod-fs-btrfs btrfs-progs block-mount smcroute avahi-daemon \
|
||||||
curl ethtool ca-bundle"
|
curl ethtool ca-bundle"
|
||||||
[config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
|
[config]="CONFIG_KERNEL_BTRFS_FS_POSIX_ACL=y CONFIG_BTRFS_PROGS_ZSTD=y \
|
||||||
|
CONFIG_TARGET_ROOTFS_PARTSIZE=512 CONFIG_TARGET_KERNEL_PARTSIZE=32 \
|
||||||
CONFIG_BUILDBOT=n"
|
CONFIG_BUILDBOT=n"
|
||||||
[files]="/mnt/backup"
|
[files]="/mnt/backup"
|
||||||
)
|
)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user