Skip to content

Commit d8bd4de

Browse files
authored
of script updates (#8339)
* oF script 1.1 * oF script 0.1.0 -> 0.2.0 - fixed subcommands, update now supports pg/projectgenerator / libs, fixed passing values to subscripts when not needed, added version query for library and pg * of script 0.2.0 -> 0.2.1 - echo verbose and remove setup for now
1 parent 8c5265d commit d8bd4de

File tree

1 file changed

+117
-16
lines changed

1 file changed

+117
-16
lines changed

scripts/of.sh

Lines changed: 117 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
#!/bin/bash
22
# pipe commands to core openFrameworks scripts
3-
OF_SCRIPT_VERSION=0.1.1
3+
OF_SCRIPT_VERSION=0.2.1
44
# Dan Rosser 2025
55
OF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66
OF_DIR="$(realpath "$OF_DIR/../")"
77
OF_CORE_SCRIPT_DIR="$(realpath "$OF_DIR/scripts")"
88
OF_CORE_CI_SCRIPT_DIR="$(realpath "$OF_DIR/scripts/ci")"
99
OF_PG_INSTALLED_DIR="$(realpath "$OF_DIR/projectGenerator")"
10-
echo "$(date): [openFrameworks: $@]"
10+
VERBOSE=${VERBOSE:-0}
11+
echoVerbose() {
12+
if [[ -n "$VERBOSE" ]]; then
13+
echo "$@"
14+
fi
15+
}
16+
echoVerbose "$(date): [openFrameworks: $@]"
1117
autoDetectOS() {
1218
if [[ -z "$PLATFORM" ]]; then
1319
export OF_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
1420
case "$OF_OS" in
1521
darwin | Dawin)
16-
export OF_PLATFORM="macos"
22+
export OF_PLATFORM="osx"
1723
export OF_ARCH=$(uname -m)
1824
;;
1925
linux | Linux)
@@ -30,8 +36,8 @@ autoDetectOS() {
3036
;;
3137
esac
3238
else
33-
export OF_OS=$(${OF_PLATFORM} | tr '[:upper:]' '[:lower:]')
34-
export OF_ARCH=""
39+
export OF_OS=$(${OF_PLATFORM} | tr '[:upper:]' '[:lower:]')
40+
export OF_ARCH=""
3541
fi
3642
}
3743

@@ -47,7 +53,7 @@ coreScriptPath() {
4753
;;
4854
esac
4955
;;
50-
macos | vs | emscripten | msys2 | android)
56+
macos | osx | vs | emscripten | msys2 | android)
5157
export OF_SCRIPT_PATH="${OF_CORE_SCRIPT_DIR}/${OF_PLATFORM}"
5258
;;
5359
*)
@@ -58,30 +64,119 @@ coreScriptPath() {
5864
}
5965

6066
autoDetectOS
61-
echo " platfrom:[$OF_PLATFORM] arch:[$OF_ARCH]"
67+
echoVerbose " platfrom:[$OF_PLATFORM] arch:[$OF_ARCH]"
6268
coreScriptPath
63-
echo " coreScriptPath: [$OF_SCRIPT_PATH]"
69+
echoVerbose " coreScriptPath: [$OF_SCRIPT_PATH]"
70+
71+
printHelp() {
72+
cat << EOF
73+
Usage: $0 <command> [subcommand] [options]
74+
75+
Commands:
76+
update [subcommand] Update openFrameworks components
77+
libs Download openFrameworks libraries (default)
78+
pg | projectgenerator Download Project Generator
79+
80+
version [subcommand] Show version information
81+
of Show openFrameworks version (default)
82+
pg | projectgenerator Show Project Generator version
83+
84+
upgrade [subcommand] Upgrade openFrameworks components
85+
addons Upgrade addons (backup recommended)
86+
apps Upgrade apps (backup recommended)
87+
88+
Options:
89+
-h, --help Show this help message
90+
91+
Examples:
92+
$0 update # Updates libraries
93+
$0 update pg # Updates Project Generator
94+
$0 version # Shows openFrameworks version
95+
$0 version pg # Shows Project Generator version
96+
$0 upgrade addons # Upgrades addons
97+
$0 upgrade apps # Upgrades apps
98+
EOF
99+
}
64100

65101
runCommand() {
66102
local CMD=$1
67103
local SUBCMD=$2
104+
local SUBCMD2=$3
68105
local SCRIPT
106+
local PLATFORM_DIR="${SUBCMD2:-$OF_PLATFORM}" # Use SUBCMD2 if provided, otherwise default to OF_PLATFORM
107+
local EXTRA_ARGS=$2
69108

70109
case "$CMD" in
71-
setup)
72-
echo "openFrameworks setup"
73-
SCRIPT="${OF_SCRIPT_PATH}/setup.sh"
110+
help|--help)
111+
printHelp
112+
exit 0
74113
;;
114+
# setup)
115+
# echo "openFrameworks setup - TODO"
116+
# SCRIPT="${OF_SCRIPT_PATH}/setup.sh"
117+
# ;;
75118
update)
76119
echo "openFrameworks update"
77-
SCRIPT="${OF_SCRIPT_PATH}/download_libs.sh"
120+
EXTRA_ARGS=""
121+
case "$SUBCMD" in
122+
""|libs)
123+
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_libs.sh"
124+
;;
125+
pg|projectgenerator) # Calls download_projectGenerator.sh
126+
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_projectGenerator.sh"
127+
;;
128+
*)
129+
SCRIPT="${OF_CORE_SCRIPT_DIR}/${PLATFORM_DIR}/download_libs.sh" ""
130+
exit 1
131+
;;
132+
esac
133+
;;
134+
version)
135+
EXTRA_ARGS=""
136+
case "$SUBCMD" in
137+
""|of) # Default: Show openFrameworks version
138+
OF_CONSTANTS_H="${OF_DIR}/libs/openFrameworks/utils/ofConstants.h"
139+
SCRIPT="NO"
140+
if [[ -f "$OF_CONSTANTS_H" ]]; then
141+
OF_VERSION_MAJOR=$(grep "#define OF_VERSION_MAJOR" "$OF_CONSTANTS_H" | awk '{print $3}')
142+
OF_VERSION_MINOR=$(grep "#define OF_VERSION_MINOR" "$OF_CONSTANTS_H" | awk '{print $3}')
143+
OF_VERSION_PATCH=$(grep "#define OF_VERSION_PATCH" "$OF_CONSTANTS_H" | awk '{print $3}')
144+
OF_VERSION_PRE_RELEASE=$(grep "#define OF_VERSION_PRE_RELEASE" "$OF_CONSTANTS_H" | awk '{print $3}' | tr -d '"')
145+
146+
OF_VERSION="${OF_VERSION_MAJOR}.${OF_VERSION_MINOR}.${OF_VERSION_PATCH}"
147+
if [[ -n "$OF_VERSION_PRE_RELEASE" && "$OF_VERSION_PRE_RELEASE" != "0" ]]; then
148+
OF_VERSION+="-${OF_VERSION_PRE_RELEASE}"
149+
fi
150+
151+
echo "openFrameworks version: [$OF_VERSION]"
152+
else
153+
echo "Error: $OF_CONSTANTS_H not found."
154+
exit 1
155+
fi
156+
;;
157+
pg|projectgenerator) # Show Project Generator version
158+
SCRIPT="${OF_DIR}/projectGenerator/projectGenerator"
159+
EXTRA_ARGS="--version"
160+
;;
161+
*)
162+
echo "Unknown version action: $SUBCMD"
163+
echo "Valid version actions: [of (default), pg, projectgenerator]"
164+
exit 1
165+
;;
166+
esac
78167
;;
79168
upgrade)
80169
echo "openFrameworks upgrade"
81170
case "$SUBCMD" in
82171
addons)
83172
echo "Upgrading addons"
84-
SCRIPT="${OF_SCRIPT_PATH}/dev/upgrade.sh"
173+
echo "Warning: This script will modify files in the addons folder. Stop and back up the folder. Commit all to local repos before proceeding."
174+
read -p "Do you want to continue? (Y/n): " CONFIRM
175+
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
176+
echo "Upgrade cancelled. No changes were made."
177+
exit 0
178+
fi
179+
SCRIPT="${OF_CORE_SCRIPT_DIR}/dev/upgrade.sh"
85180
;;
86181
apps)
87182
echo "Upgrading apps"
@@ -91,7 +186,7 @@ runCommand() {
91186
echo "Upgrade cancelled. No changes were made."
92187
exit 0
93188
fi
94-
SCRIPT="${OF_SCRIPT_PATH}/dev/upgrade.sh"
189+
SCRIPT="${OF_CORE_SCRIPT_DIR}/dev/upgrade.sh"
95190
;;
96191
*)
97192
echo "Unknown upgrade action: $SUBCMD"
@@ -107,11 +202,17 @@ runCommand() {
107202
;;
108203
esac
109204

205+
if [[ "$SCRIPT" == "NO" ]]; then
206+
exit 0
207+
fi
110208
if [[ -x "$SCRIPT" ]]; then
111209
echo "runCommand: [$SCRIPT]"
112-
"$SCRIPT" "${@:2}"
210+
"$SCRIPT" "$EXTRA_ARGS"
211+
elif [[ -f "$SCRIPT" ]]; then
212+
echo "Error: Script for ['$CMD'] exists but is not executable at: [$SCRIPT]"
213+
exit 1
113214
else
114-
echo "Error: Script for ['$CMD'] not found or not executable at: [$SCRIPT]"
215+
echo "Error: Command ['$CMD'] not implemented yet. [$SCRIPT]"
115216
exit 1
116217
fi
117218
}

0 commit comments

Comments
 (0)