Skip to content

Commit

Permalink
Replace OS image with a Debian package
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubvalenta committed Sep 15, 2020
1 parent f0d0647 commit f0a5edf
Show file tree
Hide file tree
Showing 149 changed files with 972 additions and 2,217 deletions.
7 changes: 2 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
output/
work/
deploy/
apt-cacher-ng/
.git/objects/*
.*
dist
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
deploy/*
work/*
postrun.sh
.pc
*-pc
apt-cacher-ng/
dist
6 changes: 6 additions & 0 deletions .tarignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.dockerignore
.git
.gitignore
.tarignore
debian/Dockerfile
dist
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions Dockerfile

This file was deleted.

13 changes: 0 additions & 13 deletions LICENSE

This file was deleted.

110 changes: 90 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,97 @@
.PHONY: erase build build-continue install checkargs help
_name := video-pi
_version := 1.0.0
_pkgrel := 1

erase: checkargs ## Overwrite the whole DEVICE with zeros.
sudo dd if=/dev/zero of=$(DEVICE) iflag=nocache oflag=direct bs=4M status=progress
_debian_src_filename := ${_name}_${_version}.orig.tar.xz
_debian_src_dirname := ${_name}-${_version}
_debian_pkg_filename := ${_name}_${_version}-${_pkgrel}_all.deb
_debian_container_name := video_pi_debian
_uid=$(shell id -u)
_gid=$(shell id -g)

build: ## Build the image
sudo systemctl start docker
./fix-loopback.sh
./build-docker.sh
dist_dir ?= dist

build-continue: ## Continue building the image (if previous build failed)
./fix-loopback.sh
CONTINUE=1 $(MAKE) build
.PHONY: build
build: ## Build
@echo "Done"

install: checkargs ## Install built image
unzip -p deploy/image_2018-01-02-VideoPi-standard.zip | sudo dd of=$(DEVICE) bs=4 status=progress conv=fsync
sudo sync
.PHONY: install
install: ## Install
install -D -m644 -t "$(DESTDIR)/usr/bin" bin/*
install -D -m644 -t "$(DESTDIR)/etc" etc/*
install -D -m644 -o1000 -g1000 -t "$(DESTDIR)/home/pi/.config/pcmanfm/LXDE-pi" config/pcmanfm/*
install -D -m644 -t "$(DESTDIR)/usr/share/applications" data/*.desktop
install -D -m644 -t "$(DESTDIR)/usr/share/video-pi" data/*.png
install -D -m644 -o1000 -g1000 -t "$(DESTDIR)/home/pi/.config/autostart" data/video-pi-devmon.desktop
install -D -m644 -o1000 -g1000 -t "$(DESTDIR)/home/pi/Desktop" data/raspi-config.desktop

checkargs:
ifeq (,$(DEVICE))
@echo "You must set the DEVICE variable."
@echo "Example: make backup DEVICE=/dev/sdX"
@exit 1
.PHONY: debian-build
debian-build: ## Build a Debian package
-rm -rf "$(dist_dir)"
$(MAKE) "${dist_dir}/${_debian_pkg_filename}"

${dist_dir}/${_debian_pkg_filename}: ${dist_dir}/${_debian_src_dirname} | start-docker
docker run --rm \
-u "${_uid}:${_gid}" \
-v "$$(pwd):/app" \
-w "/app/${dist_dir}/${_debian_src_dirname}" \
"$(_debian_container_name)" \
debuild -us -uc

${dist_dir}/${_debian_src_dirname}: ${dist_dir}/${_debian_src_filename}
cd "${dist_dir}" && tar xvf "${_debian_src_filename}"

${dist_dir}/${_debian_src_filename}:
mkdir -p "${dist_dir}"
tar cJvf "${dist_dir}/${_debian_src_filename}" \
-X .tarignore \
--transform 's,^\.,${_debian_src_dirname},' .

.PHONY: debian-sign
debian-sign: ${dist_dir}/${_debian_pkg_filename} | start-docker ## Sign the Debian package
ifeq ($(key_id),)
@echo "You must define the variable 'key_id'"
exit 1
endif
# See https://nixaid.com/using-gpg-inside-a-debian-docker-container/
docker run --rm -it \
-u "${_uid}:${_gid}" \
-v "$$(pwd):/app" \
-v "${HOME}/.gnupg/:/.gnupg/:ro" \
--tmpfs "/run/user/${_uid}/:mode=0700,uid=${_uid},gid=${_gid}" \
-w "/app/${dist_dir}" \
"$(_debian_container_name)" \
sh -c 'gpg-agent --daemon && dpkg-sig -k "${key_id}" --sign builder "${_debian_pkg_filename}"'

.PHONY: debian-verify
debian-verify: ${dist_dir}/${_debian_pkg_filename} | start-docker ## Verify the signature of the Debian package
# See https://nixaid.com/using-gpg-inside-a-debian-docker-container/
docker run --rm -it \
-u "${_uid}:${_gid}" \
-v "$$(pwd):/app:ro" \
-v "${HOME}/.gnupg/:/.gnupg/:ro" \
--tmpfs "/run/user/${_uid}/:mode=0700,uid=${_uid},gid=${_gid}" \
-w "/app/${dist_dir}" \
"$(_debian_container_name)" \
sh -c 'gpg-agent --daemon && dpkg-sig --verify "${_debian_pkg_filename}"'

.PHONY: debian-install
debian-install: ${dist_dir}/${_debian_pkg_filename} ## Install the built Debian package
sudo dpkg -i "${dist_dir}/${_debian_pkg_filename}"
sudo apt-get install -f --yes

.PHONY: debian-docker-build
debian-docker-build: | start-docker ## Build the Docker container
docker build -f debian/Dockerfile -t "$(_debian_container_name)" .

.PHONY: debian-docker-shell
debian-docker-shell: | start-docker ## Run bash in the Docker container
docker run --rm -it -u "${_uid}:${_gid}" -v "$$(pwd):/app" "$(_debian_container_name)" bash

.PHONY: start-docker
start-docker:
docker info &> /dev/null || sudo systemctl start docker

help: # https://gist.github.com/jhermsmeier/2d831eb8ad2fb0803091
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-14s\033[0m %s\n", $$1, $$2}'
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
14 changes: 14 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright 2015-2020 Jakub Valenta

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Loading

0 comments on commit f0a5edf

Please sign in to comment.