-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_arm.sh
executable file
·112 lines (78 loc) · 2.3 KB
/
setup_arm.sh
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
#!./vrpg/busybox/busybox-arm8l ash
# Check for help
case $2 in
-h|--help|help)
$VRPG_BB cat <<EOF
-- Virtual RPG Setup --
If you are reading this, you chose the correct
setup file for your architecture. There are a
couple of options available to you in this
setup script. Simply rerun this file with one
of the following:
help - Which you found...it's this print-out
systemd - This will install the VRPG service
and enable it.
clean - If you have issues with your setup
you may use this option to clean the
program of its setup files. You must use
this when the setup fails. Otherwise, it
will fail.
EOF
;;
esac
# Pull in config
source ./vrpg.cfg
# Check if root user
if [ $USER -ne 0 ]; then
$VRPG_BB echo "User is not root! Cannot proceed with install" >&2
exit 1
# Check/handle "rebuild" argument
if [ -d "$VRPG_EXTERN" ]; then
if [ "x$2" == "clean" ]; then
$VRPG_BB rm -rf "$VRPG_EXTERN"
exit 0
else
$VRPG_BB echo "The data directory was already built. To rebuild that" >&2
$VRPG_BB echo "directory, rerun this script with the argument 'rebuild'." >&2
exit 2
fi
fi
# Set up external directory
$VRPG_BB mkdir "$VRPG_EXTERN"
# Expand the needed busybox commands
$VRPG_BB mkdir "$VRPG_BBDIR"
$VRPG_BB cp $VRPG_BB "$VRPG_BBDIR/busybox"
$VRPG_BB echo "$VRPG_BBCMDS" | $VRPG_BB sed 's/ /\n/g' | \
while read cmd; do
$VRPG_BB ln -s busybox "$VRPG_BBDIR/$cmd"
done
# Add commands to path
PATH="$VRPG_BBDIR:$PATH"
# Create venv for python
mkdir "$VRPG_VENVDIR"
if [ ! -x /usr/bin/python3 -o ! -x /usr/bin/pip3 ]; then
echo "Could not locate a Python3 installation. Please ensure that" >&2
echo "Python3, Pip3 and VENV are installed on your system." >&2
exit 3
fi
/usr/bin/python3 -m venv "$VRPG_VENVDIR"
# Enter VENV
source "$VRPG_VENVDIR/bin/activate"
# Check for python modules
pip3 install $VRPG_PYREQS
# Check if systemd install applied
if [ "x$2" != "xsystemd" ]; then
echo "Build complete"
exit 0
fi
# Copy out service file
cat "$VRPG_ROOT/vrpg/vrpg.service" | \
sed "s@%S@$VRPG_ROOT/vrpg/start.sh@;s@%E@$VRPG_ROOT/vrpg/stop.sh@" > /lib/systemd/system/vrpg.service
# Reload system daemons
systemctl daemon-reload
# Enable module
systemctl enable vrpg.service
# Start module
systemctl start vrpg.service
# End message
echo "SystemD unit installed; build complete"