forked from agama-project/agama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-services.sh
executable file
·180 lines (155 loc) · 4.33 KB
/
setup-services.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh -x
# Using a git checkout in the current directory and set up the services, so that it can be used by:
# - the web frontend (as set up by setup-web.sh)
# - the CLI
# or both
# Exit on error; unset variables are an error.
set -eu
MYDIR=$(realpath $(dirname $0))
# Helper:
# Ensure root privileges for the installation.
# In a testing container, we are root but there is no sudo.
if [ $(id --user) != 0 ]; then
SUDO=sudo
if [ $($SUDO id --user) != 0 ]; then
echo "We are not root and cannot sudo, cannot continue."
exit 1
fi
else
SUDO=""
fi
# Helper:
# Like "sed -e $1 < $2 > $3" but $3 is a system file owned by root
sudosed() {
echo "$2 -> $3"
sed -e "$1" "$2" | $SUDO tee "$3" > /dev/null
}
# if agama is already running -> stop it
$SUDO systemctl list-unit-files agama.service &>/dev/null && $SUDO systemctl stop agama.service
# Ruby services
# Packages required for Ruby development (i.e., bundle install).
$SUDO zypper --non-interactive --gpg-auto-import-keys install \
gcc \
gcc-c++ \
make \
openssl-devel \
ruby-devel \
augeas-devel || exit 1
# Packages required by Agama Ruby services (see ./service/package/gem2rpm.yml).
# TODO extract list from gem2rpm.yml
$SUDO zypper --non-interactive --gpg-auto-import-keys install \
dbus-1-common \
suseconnect-ruby-bindings \
autoyast2-installation \
yast2 \
yast2-bootloader \
yast2-country \
yast2-hardware-detection \
yast2-installation \
yast2-iscsi-client \
yast2-network \
yast2-proxy \
yast2-storage-ng \
yast2-users \
bcache-tools \
btrfsprogs \
cryptsetup \
dmraid \
dosfstools \
e2fsprogs \
exfat-utils \
f2fs-tools \
fcoe-utils \
jfsutils \
libstorage-ng-lang \
lvm2 \
mdadm \
multipath-tools \
nilfs-utils \
nfs-client \
ntfs-3g \
ntfsprogs \
nvme-cli \
open-iscsi \
quota \
snapper \
udftools \
xfsprogs || exit 1
# Install x86_64 packages
if [ $(uname -m) == "x86_64" ]; then
$SUDO zypper --non-interactive --gpg-auto-import-keys install \
fde-tools
fi
# Install s390 packages
if [ $(uname -m) == "s390x" ]; then
$SUDO zypper --non-interactive --gpg-auto-import-keys install \
yast2-s390 \
yast2-reipl \
yast2-cio
fi
# Rubygem dependencies
(
cd $MYDIR/service
if [ -d /checkout-ruby-dbus ]; then
# we are in a container, told to use that one
# instead of a released version
# edit +Gemfile and -gemspec
sed -e '/ruby-dbus/d' -i Gemfile agama.gemspec
sed -e '/gemspec/a gem "ruby-dbus", path: "/checkout-ruby-dbus"' -i Gemfile
fi
bundle config set --local path 'vendor/bundle'
bundle install
)
# Rust service, CLI and auto-installation.
# Only install cargo if it is not available (avoid conflicts with rustup)
which cargo || $SUDO zypper --non-interactive install cargo
# Packages required by Rust code (see ./rust/package/agama-cli.spec)
$SUDO zypper --non-interactive install \
bzip2 \
jsonnet \
lshw \
python-langtable-data \
tar \
timezone \
xkeyboard-config-lang || exit 1
(
cd $MYDIR/rust
cargo build
)
# - D-Bus configuration
$SUDO cp -v $MYDIR/service/share/dbus.conf /usr/share/dbus-1/agama.conf
# - D-Bus activation configuration
# (this could be left out but then we would rely
# on the manual startup via bin/agamactl)
(
cd $MYDIR/service/share
DBUSDIR=/usr/share/dbus-1/agama-services
# cleanup previous installation
[[ -d $DBUSDIR ]] && $SUDO rm -r $DBUSDIR
# create services
$SUDO mkdir -p $DBUSDIR
for SVC in org.opensuse.Agama*.service; do
sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/service/bin/@" $SVC $DBUSDIR/$SVC
done
sudosed "s@\(ExecStart\)=/usr/bin/@\1=$MYDIR/service/bin/@" \
agama.service /usr/lib/systemd/system/agama.service
)
# and same for rust service
(
cd $MYDIR/rust/share
DBUSDIR=/usr/share/dbus-1/agama-services
for SVC in org.opensuse.Agama*.service; do
# it is intention to use debug here to get more useful debugging output
sudosed "s@\(Exec\)=/usr/bin/@\1=$MYDIR/rust/target/debug/@" $SVC $DBUSDIR/$SVC
done
)
# systemd reload and start of service
(
$SUDO systemctl daemon-reload
# Start the separate dbus-daemon for Agama
# (in CI we run a custom cockpit-ws which replaces the cockpit.socket
# dependency, continue in that case)
$SUDO systemctl start agama.service || pgrep cockpit-ws
)
# - Make sure NetworkManager is running
$SUDO systemctl start NetworkManager