From a5eaac2ff543bea7f49e9f76a0aa07bc284867c5 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Fri, 3 Aug 2018 13:19:38 -0500 Subject: [PATCH 01/20] Add manual --- docs/README.md | 41 ++++++++++++++++ docs/SUMMARY.md | 6 +++ docs/book.json | 3 ++ docs/customization.md | 29 ++++++++++++ docs/package.json | 6 +++ docs/publiclab.svg | 107 ++++++++++++++++++++++++++++++++++++++++++ docs/roadmap.md | 8 ++++ docs/workflow.md | 27 +++++++++++ 8 files changed, 227 insertions(+) create mode 100644 docs/README.md create mode 100644 docs/SUMMARY.md create mode 100644 docs/book.json create mode 100644 docs/customization.md create mode 100644 docs/package.json create mode 100644 docs/publiclab.svg create mode 100644 docs/roadmap.md create mode 100644 docs/workflow.md diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..4a34963 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,41 @@ +# Raspberry Pi Image Builder + +**PublicLab.Org** + +![](publiclab.svg) + +This documentation covers the usage of the builder script for operating system images designed to be included with Public Lab Camera Kits. + +Any person may use this script and the related infrastructure for building customized operating systems for their own projects. + +It is important to highlight that this project was forked from the [Hypriot project](https://github.com/hypriot/image-builder-rpi). Thanks! + +## Rationale + +Often DIY projects require customizing software. It is an effort to publish these customizations. + +This repository could serve to share customizations and develop them *socially*, by means of issuing pull requests and sharing build recipes and resulting images. + +This guide serves the purpose of detailing the build process and suggesting a customization workflow. + +## Developing + +Issuing a PR will build the image. We will merge PRs aligned and suitable to be included in Public Lab's Camera Kits, at the discretion of the maitainers. You are encouraged to fork your own repository and experiment with preparing your own images! + +- Repository (GitLab): https://gitlab.com/publiclab/image-builder-rpi + +By using Gitlab's automated continuous integration to build images you'll have fresh images built for you every time you push your changes. + +For the community's convenience, this repository is also mirrored at Github + +- Repository (GitHub): https://github.com/publiclab/image-builder-rpi + +## License + +Like its upstream project Hypriot, `image-builder-rpi` is licensed with the MIT license. + +This guide is licensed with Creative Commons Share-Alike 4.0 Unported license. + +## Contributors + +This project was initiated by Sebastian Silva by contract of PublicLab.Org, the **Public Laboratory for Open Technology and Science**. diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md new file mode 100644 index 0000000..d52dc05 --- /dev/null +++ b/docs/SUMMARY.md @@ -0,0 +1,6 @@ +# Summary + +* [Image Builder](README.md) +* [Customization](customization.md) +* [Workflow](workflow.md) +* [Roadmap](roadmap.md) diff --git a/docs/book.json b/docs/book.json new file mode 100644 index 0000000..a444496 --- /dev/null +++ b/docs/book.json @@ -0,0 +1,3 @@ +{ + "title": "Raspberry Pi Image Builder" +} diff --git a/docs/customization.md b/docs/customization.md new file mode 100644 index 0000000..72f397a --- /dev/null +++ b/docs/customization.md @@ -0,0 +1,29 @@ +# Image Customization + +This repository holds the recipe and files for building an operating system image capable of booting on Raspberry Pi (tested on model `Pi Zero W`). + +While you may build locally if you have Docker (tested on Linux), it is recommended that you follow the [workflow](workflow.md). + +## Files and Directories + + `builder/files/`: All files in this directory will be copied over to the Raspberry Pi image's root directory. + + `builder/build.sh`: This is the script that does the actual building. + + `builder/chroot-script.sh`: This is the script that is run inside an ARM based virtual machine that emulates the raspberry pi. It installs packages and also generates some configuration files. + + `builder/files/boot/user-data`: This is the configuration file for cloud-init. It holds important customizations such as username creation and hostname configuration. + +## Cloud Init Configuration File (`user-data`) + +This is one recommended configuration point as it can be modified *before first boot*. + +This is the main configuration file for `cloud-init` which is designed to customize cloud servers and provides many useful configuration hooks. Please refer to the [`cloud-init` documentation](https://cloudinit.readthedocs.io/en/0.7.9/) for details. + +## Customization Orientation + +If you'd like to start scripts every boot, try to customize `builder/files/etc/rc.local` adding commands which will be ran after the rest of the startup process. + +Also the web root is at `/var/www/`. You may place web content or applications here. PHP has been enabled by default. + +Once you have modified the scripts or files to be included in the distribution, follow the [workflow](workflow.md) into the next step. diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000..e20039b --- /dev/null +++ b/docs/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "gitbook-cli": "^2.3.2", + "svgexport": "^0.3.2" + } +} diff --git a/docs/publiclab.svg b/docs/publiclab.svg new file mode 100644 index 0000000..b3754de --- /dev/null +++ b/docs/publiclab.svg @@ -0,0 +1,107 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/docs/roadmap.md b/docs/roadmap.md new file mode 100644 index 0000000..a08ab52 --- /dev/null +++ b/docs/roadmap.md @@ -0,0 +1,8 @@ +# Development goals + +This is a wishlist of features to include: + +* Configure Wifi (client / access point / forwarding) +* Streaming Camera +* Web editor / runner for scripts +* Configure scripts to run at boot diff --git a/docs/workflow.md b/docs/workflow.md new file mode 100644 index 0000000..729fe75 --- /dev/null +++ b/docs/workflow.md @@ -0,0 +1,27 @@ +# Development Workflow for Custom Images + +We recommend that you follow these steps to build your images. + +## Make a Pull Request + +Create a named branch with a descriptive name (it will be used in the image filename), and **make a pull request** describing your intentions! + +**Intention to merge to master is not required**. You may issue a PR simply for sharing an experiment and for triggering a build to test an image. + +## Download the build artifact from GitLab CI + +Once you've made a PR, you should see a build triggered that is linked in your PR. + +It can take more than 20 minutes to build an image. + +You may follow the link on your PR to view the build log and find the links to download the build artifacts, which hold the image for flashing. + +These images are referred to as build artifacts and are available for download directly from the [**build jobs page at Gitlab**](https://gitlab.com/publiclab/image-builder-rpi/-/jobs). + +## Flash your image + +Using your preferred method (or the [Hypriot flash tool](https://github.com/hypriot/flash) which offers some flash-time customization hooks. + +## Share your results! + +Do comment on your PR! From a3d7a9fccde8edd6a720b219e8914869ccdedf0e Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 9 Aug 2018 23:42:23 -0500 Subject: [PATCH 02/20] Add pages build job --- .gitlab-ci.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ba5b172..32e2efb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,15 +1,34 @@ image: gitlab/dind +stages: + - publish + variables: VERSION: ${CI_COMMIT_REF_NAME} before_script: - apt-get update && apt-get install -y --no-install-recommends make linux-image-generic -job: +sd-image: + stage: publish script: - make sd-image artifacts: paths: - hypriotos-rpi-${VERSION}.img.zip - hypriotos-rpi-${VERSION}.img.zip.sha256 + +pages: + stage: publish + image: node:8.9 + before_script: + - npm install gitbook-cli -g # install gitbook + - gitbook fetch latest # fetch latest stable version + - gitbook install # add any requested plugins in book.json + script: + - gitbook build . public # build to public path + artifacts: + paths: + - public +# only: +# - master From d6c8858becaf23ba20347075f038cba257dfdca6 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 9 Aug 2018 23:44:27 -0500 Subject: [PATCH 03/20] Build proper dir for docs --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 32e2efb..6d1b172 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,9 +24,9 @@ pages: before_script: - npm install gitbook-cli -g # install gitbook - gitbook fetch latest # fetch latest stable version - - gitbook install # add any requested plugins in book.json + - gitbook install docs # add any requested plugins in book.json script: - - gitbook build . public # build to public path + - gitbook build docs public # build to public path artifacts: paths: - public From 85e00b63c8f2159566b7737bbe16e1b43323d410 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 9 Aug 2018 23:47:56 -0500 Subject: [PATCH 04/20] Only build docs for master branch --- .gitlab-ci.yml | 4 ++-- docs/workflow.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d1b172..60c8044 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,5 +30,5 @@ pages: artifacts: paths: - public -# only: -# - master + only: + - master diff --git a/docs/workflow.md b/docs/workflow.md index 729fe75..95b1422 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -20,7 +20,7 @@ These images are referred to as build artifacts and are available for download d ## Flash your image -Using your preferred method (or the [Hypriot flash tool](https://github.com/hypriot/flash) which offers some flash-time customization hooks. +Using your preferred method (or the [Hypriot flash tool](https://github.com/hypriot/flash), which offers some flash-time customization hooks). ## Share your results! From a1c47bfecd4dcb8d270af16ee5717d57bca4d3eb Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Mon, 17 Sep 2018 02:05:31 -0500 Subject: [PATCH 05/20] Add rpicam software --- builder/chroot-script.sh | 8 ++++++++ builder/files/etc/rpicam_config.txt | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100644 builder/files/etc/rpicam_config.txt diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index f9ac33b..2d7888b 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -209,6 +209,14 @@ echo "Installing rpi-serial-console script" wget -q https://raw.githubusercontent.com/lurch/rpi-serial-console/master/rpi-serial-console -O usr/local/bin/rpi-serial-console chmod +x usr/local/bin/rpi-serial-console +echo "Installing RPi Cam Web Interface" +wget -q https://github.com/silvanmelchior/RPi_Cam_Web_Interface/archive/master.zip -O /tmp/rpicam.zip +cd /tmp/ +unzip rpicam.zip +cd RPi_Cam_Web_Interface-master +cp /etc/rpicam_config.txt config.txt +./install.sh --q + # fix eth0 interface name ln -s /dev/null /etc/systemd/network/99-default.link diff --git a/builder/files/etc/rpicam_config.txt b/builder/files/etc/rpicam_config.txt new file mode 100644 index 0000000..325c3f4 --- /dev/null +++ b/builder/files/etc/rpicam_config.txt @@ -0,0 +1,8 @@ +rpicamdir="cam" +webserver="" +webport="80" +user="" +webpasswd="" +autostart="yes" +jpglink="no" +phpversion="7" From 3fb9ebb6175ba9ce1361898e7c10ff7a1620ca56 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Mon, 17 Sep 2018 02:18:12 -0500 Subject: [PATCH 06/20] Add unzip --- builder/chroot-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index 2d7888b..e874c11 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -147,6 +147,7 @@ apt-get -o Dpkg::Options::=--force-confdef \ pi-bluetooth \ lsb-release \ gettext \ + unzip \ cloud-init From c0d54309090b86fab665f8aa4750bc262ca21909 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 18 Sep 2018 00:39:34 -0500 Subject: [PATCH 07/20] Fix parameter for RPicam installation --- builder/chroot-script.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index e874c11..a791a39 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -148,6 +148,7 @@ apt-get -o Dpkg::Options::=--force-confdef \ lsb-release \ gettext \ unzip \ + motion \ cloud-init @@ -216,7 +217,7 @@ cd /tmp/ unzip rpicam.zip cd RPi_Cam_Web_Interface-master cp /etc/rpicam_config.txt config.txt -./install.sh --q +bash ./install.sh q # fix eth0 interface name ln -s /dev/null /etc/systemd/network/99-default.link From 1d717aecf195cd36a9ec7038581fa4c168f1fbb7 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 18 Sep 2018 01:05:22 -0500 Subject: [PATCH 08/20] Add rc.local --- builder/files/etc/rc.local | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 builder/files/etc/rc.local diff --git a/builder/files/etc/rc.local b/builder/files/etc/rc.local new file mode 100755 index 0000000..65634df --- /dev/null +++ b/builder/files/etc/rc.local @@ -0,0 +1,14 @@ +#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "exit 0" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + +exit 0 From fdadde8e60f1ea2523b816d0ed7376bddaa8d8d9 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 20 Sep 2018 00:29:43 -0500 Subject: [PATCH 09/20] Added gpac (MP4Box) to fix video recording --- builder/chroot-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index a791a39..5180d25 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -149,6 +149,7 @@ apt-get -o Dpkg::Options::=--force-confdef \ gettext \ unzip \ motion \ + gpac \ cloud-init From 37eed3881794c2d8830be2d37845d8103ee255e3 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 20 Sep 2018 00:59:10 -0500 Subject: [PATCH 10/20] Add gstreamer and other deps --- builder/chroot-script.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index 5180d25..eedabc0 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -147,7 +147,9 @@ apt-get -o Dpkg::Options::=--force-confdef \ pi-bluetooth \ lsb-release \ gettext \ - unzip \ + zip \ + libav-tools \ + gstreamer1.0-tools \ motion \ gpac \ cloud-init From 40e7265013768a60b4682cd67270c09508450b6d Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 20 Sep 2018 01:17:20 -0500 Subject: [PATCH 11/20] Fix deps and add basic HTML menu --- builder/chroot-script.sh | 1 + builder/files/var/www/index.html | 3 +++ 2 files changed, 4 insertions(+) diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index eedabc0..fe77ab4 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -147,6 +147,7 @@ apt-get -o Dpkg::Options::=--force-confdef \ pi-bluetooth \ lsb-release \ gettext \ + unzip \ zip \ libav-tools \ gstreamer1.0-tools \ diff --git a/builder/files/var/www/index.html b/builder/files/var/www/index.html index 88af205..a838a28 100644 --- a/builder/files/var/www/index.html +++ b/builder/files/var/www/index.html @@ -16,5 +16,8 @@

Public Lab Pi Kit

You've correctly connected to your Pi!

+

+ RPi Cam Web Interface +

From 8825d92dc0803bfa4089c0f1391f9e5ad7bba854 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 20 Sep 2018 02:07:57 -0500 Subject: [PATCH 12/20] First attempt at including ttyd --- builder/chroot-script.sh | 5 +++++ builder/files/etc/systemd/system/ttyd.service | 8 ++++++++ builder/files/var/www/index.html | 3 +++ 3 files changed, 16 insertions(+) create mode 100644 builder/files/etc/systemd/system/ttyd.service diff --git a/builder/chroot-script.sh b/builder/chroot-script.sh index f9ac33b..4b4d1d5 100644 --- a/builder/chroot-script.sh +++ b/builder/chroot-script.sh @@ -205,6 +205,11 @@ lighttpd-enable-mod fastcgi-php systemctl disable dhcpcd systemctl disable hciuart +echo "Installing ttyd web terminal" +wget -q https://github.com/tsl0922/ttyd/releases/download/1.4.2/ttyd_linux.armhf -O usr/local/bin/ttyd +chmod +x usr/local/bin/ttyd +systemctl enable ttyd + echo "Installing rpi-serial-console script" wget -q https://raw.githubusercontent.com/lurch/rpi-serial-console/master/rpi-serial-console -O usr/local/bin/rpi-serial-console chmod +x usr/local/bin/rpi-serial-console diff --git a/builder/files/etc/systemd/system/ttyd.service b/builder/files/etc/systemd/system/ttyd.service new file mode 100644 index 0000000..8cda233 --- /dev/null +++ b/builder/files/etc/systemd/system/ttyd.service @@ -0,0 +1,8 @@ +[Unit] +Description=ttyd Web Terminal + +[Service] +ExecStart=/usr/local/bin/ttyd login + +[Install] +WantedBy=multi-user.target diff --git a/builder/files/var/www/index.html b/builder/files/var/www/index.html index 88af205..b4e807c 100644 --- a/builder/files/var/www/index.html +++ b/builder/files/var/www/index.html @@ -16,5 +16,8 @@

Public Lab Pi Kit

You've correctly connected to your Pi!

+

+ Access command line +

From dc60c453aa97c21a8b5f863624a89dc8bf388c06 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 02:05:08 -0500 Subject: [PATCH 13/20] Include documentation into image --- .gitlab-ci.yml | 9 ++++++--- builder/files/var/www/index.html | 3 +++ docs/workflow.md | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 60c8044..949b7b7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,10 +1,12 @@ image: gitlab/dind stages: + - docs - publish variables: VERSION: ${CI_COMMIT_REF_NAME} + CI_JOB: ${CI_JOB_ID} before_script: - apt-get update && apt-get install -y --no-install-recommends make linux-image-generic @@ -19,16 +21,17 @@ sd-image: - hypriotos-rpi-${VERSION}.img.zip.sha256 pages: - stage: publish + stage: docs image: node:8.9 before_script: - npm install gitbook-cli -g # install gitbook - gitbook fetch latest # fetch latest stable version - gitbook install docs # add any requested plugins in book.json + - sed 's/{{ CI_JOB }}/${CI_JOB}/g' docs/workflow.md script: - - gitbook build docs public # build to public path + - gitbook build docs builder/files/var/www/docs # build to public path artifacts: paths: - - public + - builder/files/var/www/docs only: - master diff --git a/builder/files/var/www/index.html b/builder/files/var/www/index.html index 88af205..48ec526 100644 --- a/builder/files/var/www/index.html +++ b/builder/files/var/www/index.html @@ -16,5 +16,8 @@

Public Lab Pi Kit

You've correctly connected to your Pi!

+

+ Documentation +

diff --git a/docs/workflow.md b/docs/workflow.md index 95b1422..e134584 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -18,6 +18,8 @@ You may follow the link on your PR to view the build log and find the links to d These images are referred to as build artifacts and are available for download directly from the [**build jobs page at Gitlab**](https://gitlab.com/publiclab/image-builder-rpi/-/jobs). +The build matching the documentation you are currently viewing is https://gitlab.com/publiclab/image-builder-rpi/-/jobs/{{ CI_JOB }}/artifacts/browse. + ## Flash your image Using your preferred method (or the [Hypriot flash tool](https://github.com/hypriot/flash), which offers some flash-time customization hooks). From 270bff543573f945c3285e7ae80be8425945faa5 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 02:09:26 -0500 Subject: [PATCH 14/20] Build docs for all branches --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 949b7b7..2b404d8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -33,5 +33,5 @@ pages: artifacts: paths: - builder/files/var/www/docs - only: - - master +# only: +# - master From d2b1cbea56795c61973b2bd106c7d21283ff5590 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 02:14:46 -0500 Subject: [PATCH 15/20] Try escaping sed sequence --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2b404d8..05f3f1d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,7 @@ pages: - npm install gitbook-cli -g # install gitbook - gitbook fetch latest # fetch latest stable version - gitbook install docs # add any requested plugins in book.json - - sed 's/{{ CI_JOB }}/${CI_JOB}/g' docs/workflow.md + - sed \'s/{{ CI_JOB }}/${CI_JOB}/g\' docs/workflow.md script: - gitbook build docs builder/files/var/www/docs # build to public path artifacts: From dbf9af7a8522e7f298c857cc241d824aa559341d Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 02:23:16 -0500 Subject: [PATCH 16/20] Stop trying to link to image --- .gitlab-ci.yml | 1 - docs/workflow.md | 2 -- 2 files changed, 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 05f3f1d..61243dc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,6 @@ pages: - npm install gitbook-cli -g # install gitbook - gitbook fetch latest # fetch latest stable version - gitbook install docs # add any requested plugins in book.json - - sed \'s/{{ CI_JOB }}/${CI_JOB}/g\' docs/workflow.md script: - gitbook build docs builder/files/var/www/docs # build to public path artifacts: diff --git a/docs/workflow.md b/docs/workflow.md index e134584..95b1422 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -18,8 +18,6 @@ You may follow the link on your PR to view the build log and find the links to d These images are referred to as build artifacts and are available for download directly from the [**build jobs page at Gitlab**](https://gitlab.com/publiclab/image-builder-rpi/-/jobs). -The build matching the documentation you are currently viewing is https://gitlab.com/publiclab/image-builder-rpi/-/jobs/{{ CI_JOB }}/artifacts/browse. - ## Flash your image Using your preferred method (or the [Hypriot flash tool](https://github.com/hypriot/flash), which offers some flash-time customization hooks). From 3da8e4066ed482ef753fb379d69e30e55f5cb06c Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 18:53:02 -0500 Subject: [PATCH 17/20] New section on scripting --- docs/SUMMARY.md | 1 + docs/scripting.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 docs/scripting.md diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index d52dc05..40000d1 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -3,4 +3,5 @@ * [Image Builder](README.md) * [Customization](customization.md) * [Workflow](workflow.md) +* [Scripting](scripting.md) * [Roadmap](roadmap.md) diff --git a/docs/scripting.md b/docs/scripting.md new file mode 100644 index 0000000..3042f88 --- /dev/null +++ b/docs/scripting.md @@ -0,0 +1,30 @@ +# Scripting + +The operating system installed is Raspbian Lite, a derivative of the popular Debian GNU/Linux distribution. Please refer to the Debian documentation for most configuration needs. *This section attempts to introduce basic recipes to make use of scripts*. + +You'll need to access the terminal emulator in order to execute scripts (or schedule them). You may access the console with a SSH client or from the web terminal (if available). You may also copy files from and into the device with an SFTP client (such as `scp`). + +# Writing scripts + +Scripts can be written in any language included with Raspbian. The default shell is called **bash** and it's common among GNU/Linux systems. + +In Debian, you may place custom scripts in the `/usr/local/bin` directory. This will make it available to all users. +Scripts should have execution privileges enabled. Execution privileges are granted with the `chmod a+x script.sh` (where `script.sh` is the script file). + +**Tip**: If you are trying to run a script located in the current directory, you'll need to call it like this: `./my_script.sh` (with "./" to indicate the current directory) + +# Running scripts on startup + +Once your scripts are properly installed in the `/usr/local/bin` directory and work as intended, you may want to start them at boot time. You may do so by adding a line to `/etc/rc.local` which is run at the end of the boot process. + +# Scheduling scripts to be run at intervals + +It's possible to use the Cron daemon to schedule tasks either from root or as a user. Use the command `crontab -e` to edit the current users's cron entry. The basic syntax for a cron entry is: + +`minute hour day-of-month month day-of-week user command` + +Refer to the Cron manual for details (`man cron`). + +# Running a script every few seconds + +Try the `watch` command. It works as `watch -n seconds command` and runs a given command repeatedly and continually. From 3192f9871ba8753669f397a7f97d51bb01712b20 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 19:07:53 -0500 Subject: [PATCH 18/20] Add custom scripts folder --- builder/build.sh | 1 + scripts/timelapse.sh | 5 +++++ 2 files changed, 6 insertions(+) create mode 100755 scripts/timelapse.sh diff --git a/builder/build.sh b/builder/build.sh index eaf17f2..3844369 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -59,6 +59,7 @@ mount -t sysfs none ${BUILD_PATH}/sys # modify/add image files directly cp -R /builder/files/* ${BUILD_PATH}/ +cp -R /scripts/* ${BUILD_PATH}/usr/local/bin/ # make our build directory the current root # and install the Rasberry Pi firmware, kernel packages, diff --git a/scripts/timelapse.sh b/scripts/timelapse.sh new file mode 100755 index 0000000..3fd6bd5 --- /dev/null +++ b/scripts/timelapse.sh @@ -0,0 +1,5 @@ +while true +do + echo 'im' >> /var/www/cam/FIFO + sleep 5 +done From 3660c582cbc6e810e606557eabfc709ef3e6503b Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 19:36:30 -0500 Subject: [PATCH 19/20] Move scripts into builder directory --- builder/build.sh | 2 +- {scripts => builder/scripts}/timelapse.sh | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename {scripts => builder/scripts}/timelapse.sh (100%) diff --git a/builder/build.sh b/builder/build.sh index 3844369..6d56ce8 100755 --- a/builder/build.sh +++ b/builder/build.sh @@ -59,7 +59,7 @@ mount -t sysfs none ${BUILD_PATH}/sys # modify/add image files directly cp -R /builder/files/* ${BUILD_PATH}/ -cp -R /scripts/* ${BUILD_PATH}/usr/local/bin/ +cp -R /builder/scripts/* ${BUILD_PATH}/usr/local/bin/ # make our build directory the current root # and install the Rasberry Pi firmware, kernel packages, diff --git a/scripts/timelapse.sh b/builder/scripts/timelapse.sh similarity index 100% rename from scripts/timelapse.sh rename to builder/scripts/timelapse.sh From 648dae3ff8d5cbb55e7eac5c65cc3f412488746a Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Tue, 9 Oct 2018 20:59:58 -0500 Subject: [PATCH 20/20] Copy to public dir --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61243dc..d9aa876 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,8 +29,10 @@ pages: - gitbook install docs # add any requested plugins in book.json script: - gitbook build docs builder/files/var/www/docs # build to public path + after_script: + - cp -ar builder/files/var/www/docs public artifacts: paths: - - builder/files/var/www/docs + - public # only: # - master