first compiled apps attempt
This commit is contained in:
219
install-compiled.sh
Executable file
219
install-compiled.sh
Executable file
@@ -0,0 +1,219 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Purpose : Compile and install applications from compile.conf
|
||||
|
||||
CONF_FILE="$HOME/.local/share/HamPack/compile.conf"
|
||||
TMP_DIR="/tmp/hampack-build"
|
||||
VERSION_FILE="$HOME/.local/state/HamPack/.installed_versions"
|
||||
|
||||
# Get the installed version of an app
|
||||
get_installed_version() {
|
||||
local app="$1"
|
||||
|
||||
# Try --version flag first
|
||||
if command -v "$app" &> /dev/null; then
|
||||
local ver
|
||||
ver=$("$app" --version 2>&1 | grep -oP '\d+\.\d+[\.\d]*' | head -n1)
|
||||
if [ -n "$ver" ]; then
|
||||
echo "$ver"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fall back to version file
|
||||
if [ -f "$VERSION_FILE" ]; then
|
||||
local stored
|
||||
stored=$(grep "^$app=" "$VERSION_FILE" | cut -d'=' -f2)
|
||||
if [ -n "$stored" ]; then
|
||||
echo "$stored"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "unknown"
|
||||
}
|
||||
|
||||
# Save installed version to version file
|
||||
save_installed_version() {
|
||||
local app="$1"
|
||||
local version="$2"
|
||||
|
||||
touch "$VERSION_FILE"
|
||||
|
||||
if grep -q "^$app=" "$VERSION_FILE"; then
|
||||
sed -i "s/^$app=.*/$app=$version/" "$VERSION_FILE"
|
||||
else
|
||||
echo "$app=$version" >> "$VERSION_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ask the user whether to proceed when version can't be determined
|
||||
ask_user_proceed() {
|
||||
local app="$1"
|
||||
local latest="$2"
|
||||
|
||||
echo "Warning: could not determine installed version of $app."
|
||||
echo "compile.conf specifies version $latest."
|
||||
read -rp "Compile and install $app anyway? [y/N] " response
|
||||
[[ "$response" =~ ^[yY] ]]
|
||||
}
|
||||
|
||||
# Check if an update is needed
|
||||
needs_update() {
|
||||
local app="$1"
|
||||
local install_path="$2"
|
||||
local latest="$3"
|
||||
|
||||
# Not installed at all
|
||||
if ! command -v "$app" &> /dev/null && [ ! -f "$install_path" ]; then
|
||||
echo " $app is not installed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
local installed
|
||||
installed=$(get_installed_version "$app")
|
||||
|
||||
if [ "$installed" = "unknown" ]; then
|
||||
if ask_user_proceed "$app" "$latest"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo " Installed version : $installed"
|
||||
echo " Latest version : $latest"
|
||||
|
||||
if [ "$installed" = "$latest" ]; then
|
||||
echo " $app is up to date, skipping."
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo " Update available for $app."
|
||||
return 0
|
||||
}
|
||||
|
||||
# Fetch source via git or wget
|
||||
fetch_source() {
|
||||
local app="$1"
|
||||
local git_url="$2"
|
||||
local wget_url="$3"
|
||||
local src_dir="$TMP_DIR/$app"
|
||||
|
||||
rm -rf "$src_dir"
|
||||
mkdir -p "$src_dir"
|
||||
|
||||
if [ -n "$git_url" ]; then
|
||||
echo " Cloning $git_url..."
|
||||
git clone "$git_url" "$src_dir"
|
||||
elif [ -n "$wget_url" ]; then
|
||||
echo " Downloading $wget_url..."
|
||||
wget -q "$wget_url" -P "$TMP_DIR"
|
||||
local filename="${wget_url##*/}"
|
||||
tar -xf "$TMP_DIR/$filename" -C "$src_dir" --strip-components=1
|
||||
rm -f "$TMP_DIR/$filename"
|
||||
else
|
||||
echo " Error: no git or wget URL specified for $app"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Parse and run steps for a given app
|
||||
run_steps() {
|
||||
local app="$1"
|
||||
local steps="$2"
|
||||
local src_dir="$TMP_DIR/$app"
|
||||
|
||||
echo " Building $app..."
|
||||
cd "$src_dir"
|
||||
|
||||
IFS=',' read -ra step_list <<< "$steps"
|
||||
for step in "${step_list[@]}"; do
|
||||
step=$(echo "$step" | xargs)
|
||||
echo " Running: $step"
|
||||
eval "$step"
|
||||
done
|
||||
}
|
||||
|
||||
# Process a single app
|
||||
process_app() {
|
||||
local app="$1"
|
||||
local git_url="$2"
|
||||
local wget_url="$3"
|
||||
local install_path="$4"
|
||||
local steps="$5"
|
||||
local version="$6"
|
||||
|
||||
echo ""
|
||||
echo "=== $app ==="
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
echo " Warning: no version specified in compile.conf for $app."
|
||||
read -rp " Compile and install $app anyway? [y/N] " response
|
||||
if [[ ! "$response" =~ ^[yY] ]]; then
|
||||
echo " Skipping $app."
|
||||
return
|
||||
fi
|
||||
elif ! needs_update "$app" "$install_path" "$version"; then
|
||||
return
|
||||
fi
|
||||
|
||||
fetch_source "$app" "$git_url" "$wget_url"
|
||||
run_steps "$app" "$steps"
|
||||
save_installed_version "$app" "$version"
|
||||
echo " $app $version installed successfully."
|
||||
}
|
||||
|
||||
# Parse compile.conf and process each app
|
||||
process_conf() {
|
||||
local app="" git_url="" wget_url="" install_path="" steps="" version=""
|
||||
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
[[ -z "$line" || "$line" == \#* ]] && continue
|
||||
|
||||
if [[ "$line" =~ ^\[(.+)\]$ ]]; then
|
||||
if [ -n "$app" ]; then
|
||||
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version"
|
||||
fi
|
||||
app="${BASH_REMATCH[1]}"
|
||||
git_url="" wget_url="" install_path="" steps="" version=""
|
||||
continue
|
||||
fi
|
||||
|
||||
local key="${line%%=*}"
|
||||
local value="${line#*=}"
|
||||
|
||||
case "$key" in
|
||||
git) git_url="$value" ;;
|
||||
wget) wget_url="$value" ;;
|
||||
install) install_path="$value" ;;
|
||||
steps) steps="$value" ;;
|
||||
version) version="$value" ;;
|
||||
esac
|
||||
|
||||
done < "$CONF_FILE"
|
||||
|
||||
# Process the last app in the file
|
||||
if [ -n "$app" ]; then
|
||||
process_app "$app" "$git_url" "$wget_url" "$install_path" "$steps" "$version"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Main ---
|
||||
|
||||
if [ ! -f "$CONF_FILE" ]; then
|
||||
echo "Error: $CONF_FILE not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$TMP_DIR"
|
||||
mkdir -p "$HOME/.local/state/HamPack"
|
||||
|
||||
echo "Starting HamPack source builds..."
|
||||
process_conf
|
||||
|
||||
echo ""
|
||||
echo "Cleaning up..."
|
||||
rm -rf "$TMP_DIR"
|
||||
|
||||
echo "All done."
|
||||
Reference in New Issue
Block a user