host info updates
[distro-setup] / generate-ui.sh
1 #!/bin/bash
2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
7 # its license to GPL.
8
9 # Copyright 2024 Ian Kelling
10
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
14
15 # http://www.apache.org/licenses/LICENSE-2.0
16
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
22
23
24 # iank: fixed version of /usr/share/prometheus/alertmanager/generate-ui.sh, plus exit if already build
25 set -e
26
27 if [[ -e /usr/share/prometheus/alertmanager/ui/index.html ]]; then
28 exit 0
29 fi
30
31
32 ELMDISTURL=https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz
33 SRCDIR=/usr/share/gocode/src/github.com/prometheus/alertmanager/ui/app
34 DSTDIR=/usr/share/prometheus/alertmanager/ui
35
36 echo "Installing dependencies..." >&2
37 apt install libjs-bootstrap4 fonts-font-awesome curl uglifyjs \
38 golang-github-prometheus-alertmanager-dev
39
40 #/usr/share/fonts-font-awesome/
41 TMPDIR=$(mktemp -d)
42
43 echo "Downloading Elm tools..." >&2
44 cd $TMPDIR
45 curl --location $ELMDISTURL | zcat >$TMPDIR/elm
46 chmod +x $TMPDIR/elm
47
48 echo "Compiling source code..." >&2
49 ln -s $SRCDIR/src $SRCDIR/elm.json $TMPDIR
50 (cd $TMPDIR; ./elm make src/Main.elm --optimize --output $TMPDIR/app.js)
51
52 echo "Optimising source code..." >&2
53 uglifyjs $TMPDIR/app.js \
54 --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' \
55 --mangle --output $TMPDIR/script.js
56
57 echo "Installing in Alertmanager directory..." >&2
58 mkdir -p $DSTDIR
59 mkdir -p $DSTDIR/lib
60 cp $TMPDIR/script.js $DSTDIR
61 cp $SRCDIR/index.html $SRCDIR/favicon.ico $DSTDIR
62 ln -s /usr/share/fonts-font-awesome $DSTDIR/lib/font-awesome
63 ln -s /usr/share/nodejs/bootstrap/dist $DSTDIR/lib/bootstrap4
64
65 rm -rf $TMPDIR
66
67 echo "Finished! Please, restart prometheus-alertmanager to activate UI." >&2