summarylogtreecommitdiffstats
path: root/heli-x-wrapper.sh
blob: 7d959c2d9811d953fad5fa30be396ff29a4a5a12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh
APP_LOCAL_DIR=$HOME/.heli-x
APP_EXECUTABLE=/opt/heli-x/runHELI-X.sh
APP_VERSION=$(pacman -Qi heli-x | grep 'Version' | awk '{print $3}')

# function to copy all resources to the local config directory and create a file which holds the current package version
copy_resources () {
  cp -R --preserve=timestamps /opt/heli-x/resources $APP_LOCAL_DIR/
  touch $APP_LOCAL_DIR/resources/$APP_VERSION
}

# create the local config directory if it does not exist
mkdir -p $APP_LOCAL_DIR

# copy all resources if they are not present in the local config directory
if [ ! -d $APP_LOCAL_DIR/resources ]; then
  copy_resources
else
  # backup old resources if they are present from another package version and then copy the current ones
  if [ ! -f $APP_LOCAL_DIR/resources/$APP_VERSION ]; then
    rm -rf $APP_LOCAL_DIR/resources.bak
    mv $APP_LOCAL_DIR/resources $APP_LOCAL_DIR/resources.bak
    copy_resources
  fi
fi

# execute the heli-x application or server script
if [ "$1" == "server" ]; then
  APP_EXECUTABLE=${APP_EXECUTABLE/.sh/-Server.sh}
fi
exec $APP_EXECUTABLE