Skip to content

Commit

Permalink
Some build and package improvements (#45)
Browse files Browse the repository at this point in the history
* add missing package version to change log

* fix some warnings of lintian during deb build

* simplification of the debian package

* introduce build script with docker/podman support

* use already existing ssh proxy, has the nice effect of not displaying the welcome message

* update readme for 1.0.2

* fix missing argument in apt-get autoremove
  • Loading branch information
spali authored Sep 8, 2020
1 parent e53af92 commit 282b9bd
Show file tree
Hide file tree
Showing 19 changed files with 324 additions and 61 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/.idea/
/**/debian/files
/**/debian/*.substvars
debhelper-build-stamp
.debhelper
18 changes: 18 additions & 0 deletions on-boot-script/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM debian:stretch-slim

RUN set -ex \
&& echo 'deb http://deb.debian.org/debian stretch-backports main' > /etc/apt/sources.list.d/backports.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
devscripts \
fakeroot \
debhelper=12.\* dh-autoreconf=17\* \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /tmp/* /var/tmp/* /var/log/* /var/lib/apt/lists/* /var/log/alternatives.log

RUN chmod a+rwx,u+t /tmp

ENTRYPOINT []
CMD ["/bin/sh"]
22 changes: 15 additions & 7 deletions on-boot-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## Compatibility

1. Should work on any UDM/UDMPro after 1.6.3
2. Tested and confirmed on 1.6.6, 1.7.0, 1.7.2rc4, 1.7.3rc1, 1.8.0rc7
2. Tested and confirmed on 1.6.6, 1.7.0, 1.7.2rc4, 1.7.3rc1, 1.8.0rc7, 1.8.0

### Upgrade from earlier way

Expand All @@ -20,8 +20,12 @@
rm /etc/systemd/system/udmboot.service
```

* The new package is exactly the old steps packaged in a debian package
* [dpkg-build-files](dpkg-build-files) contains the scripts that build the package (using dh_make and debuild) if you want to build it yourself / change it
* [build_deb.sh](build_deb.sh) can be used to build the package by yourself.
* [dpkg-build-files](dpkg-build-files) contains the sources that debuild uses to build the package if you want to build it yourself / change it
* by default it uses docker or podman to build the debian package
* use ```./build_deb.sh build``` to not using a container
* the resulting package will be in [packages/](packages/)

* Built on Ubuntu-20.04 on Windows 10/WSL2

## Steps
Expand All @@ -32,22 +36,26 @@
unifi-os shell
```

2. Download [udm-boot_1.0.1-1_all.deb](packages/udm-boot_1.0.1-1_all.deb) and install it and go back to the UDM
2. Download [udm-boot_1.0.2_all.deb](packages/udm-boot_1.0.2_all.deb) and install it and go back to the UDM

```bash
curl -L https://raw.githubusercontent.com/boostchicken/udm-utilities/master/on-boot-script/packages/udm-boot_1.0.1-1_all.deb -o udm-boot_1.0.1-1_all.deb
dpkg -i udm-boot_1.0.1-1_all.deb
curl -L https://raw.githubusercontent.com/boostchicken/udm-utilities/master/on-boot-script/packages/udm-boot_1.0.2_all.deb -o udm-boot_1.0.2_all.deb
dpkg -i udm-boot_1.0.2_all.deb
exit
```

3. Copy any shell scripts you want to run to /mnt/data/on_boot.d on your UDM (not the unifi-os shell)and make sure they are executable and have the correct shebang (#!/bin/sh)
3. Copy any shell scripts you want to run to /mnt/data/on_boot.d on your UDM (not the unifi-os shell) and make sure they are executable and have the correct shebang (#!/bin/sh)

Examples:
* Start a DNS Container [10-dns.sh](../dns-common/on_boot.d/10-dns.sh)
* Start wpa_supplicant [on_boot.d/10-wpa_supplicant.sh](examples/udm-files/on_boot.d/10-wpa_supplicant.sh)

## Version History

### 1.0.2

* Some build improvements and more clean installation

### 1.0.1

* Fully automated install, all that is left is populating /mnt/data/on_boot.d
Expand Down
101 changes: 101 additions & 0 deletions on-boot-script/build_deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/sh

set -e

WORK_DIR="$(cd "$(dirname "$0")" && echo "${PWD}")"
TARGET_DIR="${WORK_DIR}/packages"
SOURCE_DIR="${WORK_DIR}/dpkg-build-files"
CONTAINER_FILE="${WORK_DIR}/Dockerfile"
CONTAINER_CONTEXT="${WORK_DIR}"

fatal() {
echo "ERROR: ${1}" 1>&2
exit ${2-1}
}

build_in_container=false
build=false
build_container=false
if [ $# -eq 0 ]; then
build_in_container=true
fi
if [ "${1}" = "build" ]; then
build=true
fi
if [ "${1}" = "build_container" ]; then
build_container=true
fi


build_in_container() {
docker_exec="$(command -v docker || true)"
podman_exec="$(command -v podman || true)"
container_exec="${docker_exec:-"${podman_exec}"}"
container_args=""

if [ ! -f "${container_exec}" ]; then
fatal "docker or podman not found"
fi
if [ ! -f "${CONTAINER_FILE}" ]; then
fatal "container file ${CONTAINER_FILE} not found"
fi

if [ "${container_exec}" = "${docker_exec}" ]; then
# docker does not map user, so we run it as user
container_args="--user "$(id -u):$(id -g)""
fi
"${container_exec}" build --file "${CONTAINER_FILE}" --tag udm-boot-deb-builder "${CONTAINER_CONTEXT}"
"${container_exec}" run -it \
${container_args} \
-v "${SOURCE_DIR}:/source:ro" \
-v "${TARGET_DIR}:/target:rw" \
-v "${WORK_DIR}/build_deb.sh:/build_deb.sh:ro" \
--rm \
udm-boot-deb-builder \
/build_deb.sh build_container
}


build() {
source_dir=$1
target_dir=$2
version="$(dpkg-parsechangelog --show-field version -l "${source_dir}/debian/changelog")"
name="$(dpkg-parsechangelog --show-field source -l "${source_dir}/debian/changelog")"
package_name="${name}-${version}"
build_dir="$(mktemp --tmpdir="/tmp" --directory "${name}.XXXXXXXXXX")"
build_package_dir="${build_dir}/${package_name}"

if [ ! -d "${source_dir}" ]; then
fatal "source dir ${source_dir} not found"
fi
if [ ! -d "${target_dir}" ]; then
fatal "target dir ${target_dir} not found"
fi

mkdir -p "${build_package_dir}"
cp -r "${source_dir}"/* "${build_package_dir}"
(
cd "${build_package_dir}"
# we could exclude "source" here to skip building the source,
# but lintian warns only in the source build about some stuff
debuild -us -uc --build=source,all --lintian-opts --profile debian
)

find "${build_dir}" -maxdepth 1 -type f -exec mv {} "${target_dir}" \;
rm -rf "${build_dir}"
}

build_container() {
build "/source" "/target"
}

if [ $build_in_container = true ]; then
build_in_container
fi
if [ $build = true ]; then
build "${SOURCE_DIR}" "${TARGET_DIR}"
fi
if [ $build_container = true ]; then
build_container
fi

12 changes: 12 additions & 0 deletions on-boot-script/dpkg-build-files/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
udm-boot (1.0.2) unstable; urgency=medium

* optimized package structure

-- spali <[email protected]> Thu, 03 Sep 2020 16:28:40 +0200

udm-boot (1.0.1-1) unstable; urgency=medium

* Full automation

-- Boostchicken <[email protected]> Sun, 05 Jul 2020 18:46:14 -0700

udm-boot (1.0.0-1) unstable; urgency=medium

* Initial release, happy firmware persisting!
Expand Down
3 changes: 2 additions & 1 deletion on-boot-script/dpkg-build-files/debian/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Source: udm-boot
Section: unknown
Section: contrib/utils
Priority: optional
Maintainer: Boostchicken <[email protected]>
Build-Depends: debhelper-compat (= 12)
Expand All @@ -10,5 +10,6 @@ Homepage: https://github.com/boostchicken/udm-utilities

Package: udm-boot
Architecture: all
Depends: ${misc:Depends}
Description: Run things on boot on UDM
Run things on boot!
2 changes: 1 addition & 1 deletion on-boot-script/dpkg-build-files/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Source: https://github.com/boostchicken/udm-utilities

Files: *
Copyright: 2020 [email protected]
License: GPLv3
License: GPL-3
https://github.com/boostchicken/udm-utilities/blob/master/LICENSE
2 changes: 0 additions & 2 deletions on-boot-script/dpkg-build-files/debian/files

This file was deleted.

2 changes: 2 additions & 0 deletions on-boot-script/dpkg-build-files/debian/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
on_boot.sh usr/share/udm-boot/
udm-boot.service lib/systemd/system/
57 changes: 27 additions & 30 deletions on-boot-script/dpkg-build-files/debian/postinst
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
#!/bin/sh
# postinst script for udm-boot
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
configure)
echo '#!/bin/sh
if [ -d /mnt/data/on_boot.d ]; then
for i in /mnt/data/on_boot.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
fi
' > /tmp/on_boot.sh
scp -o StrictHostKeyChecking=no /tmp/on_boot.sh [email protected]:/mnt/data/on_boot.sh
ssh -o StrictHostKeyChecking=no [email protected] 'chmod +x /mnt/data/on_boot.sh'
ssh -o StrictHostKeyChecking=no [email protected] 'mkdir -p /mnt/data/on_boot.d'

rm /tmp/on_boot.sh

echo "#!/bin/sh
ssh -o StrictHostKeyChecking=no [email protected] '/mnt/data/on_boot.sh'" > /etc/init.d/udm.sh
chmod +x /etc/init.d/udm.sh
echo "[Unit]
Description=Run On Startup UDM
After=network.target
[Service]
ExecStart=/etc/init.d/udm.sh
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/udmboot.service
systemctl enable udmboot
systemctl start udmboot
scp -P "$(cat /etc/unifi-os/ssh_proxy_port)" -o StrictHostKeyChecking=no -q /usr/share/udm-boot/on_boot.sh root@localhost:/mnt/data/on_boot.sh
/sbin/ssh-proxy 'chmod +x /mnt/data/on_boot.sh && mkdir -p /mnt/data/on_boot.d'

deb-systemd-invoke enable udm-boot
deb-systemd-invoke start udm-boot
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand All @@ -44,4 +36,9 @@ case "$1" in
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
39 changes: 39 additions & 0 deletions on-boot-script/dpkg-build-files/debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
# postrm script for udm-boot
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
# reserved for future use
true
;;

*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
37 changes: 37 additions & 0 deletions on-boot-script/dpkg-build-files/debian/preinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
# preinst script for udm-boot
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
install|upgrade)
# reserved for future use
true
;;

abort-upgrade)
;;

*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
Loading

0 comments on commit 282b9bd

Please sign in to comment.