summarylogtreecommitdiffstats
path: root/launcher.sh
blob: a6cb2988a158d48d81bf4d6859b1faea3b67f3ee (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
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

if [[ "$0" =~ / ]]; then
  read app_path < <(realpath -- "$0")
else
  if hash "$0" &> /dev/null; then
    read app_path < <(hash -t "$0")
  else
    if [ -f "./$0" ]; then
      read app_path < <(realpath -- "./$0")
    fi
  fi
fi

if [ -z "$app_path" ]; then
  app_path=/usr/bin
else
  read app_path < <(dirname -- "$app_path")
fi

app_path+="/../lib/daydreamer/"

if [ -n "$1" ] && [ -f "$1" ]; then
  read game_file_path < <(realpath "$1")
fi

launch_app() {
  if [ -n "$1" ]; then
    if [ -f "$app_path/$1" ]; then
      if [ -n "$game_file_path" ]; then
        exec -- java -jar "$app_path/$1" "$game_file_path"
      else
        exec -- java -jar "$app_path/$1"
      fi
    else
      printf -- "ā€ž%sā€: file not found" "$app_path/$1" >&2
      exit 1
    fi
    exit 255
  fi
}