mirror of
https://gitlab.com/tavo-wasd/blog.git
synced 2025-06-06 22:33:30 -06:00
85 lines
2.8 KiB
Bash
85 lines
2.8 KiB
Bash
#!/bin/sh
|
|
# External dependencies:
|
|
deps="curl tar cd mkdir cmake make"
|
|
script_name="$0"
|
|
|
|
success() {
|
|
printf ' %s - \033[32mSuccess:\033[0m \033[2m%s\033[0m\n' "$script_name" "$1"
|
|
}
|
|
|
|
warn() {
|
|
printf ' %s - \033[33mWarn:\033[0m \033[2m%s\033[0m\n' "$script_name" "$1"
|
|
}
|
|
|
|
consolelog() {
|
|
printf ' %s - \033[2mLog: %s\033[0m\n' "$script_name" "$1"
|
|
}
|
|
|
|
error() {
|
|
printf ' %s - \033[31mError: %s\033[0m\n' "$script_name" "$1"
|
|
}
|
|
|
|
missing_deps="$(for dep in $deps ; do
|
|
! command -v "$dep" 1>/dev/null 2>&1 && printf '%s ' "$dep"
|
|
done)"
|
|
|
|
[ -n "$missing_deps" ] && error "Missing dependencies for $script_name: $missing_deps" && exit 1
|
|
|
|
get_latest_wx() {
|
|
url="https://api.github.com/repos/wxWidgets/wxWidgets/releases/latest"
|
|
|
|
current_wx="$(for wx in lib/wx/wxWidgets-* ; do printf '%s' "$wx" ; done)"
|
|
current_wx="${current_wx##*-}"
|
|
current_wx="${current_wx%.tar.bz2}"
|
|
|
|
latest_wx_url="$(curl -s "$url" | while IFS= read -r line ; do
|
|
case "$line" in *browser_download_url*)
|
|
url="${line%\"*}" ; url="${url##*\"}" ; file="${url##*/}"
|
|
[ "${file##*.}" = "bz2" ] && [ "${file%-*}" = "wxWidgets" ] &&
|
|
printf '%s\n' "$url" && break ;;
|
|
esac
|
|
done)"
|
|
|
|
mkdir -p lib/wx
|
|
file="${latest_wx_url##*/}"
|
|
latest_wx_dir="lib/wx/${file%%.tar.bz2}"
|
|
latest_wx="${latest_wx_dir##*-}"
|
|
|
|
# Nor file nor new version can be determined
|
|
[ -z "$file" ] || [ -z "$latest_wx" ] && return 1
|
|
|
|
# wx is up to date, 0 if success
|
|
[ "$latest_wx" = "$current_wx" ] &&
|
|
success "wxWidgets-$current_wx is the latest version" &&
|
|
return 0
|
|
|
|
# Download wx if not present or outdated, 0 if success 1 if fail
|
|
warn "wxWidgets-$current_wx is behind wxWidgets-$latest_wx, downloading..."
|
|
curl -sL "$latest_wx_url" -o "lib/wx/$file" &&
|
|
consolelog "Extracting $file..." && (cd lib/wx && tar xf "$file") &&
|
|
consolelog "Deleting archive $file..." && rm -f "lib/wx/$file" &&
|
|
return 0 || return 1
|
|
}
|
|
|
|
build_wx() {
|
|
mkdir -p "$latest_wx_dir/autobuild"
|
|
(cd "$latest_wx_dir/autobuild" && cmake .. && make) 1>/dev/null || return 1
|
|
}
|
|
|
|
! get_latest_wx && error "Checking, downloading, or extracting failed." && exit 1
|
|
|
|
if [ "$latest_wx" != "$current_wx" ] ; then
|
|
consolelog "Building wxWidgets..."
|
|
! build_wx && error "Building wxWidgets failed" && exit 1
|
|
success "Built wxWidgets"
|
|
else
|
|
binary="$(find ./ -name 'wx-config')"
|
|
[ -n "$binary" ] && success "Found $binary, skipping building wxWidgets"
|
|
if [ -z "$binary" ] ; then
|
|
consolelog "Building wxWidgets..."
|
|
! build_wx && error "Building wxWidgets failed" && exit 1
|
|
binary="$(find ./ -name 'wx-config')"
|
|
[ -n "$binary" ] && success "Built wxWidgets"
|
|
[ -z "$binary" ] && error "Can't build wxWidgets" && exit 1
|
|
fi
|
|
fi
|