-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian-build.sh
executable file
·64 lines (51 loc) · 2.17 KB
/
debian-build.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
#!/bin/bash
set -e
DEBIAN_FOLDER="debian"
BINARY_NAME="capslock-auto-switch"
VERSION="0.2.0"
REVISION="1"
PKG_NAME="${BINARY_NAME}_${VERSION}-${REVISION}_all"
echo "🏗️ Start building debian package..."
echo "🗑️ cleaning..."
sudo rm -rf ${DEBIAN_FOLDER}/usr
rm -rf ${BINARY_NAME}*.deb
echo "🛠️ Build package structure"
mkdir -p ${DEBIAN_FOLDER}/etc/systemd/user
mkdir -p ${DEBIAN_FOLDER}/usr/share/doc/${BINARY_NAME}
mkdir -p ${DEBIAN_FOLDER}/usr/bin
mkdir -p ${DEBIAN_FOLDER}/usr/share/man/man1
echo "🗞️ Compress changelog..."
gzip -c -n -9 ./changelog > ./${DEBIAN_FOLDER}/usr/share/doc/${BINARY_NAME}/changelog.gz
echo "🖨️ Copy files..."
cp ./LICENSE ./${DEBIAN_FOLDER}/usr/share/doc/${BINARY_NAME}/copyright
echo "📝 Make man..."
# docker run --rm -v $(pwd):/working -w /working pandoc/minimal:3 --to man man.md -o capslock-auto-switch.1
gzip -c -n -9 ./debian-scripts/man.1 > ./${DEBIAN_FOLDER}/usr/share/man/man1/capslock-auto-switch.1.gz
echo "🦀 run build..."
cargo build --release
strip target/release/$BINARY_NAME
sudo cp target/release/$BINARY_NAME ${DEBIAN_FOLDER}/usr/bin
echo "🔏 Set permissions..."
SPECIAL_OWNER=$(ls -alF ./README.md | grep -Ei ' ./' | awk '{print $3}')
if [ "$SPECIAL_OWNER" != "root" ]; then
sudo chown -R root:root ./${DEBIAN_FOLDER}/usr
sudo chown -R root:root ./${DEBIAN_FOLDER}/etc
fi
sudo chmod -R 755 ./${DEBIAN_FOLDER}/usr
sudo chmod -R 755 ./${DEBIAN_FOLDER}/etc
sudo chmod -x ./${DEBIAN_FOLDER}/etc/systemd/user/capslock-auto-switch.service
sudo chmod -R 755 ./${DEBIAN_FOLDER}/usr/share/
sudo chmod 644 ./${DEBIAN_FOLDER}/usr/share/doc/${BINARY_NAME}/*
sudo chmod a-x ./${DEBIAN_FOLDER}/usr/share/man/man1/capslock-auto-switch.1.gz
echo "📦 Build Debian package..."
rm -f ${PKG_NAME}.deb
sudo dpkg-deb --build -Z xz ./${DEBIAN_FOLDER}
mv ${DEBIAN_FOLDER}.deb ${PKG_NAME}.deb
if [ "$1" = "--lint" ]; then
echo "🗹 check with lintian..."
set +e
docker run --rm -it -v ./${PKG_NAME}.deb:/app/${PKG_NAME}.deb nouchka/lintian -c /app/${PKG_NAME}.deb -v
fi
sudo chown -R $SPECIAL_OWNER:$SPECIAL_OWNER ./${DEBIAN_FOLDER}/etc
sudo chown -R $SPECIAL_OWNER:$SPECIAL_OWNER ./${DEBIAN_FOLDER}/usr
echo "🎉 Done! 🎉"