-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-dwarf
executable file
·67 lines (58 loc) · 1.25 KB
/
run-dwarf
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
#!/bin/bash -eu
#
# Run dwarf in the forground (for testing)
#
if [ $(id -u) -ne 0 ] ; then
echo "You need to run this script as root"
exit 1
fi
#
# Create the dwarf group and user
#
if ! getent group dwarf >/dev/null ; then
groupadd -r dwarf
fi
if ! getent passwd dwarf >/dev/null ; then
useradd -r -g dwarf -G dwarf,libvirt -d /var/lib/dwarf \
-s /sbin/nologin dwarf
fi
#
# Create the persistent working directory
#
mkdir -p /var/lib/dwarf/instances/_base
mkdir -p /var/lib/dwarf/images
chown -R dwarf:dwarf /var/lib/dwarf
#
# Create the temporary source directory
#
tmpd=$(mktemp -d /tmp/dwarf-XXXXXXXXXXXX)
trap "rm -rf ${tmpd} " EXIT
#
# Copy the source
#
cp -aR bin dwarf ${tmpd}
find ${tmpd} -type d | xargs chmod 777
find ${tmpd} -type f | xargs chmod 644
chmod 777 ${tmpd}/bin/*
#
# Copy the sudoer file
#
cp etc/sudoers.d/dwarf /etc/sudoers.d/dwarf
chown root:root /etc/sudoers.d/dwarf
chmod 440 /etc/sudoers.d/dwarf
#
# Initialize the database
#
if ! [ -e /var/lib/dwarf/dwarf.db ] ; then
su -s /bin/sh -c "${tmpd}/bin/dwarf-manage db-init" dwarf
fi
#
# Stop the dwarf service
#
if [ -e /lib/systemd/system/dwarf.service ] ; then
systemctl stop dwarf.service
fi
#
# Finally run it
#
su -s /bin/sh -c "${tmpd}/bin/dwarf -s" dwarf