summarylogtreecommitdiffstats
path: root/unity-editor-vrchat
blob: d068ad203bf515840a869123b592b9d1fe9cb96b (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

unityhub_editors_path="$HOME/.config/UnityHub"
unityhub_editors_json="$unityhub_editors_path/editors.json"

check_jq() {
  hash jq 2> /dev/null
  if [ $? -ne 0 ]; then
    echo "ERROR: You need to install 'jq' to register/deregister %PKGNAME% with unithub"
    exit 1
  fi
}

check_unityhub() {
  local unityhub_pids=$(pgrep unityhub)
  if [ ! -z "$unityhub_pids" ]; then
    echo "ERROR: Can't UnityHub config while it's running. Close all Unity/UnityHub processes and try again."
    exit 1
  fi
}

ensure_json() {
  if [ ! -f "$unityhub_editors_json" ] || [ ! -s "$unityhub_editors_json" ]; then
    mkdir -p "$unityhub_editors_path"
    echo "{}" > "$unityhub_editors_json"
  fi
}

unityhub_remove() {
  local oldentries=$(cat "$unityhub_editors_json" \
                     | jq 'to_entries[] | select(.value.location == ["/usr/bin/%PKGNAME%"]) | [.key?]' \
                     | jq -cs '.')
  cat "$unityhub_editors_json" | jq -c "delpaths($oldentries)" > /tmp/editors.json
  mv /tmp/editors.json "$unityhub_editors_json"
}

unityhub_add() {
  unityhub_remove
  cat "$unityhub_editors_json" | jq -c ". + {\"%PKGVER%\":{version:\"%PKGVER%\",location:[\"/usr/bin/%PKGNAME%\"],manual:true}}" > /tmp/editors.json
  mv /tmp/editors.json "$unityhub_editors_json"
}

if [ "$1" == "--register" ]; then
  check_jq
  check_unityhub
  ensure_json
  unityhub_add
  exit 0
elif [ "$1" == "--deregister" ]; then
  check_jq
  check_unityhub
  ensure_json
  unityhub_remove
  exit 0
fi

# This prevents the editor from crashing when opening projects in some systems
unset GTK_IM_MODULE

# HACK: fixes WebGL builds by adding a symlink (python -> python2) to the PATH
export PATH=/opt/Unity/Editor:$PATH

mkdir -p ~/.local/share/unity3d/Packages
exec /opt/Unity/Editor/Unity -no-throttle-updates "$@"