mirror of
https://github.com/DanielLavrushin/b4.git
synced 2026-07-10 00:12:25 +00:00
Enhance installer scripts with user override preservation and improved handling
- Updated _build.sh to skip comment-only lines and collapse multiple blank lines. - Modified install.sh to preserve user-defined bin and data directories during platform auto-detection. - Improved remove.sh to check for already processed config directories using exact matches. - Enhanced sysinfo.sh to save and restore additional configuration variables. - Updated update.sh to allow specifying a target version for updates. - Improved geoip.sh and geosite.sh to handle jq command failures gracefully. - Enhanced wizard.sh to preserve user overrides when loading platform defaults. - Fixed main.sh to correctly pass version and architecture parameters to the update action.
This commit is contained in:
parent
e0d709e31a
commit
b4cebb1070
10 changed files with 105 additions and 461 deletions
484
install.sh
484
install.sh
File diff suppressed because it is too large
Load diff
|
|
@ -25,9 +25,13 @@ append() {
|
|||
cat "$file" >>"$OUTPUT"
|
||||
else
|
||||
echo "" >>"$OUTPUT"
|
||||
echo "# ======== ${basename} ========" >>"$OUTPUT"
|
||||
# Skip shebang line, strip leading blank lines
|
||||
tail -n +2 "$file" | sed '/./,$!d' >>"$OUTPUT"
|
||||
# Skip shebang, strip comment-only lines (outside heredocs), collapse leading blanks
|
||||
tail -n +2 "$file" | awk '
|
||||
/<<[[:space:]]*EOF/ || /<<[[:space:]]*'\''EOF'\''/ { heredoc=1 }
|
||||
heredoc { print; if (/^EOF$/) heredoc=0; next }
|
||||
/^[[:space:]]*#/ { next }
|
||||
{ print }
|
||||
' | sed '/./,$!d' >>"$OUTPUT"
|
||||
fi
|
||||
|
||||
echo "" >>"$OUTPUT"
|
||||
|
|
@ -79,5 +83,8 @@ done
|
|||
# 7. Main entry point
|
||||
append "${SCRIPT_DIR}/main.sh"
|
||||
|
||||
# Collapse multiple consecutive blank lines
|
||||
sed -i '/^$/N;/^\n$/d' "$OUTPUT"
|
||||
|
||||
chmod +x "$OUTPUT"
|
||||
echo "Built: $OUTPUT ($(wc -l <"$OUTPUT") lines)"
|
||||
|
|
|
|||
|
|
@ -10,8 +10,15 @@ action_install() {
|
|||
# --- Wizard ---
|
||||
if [ "$QUIET_MODE" -eq 1 ]; then
|
||||
WIZARD_MODE="auto"
|
||||
# Preserve user overrides (--bin-dir, --data-dir) before platform defaults
|
||||
_user_bin_dir="$B4_BIN_DIR"
|
||||
_user_data_dir="$B4_DATA_DIR"
|
||||
platform_auto_detect
|
||||
platform_call info
|
||||
# Re-apply user overrides
|
||||
[ -n "$_user_bin_dir" ] && B4_BIN_DIR="$_user_bin_dir"
|
||||
[ -n "$_user_data_dir" ] && B4_DATA_DIR="$_user_data_dir"
|
||||
[ -n "$_user_data_dir" ] && B4_CONFIG_FILE="${_user_data_dir}/b4.json"
|
||||
B4_ARCH="${force_arch:-$(detect_architecture)}"
|
||||
detect_pkg_manager
|
||||
# Enable all default features in quiet mode
|
||||
|
|
@ -174,8 +181,8 @@ _show_web_info() {
|
|||
protocol="http"
|
||||
|
||||
if [ -f "$B4_CONFIG_FILE" ] && command_exists jq; then
|
||||
web_port=$(jq -r '.system.web_server.port // 7000' "$B4_CONFIG_FILE" 2>/dev/null)
|
||||
tls=$(jq -r '.system.web_server.tls_cert // ""' "$B4_CONFIG_FILE" 2>/dev/null)
|
||||
web_port=$(jq -r '.system.web_server.port // 7000' "$B4_CONFIG_FILE" 2>/dev/null) || true
|
||||
tls=$(jq -r '.system.web_server.tls_cert // ""' "$B4_CONFIG_FILE" 2>/dev/null) || true
|
||||
[ -n "$tls" ] && protocol="https"
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,10 @@ _remove_config_dirs() {
|
|||
for cfg_dir in "$B4_DATA_DIR" /etc/b4 /opt/etc/b4 /etc/storage/b4; do
|
||||
[ -z "$cfg_dir" ] && continue
|
||||
[ -d "$cfg_dir" ] || continue
|
||||
# Skip if already checked
|
||||
echo "$checked" | grep -q "$cfg_dir" && continue
|
||||
# Skip if already checked (exact match to avoid substring false positives)
|
||||
case " $checked " in
|
||||
*" $cfg_dir "*) continue ;;
|
||||
esac
|
||||
checked="${checked} ${cfg_dir}"
|
||||
|
||||
# Show remaining contents
|
||||
|
|
|
|||
|
|
@ -34,7 +34,11 @@ action_sysinfo() {
|
|||
_saved_platform="$B4_PLATFORM"
|
||||
_saved_bin_dir="$B4_BIN_DIR"
|
||||
_saved_data_dir="$B4_DATA_DIR"
|
||||
_saved_config_file="$B4_CONFIG_FILE"
|
||||
_saved_service_type="$B4_SERVICE_TYPE"
|
||||
_saved_service_dir="$B4_SERVICE_DIR"
|
||||
_saved_service_name="$B4_SERVICE_NAME"
|
||||
_saved_pkg_manager="$B4_PKG_MANAGER"
|
||||
platform_auto_detect 2>/dev/null || true
|
||||
if [ -n "$B4_PLATFORM" ]; then
|
||||
pname=$(platform_dispatch "$B4_PLATFORM" name 2>/dev/null)
|
||||
|
|
@ -155,10 +159,10 @@ action_sysinfo() {
|
|||
|
||||
# Config-derived info (queue number, worker threads, geodat paths)
|
||||
if [ -n "$cfg_file" ] && command_exists jq; then
|
||||
queue_num=$(jq -r '.system.queue_num // empty' "$cfg_file" 2>/dev/null)
|
||||
workers=$(jq -r '.system.workers // empty' "$cfg_file" 2>/dev/null)
|
||||
geosite=$(jq -r '.system.geo.sitedat_path // empty' "$cfg_file" 2>/dev/null)
|
||||
geoip=$(jq -r '.system.geo.ipdat_path // empty' "$cfg_file" 2>/dev/null)
|
||||
queue_num=$(jq -r '.system.queue_num // empty' "$cfg_file" 2>/dev/null) || true
|
||||
workers=$(jq -r '.system.workers // empty' "$cfg_file" 2>/dev/null) || true
|
||||
geosite=$(jq -r '.system.geo.sitedat_path // empty' "$cfg_file" 2>/dev/null) || true
|
||||
geoip=$(jq -r '.system.geo.ipdat_path // empty' "$cfg_file" 2>/dev/null) || true
|
||||
|
||||
[ -n "$queue_num" ] && [ "$queue_num" != "null" ] && log_detail "Queue number" "$queue_num"
|
||||
[ -n "$workers" ] && [ "$workers" != "null" ] && log_detail "Worker threads" "$workers"
|
||||
|
|
@ -294,7 +298,11 @@ action_sysinfo() {
|
|||
B4_PLATFORM="$_saved_platform"
|
||||
B4_BIN_DIR="$_saved_bin_dir"
|
||||
B4_DATA_DIR="$_saved_data_dir"
|
||||
B4_CONFIG_FILE="$_saved_config_file"
|
||||
B4_SERVICE_TYPE="$_saved_service_type"
|
||||
B4_SERVICE_DIR="$_saved_service_dir"
|
||||
B4_SERVICE_NAME="$_saved_service_name"
|
||||
B4_PKG_MANAGER="$_saved_pkg_manager"
|
||||
}
|
||||
|
||||
_sysinfo_show_storage() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
# Action: Update b4 to latest version
|
||||
|
||||
action_update() {
|
||||
force_arch="$1"
|
||||
target_ver="$1"
|
||||
force_arch="$2"
|
||||
|
||||
check_root
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ action_update() {
|
|||
# Find existing binary
|
||||
existing_bin=""
|
||||
for dir in "$B4_BIN_DIR" /usr/local/bin /usr/bin /usr/sbin /opt/bin /opt/sbin; do
|
||||
[ -z "$dir" ] && continue
|
||||
if [ -f "${dir}/${BINARY_NAME}" ]; then
|
||||
existing_bin="${dir}/${BINARY_NAME}"
|
||||
B4_BIN_DIR="$dir"
|
||||
|
|
@ -32,7 +34,9 @@ action_update() {
|
|||
fi
|
||||
|
||||
# Get current version
|
||||
current_ver=$("$existing_bin" --version 2>&1 | head -1) || current_ver="unknown"
|
||||
_ver_full=$("$existing_bin" --version 2>&1) || _ver_full=""
|
||||
current_ver=$(echo "$_ver_full" | grep -i "version" | head -1)
|
||||
[ -z "$current_ver" ] && current_ver="unknown"
|
||||
log_info "Current: ${current_ver}"
|
||||
|
||||
# Detect arch from existing binary or system
|
||||
|
|
@ -42,10 +46,15 @@ action_update() {
|
|||
B4_ARCH=$(detect_architecture)
|
||||
fi
|
||||
|
||||
# Get latest version
|
||||
log_info "Checking for updates..."
|
||||
latest_ver=$(get_latest_version)
|
||||
log_info "Latest: ${latest_ver}"
|
||||
# Get target version
|
||||
if [ -n "$target_ver" ]; then
|
||||
latest_ver="$target_ver"
|
||||
log_info "Target: ${latest_ver}"
|
||||
else
|
||||
log_info "Checking for updates..."
|
||||
latest_ver=$(get_latest_version)
|
||||
log_info "Latest: ${latest_ver}"
|
||||
fi
|
||||
|
||||
if [ "$current_ver" = "$latest_ver" ] || echo "$current_ver" | grep -q "$latest_ver"; then
|
||||
log_ok "Already up to date"
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ feature_geoip_run() {
|
|||
|
||||
# Check if config already has a geoip path
|
||||
if [ -f "$B4_CONFIG_FILE" ] && command_exists jq; then
|
||||
existing=$(jq -r '.system.geo.ipdat_path // empty' "$B4_CONFIG_FILE" 2>/dev/null)
|
||||
existing=$(jq -r '.system.geo.ipdat_path // empty' "$B4_CONFIG_FILE" 2>/dev/null) || true
|
||||
if [ -n "$existing" ] && [ "$existing" != "null" ]; then
|
||||
save_dir=$(dirname "$existing")
|
||||
log_info "Found existing geoip path: $save_dir"
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ feature_geosite_run() {
|
|||
|
||||
# Check if config already has a geosite path
|
||||
if [ -f "$B4_CONFIG_FILE" ] && command_exists jq; then
|
||||
existing=$(jq -r '.system.geo.sitedat_path // empty' "$B4_CONFIG_FILE" 2>/dev/null)
|
||||
existing=$(jq -r '.system.geo.sitedat_path // empty' "$B4_CONFIG_FILE" 2>/dev/null) || true
|
||||
if [ -n "$existing" ] && [ "$existing" != "null" ]; then
|
||||
save_dir=$(dirname "$existing")
|
||||
log_info "Found existing geosite path: $save_dir"
|
||||
|
|
@ -121,7 +121,7 @@ _geo_remove_file() {
|
|||
for cfg in "$B4_CONFIG_FILE" /etc/b4/b4.json /opt/etc/b4/b4.json; do
|
||||
[ -f "$cfg" ] || continue
|
||||
if command_exists jq; then
|
||||
fpath=$(jq -r ".system.geo.${config_key} // empty" "$cfg" 2>/dev/null)
|
||||
fpath=$(jq -r ".system.geo.${config_key} // empty" "$cfg" 2>/dev/null) || true
|
||||
if [ -n "$fpath" ] && [ -f "$fpath" ]; then
|
||||
log_info "Found ${filename}: ${fpath}"
|
||||
if [ "$QUIET_MODE" -eq 1 ] || confirm "Remove ${filename}?" "y"; then
|
||||
|
|
|
|||
|
|
@ -50,8 +50,13 @@ wizard_auto_detect() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# 2. Load platform defaults
|
||||
# 2. Load platform defaults (preserve user overrides)
|
||||
_user_bin_dir="$B4_BIN_DIR"
|
||||
_user_data_dir="$B4_DATA_DIR"
|
||||
platform_call info
|
||||
[ -n "$_user_bin_dir" ] && B4_BIN_DIR="$_user_bin_dir"
|
||||
[ -n "$_user_data_dir" ] && B4_DATA_DIR="$_user_data_dir"
|
||||
[ -n "$_user_data_dir" ] && B4_CONFIG_FILE="${_user_data_dir}/b4.json"
|
||||
|
||||
# 3. Detect architecture
|
||||
B4_ARCH=$(detect_architecture)
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ main() {
|
|||
case "$ACTION" in
|
||||
install) action_install "$VERSION" "$FORCE_ARCH" ;;
|
||||
remove) action_remove ;;
|
||||
update) action_update "$FORCE_ARCH" ;;
|
||||
update) action_update "$VERSION" "$FORCE_ARCH" ;;
|
||||
sysinfo) action_sysinfo ;;
|
||||
esac
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue