forked from thelounge/thelounge-deb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-package
executable file
·69 lines (55 loc) · 2.29 KB
/
build-package
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
#!/usr/bin/env bash
# Exit the script if any of the commands fail
set -e
set -u
set -o pipefail
# Set working directory to the location of this script
cd "$(dirname "${BASH_SOURCE[0]}")"
# Use "~" in place of "-" in NPMVERSION to make dpkg sort pre-releases correctly
# See https://github.com/thelounge/thelounge-deb/issues/58
# Some variables
NPMVERSION=$(grep Version debian/control | awk -F': ' '{print $2}' | sed -E 's/-[0-9]+$//' | sed -E 's/~/-/')
STARTDIR="$(pwd)"
DESTDIR="$STARTDIR/pkg"
OUTDIR="$STARTDIR/deb"
CACHE="$STARTDIR/cache"
MODULES_DIR="$DESTDIR/usr/lib/thelounge/node_modules"
export HOME="$STARTDIR" # because yarn is stupid and tries to mess with the user config files
echo "Building $NPMVERSION..."
# Remove potential leftovers from a previous build
rm -rf "$DESTDIR" "$OUTDIR"
install -dm755 "$DESTDIR/usr/bin"
install -dm755 "$MODULES_DIR/thelounge"
# Fetch the lock file so that we actually get the pinned deps that we want
# curl -O "https://raw.githubusercontent.com/thelounge/thelounge/$NPMVERSION/yarn.lock"
cp ../thelounge/yarn.lock .
alias yarn=yarnpkg
# Install the package itself
# we on purposes don't use yarn global add, because with it --ignore-scripts
# is pointless: https://github.com/yarnpkg/yarn/issues/8291 but we tried
yarn add --no-default-rc \
--frozen-lockfile \
--prod --non-interactive --ignore-scripts \
--ignore-engines \
--cache-folder "$CACHE" --modules-folder "$MODULES_DIR" \
../thelounge
#"thelounge@${NPMVERSION}"
# Write .thelounge_home to set correct system config directory
echo "/var/lib/thelounge" > "$MODULES_DIR/thelounge/.thelounge_home"
# manually write the binary link
ln -s "${MODULES_DIR#$DESTDIR}/thelounge/index.js" "$DESTDIR/usr/bin/thelounge"
# Install configuration/home directory
install -dm775 "$DESTDIR/etc/thelounge"
install -dm770 "$DESTDIR/etc/thelounge/users"
install -Dm660 \
"$MODULES_DIR/thelounge/dist/defaults/config.js" \
"$DESTDIR/etc/thelounge/config.js"
# Install systemd units
install -Dm644 "$STARTDIR/systemd/system.service" \
"$DESTDIR/lib/systemd/system/thelounge.service"
install -Dm644 "$STARTDIR/systemd/user.service" \
"$DESTDIR/usr/lib/systemd/user/thelounge.service"
# Build .deb
mkdir "$DESTDIR/DEBIAN" "$OUTDIR"
cp "$STARTDIR/debian/"* "$DESTDIR/DEBIAN/"
dpkg-deb -Z xz --root-owner-group --build "$DESTDIR" "$OUTDIR"