-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstaller
More file actions
executable file
·120 lines (91 loc) · 2.63 KB
/
installer
File metadata and controls
executable file
·120 lines (91 loc) · 2.63 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#
# installer for xtalk and related packages inside a python venv
#
function errorOut {
>&2 echo "ERROR: $1"
>&2 echo "Aborting..."
exit 1
}
#name of the directory this script resides in (hopefully)
SCRIPT_DIR="$(readlink -f "${BASH_SOURCE[0]}")" || errorOut "Failed to execute readlink."
SCRIPT_DIR="$(dirname "$SCRIPT_DIR")" || errorOut "Failed to execute dirname."
#name of this script
SCRIPT_NAME="${BASH_SOURCE[0]##*/}"
#where to find the offline packages
PKG_DIR="$SCRIPT_DIR/pkgs"
#where to write the binary
BIN="$SCRIPT_DIR/xtalk"
#default venv install path
ENV_DIR="$HOME"
#ENV is initialized later
function usage {
echo "Usage: $SCRIPT_NAME install|uninstall|reinstall [env dir]
[env dir]: Path to the directory where to install the python venv to. Default: $ENV_DIR"
exit 1
}
function isInstalled {
[ -d "$ENV" ] || [ -f "$BIN" ]
}
function installR {
isInstalled && errorOut "$BIN already appears to be installed. Either remove the existing installation manually beforehand or use the reinstall command."
echo "Creating the python venv at $ENV..."
#NOTE: python3-rtmidi must be installed via the package manager as it involves a lot of OS binary dependencies which we cannot all know at the time of offline download
python3 -m venv --system-site-packages "$ENV" || errorOut "Failed to create the python venv."
echo "Installing the dependencies inside the python venv..."
source "$ENV/bin/activate" || errorOut "Failed to activate the python venv at $ENV."
cd "$PKG_DIR" || errorOut "Failed to switch to $PKG_DIR."
#install dependencies
pip3 install --no-index --find-links=. pynput || errorOut "Failed to install pynput."
#create binary
cat << EOF > "$BIN" || errorOut "Failed to write to $BIN."
#!/bin/bash
function errorOut {
>&2 echo "ERROR: \$1"
>&2 echo "Aborting..."
exit 1
}
source "$ENV/bin/activate" || errorOut "Failed to activate the python venv at $ENV."
exec python3 "$SCRIPT_DIR/xtalk.py" "\$@"
EOF
chmod +x "$BIN" || errorOut "Failed to make $BIN executable."
}
function uninstallR {
echo "Removing $BIN..."
rm -f "$BIN"
echo "Removing $ENV..."
rm -rf "$ENV"
return 0
}
function reinstallR {
uninstallR || errorOut "Failed to uninstall."
installR
}
function main {
[ $# -lt 1 ] && usage
[ $# -gt 2 ] && usage
[ $EUID -eq 0 ] && errorOut "This script must not be run as root."
[ -z "$HOME" ] && errorOut "The HOME variable is not set."
#parse commands
local cmd="$1"
ENV="${2:-$ENV_DIR}"
[ -d "$ENV" ] || errorOut "Not an existing directory: $ENV"
ENV="$ENV/xtalk-venv"
case "$cmd" in
install)
installR
;;
uninstall)
uninstallR
;;
reinstall)
reinstallR
;;
*)
usage
;;
esac
echo "All done."
exit 0
}
main "$@"