Skip to content

Commit

Permalink
Merge pull request #284 from gerlero/vars
Browse files Browse the repository at this point in the history
Update variable naming
  • Loading branch information
gerlero authored Oct 6, 2024
2 parents 0ed3de3 + 2abcff5 commit 1c2483b
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 139 deletions.
4 changes: 2 additions & 2 deletions Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleVersion</key>
<string>{{APP_VERSION}}-{{DEPS_KIND}}-{{ARCH}}</string>
<string>{{app_version}}-{{deps_kind}}-{{arch}}</string>
<key>CFBundleShortVersionString</key>
<string>{{APP_VERSION}}</string>
<string>{{app_version}}</string>
</dict>
</plist>
10 changes: 5 additions & 5 deletions Contents/Resources/etc/bashrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
SCRIPT_DIR="$(\cd $(dirname ${BASH_SOURCE:-${ZSH_NAME:+$0}}) && \pwd -L)"
script_dir="$(\cd $(dirname ${BASH_SOURCE:-${ZSH_NAME:+$0}}) && \pwd -L)"

"$SCRIPT_DIR/../volume" -quiet mount
"$script_dir/../volume" -quiet mount

VOLUME=`"$SCRIPT_DIR/../volume" -show-prefix`
volume=`"$script_dir/../volume" -show-prefix`

if [ ${BASH_VERSINFO:-4} -ge 4 ]; then
# Keep the volume directory open in this process (prevents accidental ejection)
exec {fd}<"$VOLUME"
exec {fd}<"$volume"
fi

. "$VOLUME/etc/bashrc"
. "$volume/etc/bashrc"
16 changes: 8 additions & 8 deletions Contents/Resources/etc/openfoam
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#!/bin/zsh -e

APP_NAME="{{APP_NAME}}"
app_name="{{app_name}}"

APP_BUNDLE="${0:A:h:h:h:h}"
app_bundle="${0:A:h:h:h:h}"

if [ $# -eq 0 ]; then
echo "---------------------------------------------------------------------------" 1>&2
echo " | " 1>&2
echo " ( ) | °°° $APP_NAME.app °°° " 1>&2
echo " ( ) | °°° $app_name.app °°° " 1>&2
echo " ( ) ( ) | " 1>&2
echo " ( ) | Native OpenFOAM for macOS " 1>&2
echo " | {{APP_HOMEPAGE}} " 1>&2
echo "---------------------------------------------------------------------------" 1>&2

"$APP_BUNDLE/Contents/Resources/volume" mount 1>&2
"$app_bundle/Contents/Resources/volume" mount 1>&2

echo "Activating the OpenFOAM environment..." 1>&2
else
"$APP_BUNDLE/Contents/Resources/volume" -quiet mount 1>&2
"$app_bundle/Contents/Resources/volume" -quiet mount 1>&2
fi

VOLUME=$("$APP_BUNDLE/Contents/Resources/volume" -show-prefix)
volume=$("$app_bundle/Contents/Resources/volume" -show-prefix)

# Keep the volume directory open in this process (prevents accidental ejection)
exec {fd}<"$VOLUME"
exec {fd}<"$volume"

PATH="$VOLUME/usr/opt/bash/bin${PATH+:$PATH}" exec bash "$VOLUME/etc/openfoam" "$@"
PATH="$volume/usr/opt/bash/bin${PATH+:$PATH}" exec bash "$volume/etc/openfoam" "$@"
84 changes: 42 additions & 42 deletions Contents/Resources/volume
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/bin/zsh -e

APP_NAME="{{APP_NAME}}"
VOLUME_ID="{{VOLUME_ID}}"
app_name="{{app_name}}"
volume_id="{{volume_id}}"

APP_BUNDLE="${0:A:h:h:h}"
DMG_FILE="$APP_BUNDLE/Contents/Resources/$APP_NAME.dmg"
VOLUME="/Volumes/$APP_NAME"
VOLUME_ID_FILE="$VOLUME/.vol_id"
app_bundle="${0:A:h:h:h}"
dmg_file="$app_bundle/Contents/Resources/$app_name.dmg"
volume="/Volumes/$app_name"
volume_id_file="$volume/.vol_id"

printHelp() {
print_help() {
cat<<HELP_USAGE
Usage: ${0##*/} [OPTION] <command>
commands:
mount Mount the $APP_NAME volume. Does nothing if the volume is
mount Mount the $app_name volume. Does nothing if the volume is
already mounted
eject Eject the $APP_NAME volume
eject Eject the $app_name volume
options:
-quiet Do not print status messages to stdout
Expand All @@ -25,32 +25,32 @@ options:
-show-prefix Print the volume mount point and exit
-help Print this message and exit
Manage the $APP_NAME mountable volume (virtual disk) that contains the OpenFOAM
Manage the $app_name mountable volume (virtual disk) that contains the OpenFOAM
installation
HELP_USAGE
}

QUIET=false
FORCE=false
quiet=false
force=false

while [ "$#" -gt 0 ]
do
case "$1" in
-quiet)
QUIET=true
quiet=true
shift
;;
-force)
FORCE=true
force=true
shift
;;
-show-prefix)
echo "$VOLUME"
echo "$volume"
exit 0
;;
-h | -help)
printHelp
print_help
exit 0
;;
-*)
Expand All @@ -71,60 +71,60 @@ fi

case "$1" in
mount)
if [ -d "$VOLUME" ]; then
if [ ! -f "$VOLUME_ID_FILE" ] || [ "$VOLUME_ID" != "$(< "$VOLUME_ID_FILE")" ]; then
if $FORCE; then
$QUIET || echo "Ejecting different volume already mounted at $VOLUME..."
if ! hdiutil detach -quiet "$VOLUME" -force; then
echo "ERROR: Failed to force eject a different volume at $VOLUME" 1>&2
if [ -d "$volume" ]; then
if [ ! -f "$volume_id_file" ] || [ "$volume_id" != "$(< "$volume_id_file")" ]; then
if $force; then
$quiet || echo "Ejecting different volume already mounted at $volume..."
if ! hdiutil detach -quiet "$volume" -force; then
echo "ERROR: Failed to force eject a different volume at $volume" 1>&2
exit 1
fi
else
echo "ERROR: A different volume is already mounted at $VOLUME" 1>&2
echo "ERROR: A different volume is already mounted at $volume" 1>&2
echo "Eject the volume and try again?" 1>&2
exit 1
fi
fi
$QUIET || echo "The $APP_NAME volume is already mounted."
$quiet || echo "The $app_name volume is already mounted."
else
$QUIET || echo "Mounting the $APP_NAME volume..."
if ! hdiutil attach -quiet -noverify "$DMG_FILE"; then
echo "ERROR: Failed to mount the $APP_NAME volume" 1>&2
$quiet || echo "Mounting the $app_name volume..."
if ! hdiutil attach -quiet -noverify "$dmg_file"; then
echo "ERROR: Failed to mount the $app_name volume" 1>&2
exit 1
fi
if [ ! -f "$VOLUME_ID_FILE" ] || [ "$VOLUME_ID" != "$(< "$VOLUME_ID_FILE")" ]; then
echo "ERROR: A different volume is mounted at $VOLUME" 1>&2
if [ ! -f "$volume_id_file" ] || [ "$volume_id" != "$(< "$volume_id_file")" ]; then
echo "ERROR: A different volume is mounted at $volume" 1>&2
echo "Eject the volume and try again?" 1>&2
exit 1
fi
fi
$QUIET || echo "You can safely eject the volume from the Finder after use."
$quiet || echo "You can safely eject the volume from the Finder after use."
exit 0
;;
eject)
if [ ! -d "$VOLUME" ]; then
$QUIET || echo "The $APP_NAME volume is not mounted."
if [ ! -d "$volume" ]; then
$quiet || echo "The $app_name volume is not mounted."
exit 0
fi
if $FORCE; then
$QUIET || echo "Ejecting the volume at $VOLUME..."
if ! hdiutil detach -quiet "$VOLUME" -force; then
echo "ERROR: Failed to force eject the volume at $VOLUME" 1>&2
if $force; then
$quiet || echo "Ejecting the volume at $volume..."
if ! hdiutil detach -quiet "$volume" -force; then
echo "ERROR: Failed to force eject the volume at $volume" 1>&2
exit 1
fi
else
if [ ! -f "$VOLUME_ID_FILE" ] || [ "$VOLUME_ID" != "$(< "$VOLUME_ID_FILE")" ]; then
$QUIET || echo "A different volume is mounted at $VOLUME (use -force to eject it anyway)."
if [ ! -f "$volume_id_file" ] || [ "$volume_id" != "$(< "$volume_id_file")" ]; then
$quiet || echo "A different volume is mounted at $volume (use -force to eject it anyway)."
exit 0
fi
$QUIET || echo "Ejecting the $APP_NAME volume..."
if ! hdiutil detach -quiet "$VOLUME"; then
echo "ERROR: Failed to eject the $APP_NAME volume" 1>&2
$quiet || echo "Ejecting the $app_name volume..."
if ! hdiutil detach -quiet "$volume"; then
echo "ERROR: Failed to eject the $app_name volume" 1>&2
echo "The volume is probably in use (use -force to override)" 1>&2
exit 1
fi
fi
$QUIET || echo "Done."
$quiet || echo "Done."
exit 0
;;
*)
Expand Down
Loading

0 comments on commit 1c2483b

Please sign in to comment.