Compare commits

...

2 Commits

Author SHA1 Message Date
395263ee66 Update feeds after distclean 2024-12-07 10:02:34 -05:00
bdc4ff67e7 Mke backup filenames human readable 2024-12-06 12:51:31 -05:00

View File

@@ -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
@@ -118,6 +120,7 @@ init() {
fi fi
} }
# @description Arguments
parse_input() { parse_input() {
debug "${FUNCNAME[0]}" "$*" debug "${FUNCNAME[0]}" "$*"
declare -ga PROFILES declare -ga PROFILES
@@ -152,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
@@ -315,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=("$@")
@@ -457,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"
@@ -516,15 +524,15 @@ 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"
@@ -593,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
@@ -605,7 +613,34 @@ from_source() {
return 0 return 0
} }
# 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
@@ -622,21 +657,6 @@ extract() {
return 1 return 1
fi fi
} }
backup() {
debug "BACKUP1"
local file="$1" dir="$2" count=1
local creation_date base_name backup_file
debug "file=$file dir=$dir count=$count"
[[ -f $file ]] || return 1
[[ -d $dir ]] || execute mkdir -p "$dir"
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"
base_name="${file##*/}"
backup_file="$dir/$creation_date-$base_name.bk.$count"
while [[ -e $backup_file ]]; do ((count++)); done
execute mv "$file" "$backup_file"
}
verify() { verify() {
local file_to_check="$1" sum_file="$2" local file_to_check="$1" sum_file="$2"
local checksum local checksum
@@ -658,6 +678,8 @@ execute() {
fi fi
} }
# @description The openwrtbuilder main function
# @internal
main() { main() {
debug "${FUNCNAME[0]}" debug "${FUNCNAME[0]}"