Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

of script updates #8339

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 117 additions & 16 deletions scripts/of.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#!/bin/bash
# pipe commands to core openFrameworks scripts
OF_SCRIPT_VERSION=0.1.1
OF_SCRIPT_VERSION=0.2.1
# Dan Rosser 2025
OF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
OF_DIR="$(realpath "$OF_DIR/../")"
OF_CORE_SCRIPT_DIR="$(realpath "$OF_DIR/scripts")"
OF_CORE_CI_SCRIPT_DIR="$(realpath "$OF_DIR/scripts/ci")"
OF_PG_INSTALLED_DIR="$(realpath "$OF_DIR/projectGenerator")"
echo "$(date): [openFrameworks: $@]"
VERBOSE=${VERBOSE:-0}
echoVerbose() {
if [[ -n "$VERBOSE" ]]; then
echo "$@"
fi
}
echoVerbose "$(date): [openFrameworks: $@]"
autoDetectOS() {
if [[ -z "$PLATFORM" ]]; then
export OF_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$OF_OS" in
darwin | Dawin)
export OF_PLATFORM="macos"
export OF_PLATFORM="osx"
export OF_ARCH=$(uname -m)
;;
linux | Linux)
Expand All @@ -30,8 +36,8 @@ autoDetectOS() {
;;
esac
else
export OF_OS=$(${OF_PLATFORM} | tr '[:upper:]' '[:lower:]')
export OF_ARCH=""
export OF_OS=$(${OF_PLATFORM} | tr '[:upper:]' '[:lower:]')
export OF_ARCH=""
fi
}

Expand All @@ -47,7 +53,7 @@ coreScriptPath() {
;;
esac
;;
macos | vs | emscripten | msys2 | android)
macos | osx | vs | emscripten | msys2 | android)
export OF_SCRIPT_PATH="${OF_CORE_SCRIPT_DIR}/${OF_PLATFORM}"
;;
*)
Expand All @@ -58,30 +64,119 @@ coreScriptPath() {
}

autoDetectOS
echo " platfrom:[$OF_PLATFORM] arch:[$OF_ARCH]"
echoVerbose " platfrom:[$OF_PLATFORM] arch:[$OF_ARCH]"
coreScriptPath
echo " coreScriptPath: [$OF_SCRIPT_PATH]"
echoVerbose " coreScriptPath: [$OF_SCRIPT_PATH]"

printHelp() {
cat << EOF
Usage: $0 <command> [subcommand] [options]

Commands:
update [subcommand] Update openFrameworks components
libs Download openFrameworks libraries (default)
pg | projectgenerator Download Project Generator

version [subcommand] Show version information
of Show openFrameworks version (default)
pg | projectgenerator Show Project Generator version

upgrade [subcommand] Upgrade openFrameworks components
addons Upgrade addons (backup recommended)
apps Upgrade apps (backup recommended)

Options:
-h, --help Show this help message

Examples:
$0 update # Updates libraries
$0 update pg # Updates Project Generator
$0 version # Shows openFrameworks version
$0 version pg # Shows Project Generator version
$0 upgrade addons # Upgrades addons
$0 upgrade apps # Upgrades apps
EOF
}

runCommand() {
local CMD=$1
local SUBCMD=$2
local SUBCMD2=$3
local SCRIPT
local PLATFORM_DIR="${SUBCMD2:-$OF_PLATFORM}" # Use SUBCMD2 if provided, otherwise default to OF_PLATFORM
local EXTRA_ARGS=$2

case "$CMD" in
setup)
echo "openFrameworks setup"
SCRIPT="${OF_SCRIPT_PATH}/setup.sh"
help|--help)
printHelp
exit 0
;;
# setup)
# echo "openFrameworks setup - TODO"
# SCRIPT="${OF_SCRIPT_PATH}/setup.sh"
# ;;
update)
echo "openFrameworks update"
SCRIPT="${OF_SCRIPT_PATH}/download_libs.sh"
EXTRA_ARGS=""
case "$SUBCMD" in
""|libs)
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_libs.sh"
;;
pg|projectgenerator) # Calls download_projectGenerator.sh
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_projectGenerator.sh"
;;
*)
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_libs.sh" ""
exit 1
;;
esac
;;
version)
EXTRA_ARGS=""
case "$SUBCMD" in
""|of) # Default: Show openFrameworks version
OF_CONSTANTS_H="${OF_DIR}/libs/openFrameworks/utils/ofConstants.h"
SCRIPT="NO"
if [[ -f "$OF_CONSTANTS_H" ]]; then
OF_VERSION_MAJOR=$(grep "#define OF_VERSION_MAJOR" "$OF_CONSTANTS_H" | awk '{print $3}')
OF_VERSION_MINOR=$(grep "#define OF_VERSION_MINOR" "$OF_CONSTANTS_H" | awk '{print $3}')
OF_VERSION_PATCH=$(grep "#define OF_VERSION_PATCH" "$OF_CONSTANTS_H" | awk '{print $3}')
OF_VERSION_PRE_RELEASE=$(grep "#define OF_VERSION_PRE_RELEASE" "$OF_CONSTANTS_H" | awk '{print $3}' | tr -d '"')

OF_VERSION="${OF_VERSION_MAJOR}.${OF_VERSION_MINOR}.${OF_VERSION_PATCH}"
if [[ -n "$OF_VERSION_PRE_RELEASE" && "$OF_VERSION_PRE_RELEASE" != "0" ]]; then
OF_VERSION+="-${OF_VERSION_PRE_RELEASE}"
fi

echo "openFrameworks version: [$OF_VERSION]"
else
echo "Error: $OF_CONSTANTS_H not found."
exit 1
fi
;;
pg|projectgenerator) # Show Project Generator version
SCRIPT="${OF_DIR}/projectGenerator/projectGenerator"
EXTRA_ARGS="--version"
;;
*)
echo "Unknown version action: $SUBCMD"
echo "Valid version actions: [of (default), pg, projectgenerator]"
exit 1
;;
esac
;;
upgrade)
echo "openFrameworks upgrade"
case "$SUBCMD" in
addons)
echo "Upgrading addons"
SCRIPT="${OF_SCRIPT_PATH}/dev/upgrade.sh"
echo "Warning: This script will modify files in the addons folder. Stop and back up the folder. Commit all to local repos before proceeding."
read -p "Do you want to continue? (Y/n): " CONFIRM
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
echo "Upgrade cancelled. No changes were made."
exit 0
fi
SCRIPT="${OF_CORE_SCRIPT_DIR}/dev/upgrade.sh"
;;
apps)
echo "Upgrading apps"
Expand All @@ -91,7 +186,7 @@ runCommand() {
echo "Upgrade cancelled. No changes were made."
exit 0
fi
SCRIPT="${OF_SCRIPT_PATH}/dev/upgrade.sh"
SCRIPT="${OF_CORE_SCRIPT_DIR}/dev/upgrade.sh"
;;
*)
echo "Unknown upgrade action: $SUBCMD"
Expand All @@ -107,11 +202,17 @@ runCommand() {
;;
esac

if [[ "$SCRIPT" == "NO" ]]; then
exit 0
fi
if [[ -x "$SCRIPT" ]]; then
echo "runCommand: [$SCRIPT]"
"$SCRIPT" "${@:2}"
"$SCRIPT" "$EXTRA_ARGS"
elif [[ -f "$SCRIPT" ]]; then
echo "Error: Script for ['$CMD'] exists but is not executable at: [$SCRIPT]"
exit 1
else
echo "Error: Script for ['$CMD'] not found or not executable at: [$SCRIPT]"
echo "Error: Command ['$CMD'] not implemented yet. [$SCRIPT]"
exit 1
fi
}
Expand Down