From c2c1e3ffe39a557613a4f770b292cc66ca82c969 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 09:39:38 -0500 Subject: [PATCH 01/29] fix source for s3 --- .drone.yml | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index 23465945..7ffa3e99 100644 --- a/.drone.yml +++ b/.drone.yml @@ -68,8 +68,9 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: /**/build/* # build/* - target: / #strip_prefix: build/ + source: build/* # + target: / + strip_prefix: build/ when: branch: exclude: @@ -113,8 +114,9 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: /**/build/* # build/* - target: / #strip_prefix: build/ + source: build/* + target: / + strip_prefix: build/ when: branch: - master @@ -198,8 +200,9 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: /**/build/* # build/* - target: / #strip_prefix: build/ + source: build/* + target: / + strip_prefix: build/ when: branch: exclude: @@ -243,8 +246,9 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: /**/build/* # build/* - target: / #strip_prefix: build/ + source: build/* + target: / + strip_prefix: build/ when: branch: - master @@ -257,7 +261,7 @@ volumes: host: path: /var/run/docker.sock -#AWS STUFF HERE +#AWS SETUP # steps: # - name: upload # image: plugins/s3 From 0152e6ed232f6b25ec3be29b13a1c340619d568c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 09:51:26 -0500 Subject: [PATCH 02/29] fix source for s3 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 7ffa3e99..d3c68790 100644 --- a/.drone.yml +++ b/.drone.yml @@ -68,7 +68,7 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: build/* # + source: build/* target: / strip_prefix: build/ when: From de3386c1c50237d3e23b537f715516fa64c20f90 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 19:54:30 -0500 Subject: [PATCH 03/29] fix target for s3 experiment --- .drone.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index d3c68790..f9cfedde 100644 --- a/.drone.yml +++ b/.drone.yml @@ -68,8 +68,8 @@ steps: from_secret: aws_id secret_key: from_secret: aws_secret - source: build/* - target: / + source: build/* + target: experiment strip_prefix: build/ when: branch: @@ -115,7 +115,7 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: / + target: / strip_prefix: build/ when: branch: @@ -201,7 +201,7 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: / + target: experiment strip_prefix: build/ when: branch: @@ -247,7 +247,7 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: / + target: / strip_prefix: build/ when: branch: From 7d2e4835d16b6915288fa6080909e83b261ab22a Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 20:17:30 -0500 Subject: [PATCH 04/29] mirrordirector, revert after build --- scripts.d/05_mirrors.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts.d/05_mirrors.sh b/scripts.d/05_mirrors.sh index 4d3fb7d4..58220690 100755 --- a/scripts.d/05_mirrors.sh +++ b/scripts.d/05_mirrors.sh @@ -7,7 +7,7 @@ if uname -m | grep -q "aarch64" ; then fi cat << EOF > mnt/img_root/etc/apt/sources.list -deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi +deb http://mirrordirector.raspbian.org/ buster main contrib non-free rpi #deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi From 5aefbd074b7b71c015c2b8dee200e26aae4a864e Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 20:17:47 -0500 Subject: [PATCH 05/29] mirrordirector, revert after build --- scripts.d/50_mirrors_default.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 scripts.d/50_mirrors_default.sh diff --git a/scripts.d/50_mirrors_default.sh b/scripts.d/50_mirrors_default.sh new file mode 100644 index 00000000..9bb67fb2 --- /dev/null +++ b/scripts.d/50_mirrors_default.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +source lib.sh + +if uname -m | grep -q "aarch64" ; then + exit 0 +fi + +cat << EOF > mnt/img_root/etc/apt/sources.list +deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi +#deb http://mirrordirector.raspbian.org/ buster main contrib non-free rpi +# Uncomment line below then 'apt-get update' to enable 'apt-get source' +#deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi +EOF \ No newline at end of file From 6761cf31ab70a032f5107dd5adab9555d0274c6c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 20:18:04 -0500 Subject: [PATCH 06/29] mirrordirector, revert after build --- scripts.d/50_mirrors_default.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts.d/50_mirrors_default.sh diff --git a/scripts.d/50_mirrors_default.sh b/scripts.d/50_mirrors_default.sh old mode 100644 new mode 100755 From 84914ca6d236d0712724425a9e3fa43faa5bd7d3 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 20:18:51 -0500 Subject: [PATCH 07/29] mirrordirector, revert after build --- scripts.d/50_mirrors_default.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts.d/50_mirrors_default.sh b/scripts.d/50_mirrors_default.sh index 9bb67fb2..2218bd07 100755 --- a/scripts.d/50_mirrors_default.sh +++ b/scripts.d/50_mirrors_default.sh @@ -11,4 +11,6 @@ deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi #deb http://mirrordirector.raspbian.org/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi -EOF \ No newline at end of file +EOF + +_apt update || die "Could not update package sources" \ No newline at end of file From 43b678c89d246e5cc3b77e11ba01da5674cbc0c9 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 20:41:09 -0500 Subject: [PATCH 08/29] mirrordirector url fix --- scripts.d/05_mirrors.sh | 2 +- scripts.d/50_mirrors_default.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts.d/05_mirrors.sh b/scripts.d/05_mirrors.sh index 58220690..f48478f5 100755 --- a/scripts.d/05_mirrors.sh +++ b/scripts.d/05_mirrors.sh @@ -7,7 +7,7 @@ if uname -m | grep -q "aarch64" ; then fi cat << EOF > mnt/img_root/etc/apt/sources.list -deb http://mirrordirector.raspbian.org/ buster main contrib non-free rpi +deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi #deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi diff --git a/scripts.d/50_mirrors_default.sh b/scripts.d/50_mirrors_default.sh index 2218bd07..d4ddad8e 100755 --- a/scripts.d/50_mirrors_default.sh +++ b/scripts.d/50_mirrors_default.sh @@ -8,7 +8,7 @@ fi cat << EOF > mnt/img_root/etc/apt/sources.list deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi -#deb http://mirrordirector.raspbian.org/ buster main contrib non-free rpi +#deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi EOF From ff66d2a285f0fb39fd0c7a0e64f2bbcf7ff2c8c5 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 21:10:48 -0500 Subject: [PATCH 09/29] revert mirrors before script 50 --- scripts.d/{50_mirrors_default.sh => 40_mirrors_default.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts.d/{50_mirrors_default.sh => 40_mirrors_default.sh} (100%) diff --git a/scripts.d/50_mirrors_default.sh b/scripts.d/40_mirrors_default.sh similarity index 100% rename from scripts.d/50_mirrors_default.sh rename to scripts.d/40_mirrors_default.sh From 4a52cf3daaf55ddb8e98e5d69e646a5b99f3a0b7 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 21:25:24 -0500 Subject: [PATCH 10/29] use mirrordirector, berkeley commented --- scripts.d/05_mirrors.sh | 1 + scripts.d/40_mirrors_default.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/scripts.d/05_mirrors.sh b/scripts.d/05_mirrors.sh index f48478f5..8412f68a 100755 --- a/scripts.d/05_mirrors.sh +++ b/scripts.d/05_mirrors.sh @@ -8,6 +8,7 @@ fi cat << EOF > mnt/img_root/etc/apt/sources.list deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi +#deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi #deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi diff --git a/scripts.d/40_mirrors_default.sh b/scripts.d/40_mirrors_default.sh index d4ddad8e..2ee0b354 100755 --- a/scripts.d/40_mirrors_default.sh +++ b/scripts.d/40_mirrors_default.sh @@ -8,6 +8,7 @@ fi cat << EOF > mnt/img_root/etc/apt/sources.list deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi +#deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi #deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi From 8640fc1b1b001550c73354578f1fd5b6c23ffce4 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 21:39:51 -0500 Subject: [PATCH 11/29] balena arm64 --- scripts.d/20_balena.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts.d/20_balena.sh b/scripts.d/20_balena.sh index 817cd06e..ce7e1a55 100755 --- a/scripts.d/20_balena.sh +++ b/scripts.d/20_balena.sh @@ -8,6 +8,14 @@ echo "Balena installation" releases=$(curl -s https://api.github.com/repos/balena-os/balena-engine/releases/latest -H "Authorization: token $GITHUB_KEY" | jq -r ".assets[].browser_download_url") armv6link=$(echo "$releases" | tr " " "\\n" | grep armv6) armv7link=$(echo "$releases" | tr " " "\\n" | grep armv7) +arm64link=$(echo "$releases" | tr " " "\\n" | grep aarch64) + +# arm64 +wget -c "$arm64link" +tar xvzf "$(basename "$arm64link")" ./balena-engine/balena-engine +mv balena-engine/balena-engine mnt/img_root/usr/bin/balena-engine-aarch64 +_op _chroot chown root:root /usr/bin/balena-engine-aarch64 +rm -rf balena-engine/ # armv7 wget -c "$armv7link" From 14c9467b70cc26174c74285bb9c5d0e804103664 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Wed, 5 Aug 2020 21:53:16 -0500 Subject: [PATCH 12/29] berkeley mirrors, remove mirrordirector --- scripts.d/05_mirrors.sh | 3 +-- scripts.d/40_mirrors_default.sh | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts.d/05_mirrors.sh b/scripts.d/05_mirrors.sh index 8412f68a..4d3fb7d4 100755 --- a/scripts.d/05_mirrors.sh +++ b/scripts.d/05_mirrors.sh @@ -7,8 +7,7 @@ if uname -m | grep -q "aarch64" ; then fi cat << EOF > mnt/img_root/etc/apt/sources.list -deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi -#deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi +deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi #deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi diff --git a/scripts.d/40_mirrors_default.sh b/scripts.d/40_mirrors_default.sh index 2ee0b354..d8cdc2c8 100755 --- a/scripts.d/40_mirrors_default.sh +++ b/scripts.d/40_mirrors_default.sh @@ -9,7 +9,6 @@ fi cat << EOF > mnt/img_root/etc/apt/sources.list deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi #deb http://mirrors.ocf.berkeley.edu/raspbian/raspbian buster main contrib non-free rpi -#deb http://mirrordirector.raspbian.org/raspbian/ buster main contrib non-free rpi # Uncomment line below then 'apt-get update' to enable 'apt-get source' #deb-src http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi EOF From 6b29b4e4a1d2e6a389f210c4eaccad817f3e8b6c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Thu, 6 Aug 2020 02:48:09 -0500 Subject: [PATCH 13/29] re-arrange deployment --- .drone.yml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.drone.yml b/.drone.yml index f9cfedde..0b2b37e2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -32,7 +32,7 @@ steps: - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --armhf' # --arm64 or --armhf, need to implement in builder -- name: deploy-experiment +- name: deploy-master image: balenalib/armv7hf-golang volumes: - name: dockersock @@ -54,13 +54,12 @@ steps: - .drone/upload.sh when: branch: - exclude: - - master + - master event: include: - tag -- name: s3-experiment +- name: s3-master image: plugins/s3 settings: bucket: treehouses @@ -69,17 +68,16 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: experiment strip_prefix: build/ + target: / when: branch: - exclude: - - master + - master event: include: - tag -- name: deploy-master +- name: deploy-experiment image: balenalib/armv7hf-golang volumes: - name: dockersock @@ -101,12 +99,13 @@ steps: - .drone/upload.sh when: branch: - - master + exclude: + - master event: include: - tag -- name: s3-master +- name: s3-experiment image: plugins/s3 settings: bucket: treehouses @@ -115,11 +114,12 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: / strip_prefix: build/ + target: experiment when: branch: - - master + exclude: + - master event: include: - tag @@ -164,7 +164,7 @@ steps: - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --arm64' -- name: deploy-experiment +- name: deploy-master image: balenalib/aarch64-golang volumes: - name: dockersock @@ -186,13 +186,12 @@ steps: - .drone/upload.sh when: branch: - exclude: - - master + - master event: include: - tag -- name: s3-experiment +- name: s3-master image: plugins/s3 settings: bucket: treehouses @@ -201,17 +200,16 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: experiment strip_prefix: build/ + target: / when: branch: - exclude: - - master + - master event: include: - tag -- name: deploy-master +- name: deploy-experiment image: balenalib/aarch64-golang volumes: - name: dockersock @@ -233,12 +231,13 @@ steps: - .drone/upload.sh when: branch: - - master + exclude: + - master event: include: - tag -- name: s3-master +- name: s3-experiment image: plugins/s3 settings: bucket: treehouses @@ -247,11 +246,12 @@ steps: secret_key: from_secret: aws_secret source: build/* - target: / strip_prefix: build/ + target: experiment when: branch: - - master + exclude: + - master event: include: - tag From ac002f4b2753eff2fba278715d02d5b82b35e19c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Thu, 6 Aug 2020 04:08:08 -0500 Subject: [PATCH 14/29] first trial --- .drone.yml | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/.drone.yml b/.drone.yml index 0b2b37e2..3dee2f15 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,7 +7,7 @@ platform: steps: - name: build - image: balenalib/armv7hf-golang + image: johndockenson/runner-armhf volumes: - name: dockersock path: /var/run/docker.sock @@ -19,21 +19,12 @@ steps: - git fetch --tags - df -h - losetup -a - - apt-get update - - apt-get dist-upgrade -y - - apt-get install kpartx parted wget curl jq aria2 unzip python3 python3-pip qemu-user-static dmsetup g++-arm-linux-gnueabihf nodejs npm git apt-transport-https ca-certificates gnupg-agent software-properties-common -y - - curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - - - apt-key fingerprint 0EBFCD88 - - add-apt-repository "deb [arch=armhf] https://download.docker.com/linux/debian $(lsb_release -cs) stable" - - apt-get update - - apt-get install docker-ce -y - - python3 -m pip install requests - dmsetup remove_all - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --armhf' # --arm64 or --armhf, need to implement in builder - name: deploy-master - image: balenalib/armv7hf-golang + image: johndockenson/runner-armhf volumes: - name: dockersock path: /var/run/docker.sock @@ -43,8 +34,6 @@ steps: privileged: true commands: - pwd - - apt-get update - - apt-get install rsync git ssh -y #- git fetch --tags - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - .drone/environment.sh @@ -78,7 +67,7 @@ steps: - tag - name: deploy-experiment - image: balenalib/armv7hf-golang + image: johndockenson/runner-armhf volumes: - name: dockersock path: /var/run/docker.sock @@ -88,8 +77,6 @@ steps: privileged: true commands: - pwd - - apt-get update - - apt-get install rsync git ssh -y #- git fetch --tags - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - .drone/environment.sh @@ -139,7 +126,7 @@ platform: steps: - name: build - image: balenalib/aarch64-golang + image: johndockenson/runner-arm64 volumes: - name: dockersock path: /var/run/docker.sock @@ -151,21 +138,12 @@ steps: - git fetch --tags - df -h - losetup -a - - apt-get update - - apt-get dist-upgrade -y - - apt-get install kpartx parted wget curl jq aria2 unzip python3 python3-pip qemu-user-static dmsetup g++-aarch64-linux-gnu nodejs npm git apt-transport-https ca-certificates gnupg-agent software-properties-common -y - - curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - - - apt-key fingerprint 0EBFCD88 - - add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" - - apt-get update - - apt-get install docker-ce -y - - python3 -m pip install requests - dmsetup remove_all - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --arm64' - name: deploy-master - image: balenalib/aarch64-golang + image: johndockenson/runner-arm64 volumes: - name: dockersock path: /var/run/docker.sock @@ -175,8 +153,6 @@ steps: privileged: true commands: - pwd - - apt-get update - - apt-get install rsync git ssh -y #- git fetch --tags - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - .drone/environment.sh @@ -210,7 +186,7 @@ steps: - tag - name: deploy-experiment - image: balenalib/aarch64-golang + image: johndockenson/runner-arm64 volumes: - name: dockersock path: /var/run/docker.sock @@ -220,8 +196,6 @@ steps: privileged: true commands: - pwd - - apt-get update - - apt-get install rsync git ssh -y #- git fetch --tags - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - .drone/environment.sh From 2e0822e29aa142343ea9f71a01dab8e0f35f60b2 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Thu, 6 Aug 2020 04:28:54 -0500 Subject: [PATCH 15/29] comments --- .drone.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3dee2f15..bed82bd9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,7 +39,7 @@ steps: - .drone/environment.sh - echo "$experiment" - echo "$image_path" - - .drone/compress.sh + - .drone/compress.sh #split these steps! - .drone/upload.sh when: branch: @@ -82,7 +82,7 @@ steps: - .drone/environment.sh - echo "$experiment" - echo "$image_path" - - .drone/compress.sh + - .drone/compress.sh #split these steps! - .drone/upload.sh when: branch: @@ -158,7 +158,7 @@ steps: - .drone/environment.sh - echo "$experiment" - echo "$image_path" - - .drone/compress.sh + - .drone/compress.sh #split these steps! - .drone/upload.sh when: branch: @@ -201,7 +201,7 @@ steps: - .drone/environment.sh - echo "$experiment" - echo "$image_path" - - .drone/compress.sh + - .drone/compress.sh #split these steps! - .drone/upload.sh when: branch: From c31ebb8bf8506791ff150053f11d4d0bd5ab2661 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Fri, 7 Aug 2020 23:19:12 -0500 Subject: [PATCH 16/29] fix install directory --- scripts.d/20_install_autorun.sh | 22 ++ scripts.d/20_install_balena_service.sh | 38 +++ scripts.d/20_install_balena_socket.sh | 16 ++ scripts.d/20_install_bluetooth.sh | 20 ++ scripts.d/20_install_do_autorun.sh | 206 ++++++++++++++++ scripts.d/20_install_files copy.sh | 7 + scripts.d/20_install_files.sh | 323 +------------------------ scripts.d/20_install_rclocal.sh | 30 +++ 8 files changed, 341 insertions(+), 321 deletions(-) create mode 100755 scripts.d/20_install_autorun.sh create mode 100755 scripts.d/20_install_balena_service.sh create mode 100755 scripts.d/20_install_balena_socket.sh create mode 100755 scripts.d/20_install_bluetooth.sh create mode 100755 scripts.d/20_install_do_autorun.sh create mode 100755 scripts.d/20_install_files copy.sh create mode 100755 scripts.d/20_install_rclocal.sh diff --git a/scripts.d/20_install_autorun.sh b/scripts.d/20_install_autorun.sh new file mode 100755 index 00000000..7349b1b3 --- /dev/null +++ b/scripts.d/20_install_autorun.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +source lib.sh + +cat << EOF > mnt/img_root/etc/systemd/system/autorun.service +[Unit] +Description=run autorun(once)(.sh) scripts from USB stick or in /boot +After=local_fs.target remote_fs.target network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/do_autorun start +Restart=no + +[Install] +WantedBy=multi-user.target + +EOF + +mkdir -p "mnt/img_root/etc/systemd/system/multi-user.target.wants" +_op _chroot ln -sr mnt/img_root/etc/systemd/system/autorun.service mnt/img_root/etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file diff --git a/scripts.d/20_install_balena_service.sh b/scripts.d/20_install_balena_service.sh new file mode 100755 index 00000000..a8e099d2 --- /dev/null +++ b/scripts.d/20_install_balena_service.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +cat << EOF > mnt/img_root/etc/systemd/system/balena.service +[Unit] +Description=Balena Application Container Engine +Documentation=https://www.balena.io/engine/ +After=network-online.target balena.socket firewalld.service +Wants=network-online.target +Requires=balena.socket + +[Service] +Type=notify +# the default is not to use systemd for cgroups because the delegate issues still +# exists and systemd currently does not support the cgroup feature set required +# for containers run by balena +ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=1048576 +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNPROC=infinity +LimitCORE=infinity +# Uncomment TasksMax if your systemd version supports it. +# Only systemd 226 and above support this version. +#TasksMax=infinity +TimeoutStartSec=0 +# set delegate yes so that systemd does not reset the cgroups of balena containers +Delegate=yes +# kill only the balena process, not all processes in the cgroup +KillMode=process +# restart the balena process if it exits prematurely +Restart=on-failure +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target +EOF \ No newline at end of file diff --git a/scripts.d/20_install_balena_socket.sh b/scripts.d/20_install_balena_socket.sh new file mode 100755 index 00000000..60396d51 --- /dev/null +++ b/scripts.d/20_install_balena_socket.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cat << EOF > mnt/img_root/etc/systemd/system/balena.socket +[Unit] +Description=Balena Socket for the API +PartOf=balena.service + +[Socket] +ListenStream=/var/run/balena.sock +SocketMode=0660 +SocketUser=root +SocketGroup=balena + +[Install] +WantedBy=sockets.target +EOF \ No newline at end of file diff --git a/scripts.d/20_install_bluetooth.sh b/scripts.d/20_install_bluetooth.sh new file mode 100755 index 00000000..37c1e03e --- /dev/null +++ b/scripts.d/20_install_bluetooth.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +cat << EOF > mnt/img_root/etc/systemd/system/rpibluetooth.service +[Unit] +Description=Bluetooth server +After=rpibluetooth.service +Requires=rpibluetooth.service bluetooth.service + +StartLimitIntervalSec=500 +StartLimitBurst=5 + +[Service] +Restart=always +RestartSec=5s + +ExecStart=/usr/bin/python3 /usr/local/bin/bluetooth-server.py & + +[Install] +WantedBy=multi-user.target +EOF \ No newline at end of file diff --git a/scripts.d/20_install_do_autorun.sh b/scripts.d/20_install_do_autorun.sh new file mode 100755 index 00000000..963951b2 --- /dev/null +++ b/scripts.d/20_install_do_autorun.sh @@ -0,0 +1,206 @@ +#!/bin/bash + +cat << EOF > mnt/img_root/usr/local/bin/do_autorun +#!/bin/bash + +rebootrequired=0 + +led_mode() { + mode="$1" + trigger=/sys/class/leds/led0/trigger + [ -e $trigger ] && echo "$mode" > $trigger +} + +log() { + echo "do_autorun:" "$@" +} + +find_script() { + base_name="$1" + + for ext in "" .sh .txt; do + script="$base_name$ext" + + if [ -e "$script" ]; then + echo "$script" + return + fi + done +} + +wifiunblock(){ + if [[ $(rfkill list wifi -o soft -n) == "blocked" ]]; then + rfkill unblock wifi + log "wifi unblocked" + fi +} + +autorunonce(){ + log "searching for autorunonce script" + script=$(find_script "$1/autorunonce") + + if [ -z "$script" ]; then + log "no autorunonce found" + return 1 + fi + + newname="$(basename "$script" | sed -e 's/run/ran/')" + newscript="$(dirname "$script")/$newname" + log "moving autorunonce script: $script -> $newscript" + mv -v "$script" "$newscript" + log "converting dos newlines to unix" + dos2unix "$newscript" + sync + log "running autorunonce script $script" + led_mode timer + bash "$newscript" + log "autorunonce script is done" +} + +autorun(){ + log "searching for autorun script" + script=$(find_script "$1/autorun") + + if [ -z "$script" ]; then + log "no autorun script found" + return 1 + fi + + log "converting dos newlines to unix" + dos2unix "$script" + + log "running autorun script $script" + led_mode heartbeat + sudo screen -dmS treehouses bash -c 'sudo '"$script" + log "autorun script started in screen" +} + +onenodeforall() { + arch=$(uname -m) + log "onenodeforall" + if [ "$arch" == "armv6l" ] + then + log "$arch - rpi0/1" + if [ "$(readlink -- /usr/bin/node)" != "node-armv6l" ] + then + unlink /usr/bin/node + ln -sr /usr/bin/node-armv6l /usr/bin/node + fi + elif [ "$arch" == "armv7l" ] + then + log "$arch - rpi2/3" + if [ "$(readlink -- /usr/bin/node)" != "node-armv7l" ] + then + unlink /usr/bin/node + ln -sr /usr/bin/node-armv7l /usr/bin/node + fi + else + log "$arch - something went wrong" + fi +} + +onebalenaforall() { + arch=$(uname -m) + log "onebalenaforall" + if [ "$arch" == "armv6l" ] + then + log "$arch - rpi0/1" + if [ "$(readlink -- /usr/bin/balena)" != "balena-engine-armv6l" ] + then + unlink /usr/bin/balena-engine + ln -sr /usr/bin/balena-engine-armv6l /usr/bin/balena-engine + fi + elif [ "$arch" == "armv7l" ] + then + log "$arch - rpi2/3" + if [ "$(readlink -- /usr/bin/balena-engine)" != "balena-engine-armv7l" ] + then + unlink /usr/bin/balena-engine + ln -sr /usr/bin/balena-engine-armv7l /usr/bin/balena-engine + fi + else + log "$arch - something went wrong" + fi +} + +usbgadget() { + case "$(treehouses detectrpi)" in + RPIZ|RPIZW) + if grep -q -w "^#dtoverlay=dwc2" /boot/config.txt + then + sed -i -e 's/#dtoverlay=dwc2/dtoverlay=dwc2/g' /boot/config.txt + rebootrequired=1 + fi + + if grep -q "#modules-load=dwc2,g_ether" /boot/cmdline.txt + then + sed -i -e 's/#modules-load=dwc2,g_ether/modules-load=dwc2,g_ether/g' /boot/cmdline.txt + rebootrequired=1 + fi + ;; + *) + if grep -q -w "^dtoverlay=dwc2" /boot/config.txt + then + sed -i -e 's/dtoverlay=dwc2/#dtoverlay=dwc2/g' /boot/config.txt + rebootrequired=1 + fi + + if grep -q " modules-load=dwc2,g_ether" /boot/cmdline.txt + then + sed -i -e 's/ modules-load=dwc2,g_ether/ #modules-load=dwc2,g_ether/g' /boot/cmdline.txt + rebootrequired=1 + fi + esac +} + +start() { + led_mode default-on + log "starting" + wifiunblock + usbgadget + onenodeforall + onebalenaforall + if [[ rebootrequired -eq 1 ]] + then + reboot + fi + mkdir -p /data + if [ -b /dev/sda1 ] + then + log "usb stick" + mountpoint -q /data || mount /dev/sda1 /data + cd /data || exit 1 + autorunonce /data || autorun /data + else + log "no usb stick" + cd /boot || exit 1 + autorunonce /boot || autorun /boot + fi +} + +stop() { + log "stopping" + sudo screen -X -S "treehouses" quit +} + + +# Some things that run always +touch /var/lock/autorun + +# Carry out specific functions when asked to by the system +case "$1" in + start) + start + ;; + stop) + stop + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac + +exit 0 + +EOF \ No newline at end of file diff --git a/scripts.d/20_install_files copy.sh b/scripts.d/20_install_files copy.sh new file mode 100755 index 00000000..05543824 --- /dev/null +++ b/scripts.d/20_install_files copy.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +exit 0 + +source lib.sh +echo "Installing files" +#(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root \ No newline at end of file diff --git a/scripts.d/20_install_files.sh b/scripts.d/20_install_files.sh index ee1fde27..5a2c027c 100755 --- a/scripts.d/20_install_files.sh +++ b/scripts.d/20_install_files.sh @@ -1,327 +1,8 @@ #!/bin/bash -source lib.sh +#source lib.sh echo "Installing files" -#(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root - -cat << EOF > /etc/rc.local -#!/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. - -# Print the IP address -_IP=$(hostname -I) || true -if [ "$_IP" ]; then - printf "My IP address is %s\n" "$_IP" -fi - -if [ -f "/etc/tunnel" ]; -then - /etc/tunnel -fi - -exit 0 -EOF - -cat << EOF > /usr/local/bin/do_autorun -#!/bin/bash - -rebootrequired=0 - -led_mode() { - mode="$1" - trigger=/sys/class/leds/led0/trigger - [ -e $trigger ] && echo "$mode" > $trigger -} - -log() { - echo "do_autorun:" "$@" -} - -find_script() { - base_name="$1" - - for ext in "" .sh .txt; do - script="$base_name$ext" - - if [ -e "$script" ]; then - echo "$script" - return - fi - done -} - -wifiunblock(){ - if [[ $(rfkill list wifi -o soft -n) == "blocked" ]]; then - rfkill unblock wifi - log "wifi unblocked" - fi -} - -autorunonce(){ - log "searching for autorunonce script" - script=$(find_script "$1/autorunonce") - - if [ -z "$script" ]; then - log "no autorunonce found" - return 1 - fi - - newname="$(basename "$script" | sed -e 's/run/ran/')" - newscript="$(dirname "$script")/$newname" - log "moving autorunonce script: $script -> $newscript" - mv -v "$script" "$newscript" - log "converting dos newlines to unix" - dos2unix "$newscript" - sync - log "running autorunonce script $script" - led_mode timer - bash "$newscript" - log "autorunonce script is done" -} - -autorun(){ - log "searching for autorun script" - script=$(find_script "$1/autorun") - - if [ -z "$script" ]; then - log "no autorun script found" - return 1 - fi - - log "converting dos newlines to unix" - dos2unix "$script" - - log "running autorun script $script" - led_mode heartbeat - sudo screen -dmS treehouses bash -c 'sudo '"$script" - log "autorun script started in screen" -} - -onenodeforall() { - arch=$(uname -m) - log "onenodeforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/node)" != "node-armv6l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv6l /usr/bin/node - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/node)" != "node-armv7l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv7l /usr/bin/node - fi - else - log "$arch - something went wrong" - fi -} - -onebalenaforall() { - arch=$(uname -m) - log "onebalenaforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/balena)" != "balena-engine-armv6l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv6l /usr/bin/balena-engine - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/balena-engine)" != "balena-engine-armv7l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv7l /usr/bin/balena-engine - fi - else - log "$arch - something went wrong" - fi -} - -usbgadget() { - case "$(treehouses detectrpi)" in - RPIZ|RPIZW) - if grep -q -w "^#dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/#dtoverlay=dwc2/dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q "#modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/#modules-load=dwc2,g_ether/modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - ;; - *) - if grep -q -w "^dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/dtoverlay=dwc2/#dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q " modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/ modules-load=dwc2,g_ether/ #modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - esac -} - -start() { - led_mode default-on - log "starting" - wifiunblock - usbgadget - onenodeforall - onebalenaforall - if [[ rebootrequired -eq 1 ]] - then - reboot - fi - mkdir -p /data - if [ -b /dev/sda1 ] - then - log "usb stick" - mountpoint -q /data || mount /dev/sda1 /data - cd /data || exit 1 - autorunonce /data || autorun /data - else - log "no usb stick" - cd /boot || exit 1 - autorunonce /boot || autorun /boot - fi -} - -stop() { - log "stopping" - sudo screen -X -S "treehouses" quit -} - - -# Some things that run always -touch /var/lock/autorun - -# Carry out specific functions when asked to by the system -case "$1" in - start) - start - ;; - stop) - stop - ;; - *) - echo "Usage: $0 {start|stop}" - exit 1 - ;; -esac exit 0 -EOF - -cat << EOF > /etc/systemd/system/autorun.service -[Unit] -Description=run autorun(once)(.sh) scripts from USB stick or in /boot -After=local_fs.target remote_fs.target network-online.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/local/bin/do_autorun start -Restart=no - -[Install] -WantedBy=multi-user.target - -EOF - -cat << EOF > /etc/systemd/system/balena.service -[Unit] -Description=Balena Application Container Engine -Documentation=https://www.balena.io/engine/ -After=network-online.target balena.socket firewalld.service -Wants=network-online.target -Requires=balena.socket - -[Service] -Type=notify -# the default is not to use systemd for cgroups because the delegate issues still -# exists and systemd currently does not support the cgroup feature set required -# for containers run by balena -ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock -ExecReload=/bin/kill -s HUP $MAINPID -LimitNOFILE=1048576 -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -LimitNPROC=infinity -LimitCORE=infinity -# Uncomment TasksMax if your systemd version supports it. -# Only systemd 226 and above support this version. -#TasksMax=infinity -TimeoutStartSec=0 -# set delegate yes so that systemd does not reset the cgroups of balena containers -Delegate=yes -# kill only the balena process, not all processes in the cgroup -KillMode=process -# restart the balena process if it exits prematurely -Restart=on-failure -StartLimitBurst=3 -StartLimitInterval=60s - -[Install] -WantedBy=multi-user.target -EOF - -cat << EOF > /etc/systemd/system/balena.socket -[Unit] -Description=Balena Socket for the API -PartOf=balena.service - -[Socket] -ListenStream=/var/run/balena.sock -SocketMode=0660 -SocketUser=root -SocketGroup=balena - -[Install] -WantedBy=sockets.target -EOF - -cat << EOF > /etc/systemd/system/rpibluetooth.service -[Unit] -Description=Bluetooth server -After=rpibluetooth.service -Requires=rpibluetooth.service bluetooth.service - -StartLimitIntervalSec=500 -StartLimitBurst=5 - -[Service] -Restart=always -RestartSec=5s - -ExecStart=/usr/bin/python3 /usr/local/bin/bluetooth-server.py & - -[Install] -WantedBy=multi-user.target -EOF -mkdir -p mnt/img_root/etc/systemd/system/multi-user.target -_op _chroot ln -s /etc/systemd/system/autorun.service /etc/systemd/system/multi-user.target/autorun.service \ No newline at end of file +#(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root \ No newline at end of file diff --git a/scripts.d/20_install_rclocal.sh b/scripts.d/20_install_rclocal.sh new file mode 100755 index 00000000..635ed729 --- /dev/null +++ b/scripts.d/20_install_rclocal.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +cat << EOF > mnt/img_root/etc/rc.local +#!/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. + +# Print the IP address +_IP=$(hostname -I) || true +if [ "$_IP" ]; then + printf "My IP address is %s\n" "$_IP" +fi + +if [ -f "/etc/tunnel" ]; +then + /etc/tunnel +fi + +exit 0 + +EOF \ No newline at end of file From 52e56fa2b3c2d74031e1617ad5a8f51e2b4cd5c8 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Fri, 7 Aug 2020 23:19:56 -0500 Subject: [PATCH 17/29] fix install directory, remove old install folder --- install/etc/rc.local | 25 --- install/etc/systemd/system/autorun.service | 12 -- install/etc/systemd/system/balena.service | 34 --- install/etc/systemd/system/balena.socket | 12 -- .../multi-user.target.wants/autorun.service | 1 - .../etc/systemd/system/rpibluetooth.service | 16 -- install/usr/local/bin/do_autorun | 201 ------------------ 7 files changed, 301 deletions(-) delete mode 100644 install/etc/rc.local delete mode 100644 install/etc/systemd/system/autorun.service delete mode 100644 install/etc/systemd/system/balena.service delete mode 100644 install/etc/systemd/system/balena.socket delete mode 120000 install/etc/systemd/system/multi-user.target.wants/autorun.service delete mode 100644 install/etc/systemd/system/rpibluetooth.service delete mode 100755 install/usr/local/bin/do_autorun diff --git a/install/etc/rc.local b/install/etc/rc.local deleted file mode 100644 index f62409de..00000000 --- a/install/etc/rc.local +++ /dev/null @@ -1,25 +0,0 @@ -#!/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. - -# Print the IP address -_IP=$(hostname -I) || true -if [ "$_IP" ]; then - printf "My IP address is %s\n" "$_IP" -fi - -if [ -f "/etc/tunnel" ]; -then - /etc/tunnel -fi - -exit 0 diff --git a/install/etc/systemd/system/autorun.service b/install/etc/systemd/system/autorun.service deleted file mode 100644 index 5f30070a..00000000 --- a/install/etc/systemd/system/autorun.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=run autorun(once)(.sh) scripts from USB stick or in /boot -After=local_fs.target remote_fs.target network-online.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/local/bin/do_autorun start -Restart=no - -[Install] -WantedBy=multi-user.target diff --git a/install/etc/systemd/system/balena.service b/install/etc/systemd/system/balena.service deleted file mode 100644 index 4003289e..00000000 --- a/install/etc/systemd/system/balena.service +++ /dev/null @@ -1,34 +0,0 @@ -[Unit] -Description=Balena Application Container Engine -Documentation=https://www.balena.io/engine/ -After=network-online.target balena.socket firewalld.service -Wants=network-online.target -Requires=balena.socket - -[Service] -Type=notify -# the default is not to use systemd for cgroups because the delegate issues still -# exists and systemd currently does not support the cgroup feature set required -# for containers run by balena -ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock -ExecReload=/bin/kill -s HUP $MAINPID -LimitNOFILE=1048576 -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -LimitNPROC=infinity -LimitCORE=infinity -# Uncomment TasksMax if your systemd version supports it. -# Only systemd 226 and above support this version. -#TasksMax=infinity -TimeoutStartSec=0 -# set delegate yes so that systemd does not reset the cgroups of balena containers -Delegate=yes -# kill only the balena process, not all processes in the cgroup -KillMode=process -# restart the balena process if it exits prematurely -Restart=on-failure -StartLimitBurst=3 -StartLimitInterval=60s - -[Install] -WantedBy=multi-user.target diff --git a/install/etc/systemd/system/balena.socket b/install/etc/systemd/system/balena.socket deleted file mode 100644 index 8583cad2..00000000 --- a/install/etc/systemd/system/balena.socket +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Balena Socket for the API -PartOf=balena.service - -[Socket] -ListenStream=/var/run/balena.sock -SocketMode=0660 -SocketUser=root -SocketGroup=balena - -[Install] -WantedBy=sockets.target \ No newline at end of file diff --git a/install/etc/systemd/system/multi-user.target.wants/autorun.service b/install/etc/systemd/system/multi-user.target.wants/autorun.service deleted file mode 120000 index cf87e656..00000000 --- a/install/etc/systemd/system/multi-user.target.wants/autorun.service +++ /dev/null @@ -1 +0,0 @@ -/etc/systemd/system/autorun.service \ No newline at end of file diff --git a/install/etc/systemd/system/rpibluetooth.service b/install/etc/systemd/system/rpibluetooth.service deleted file mode 100644 index 47be8912..00000000 --- a/install/etc/systemd/system/rpibluetooth.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=Bluetooth server -After=rpibluetooth.service -Requires=rpibluetooth.service bluetooth.service - -StartLimitIntervalSec=500 -StartLimitBurst=5 - -[Service] -Restart=always -RestartSec=5s - -ExecStart=/usr/bin/python3 /usr/local/bin/bluetooth-server.py & - -[Install] -WantedBy=multi-user.target diff --git a/install/usr/local/bin/do_autorun b/install/usr/local/bin/do_autorun deleted file mode 100755 index 174d1aca..00000000 --- a/install/usr/local/bin/do_autorun +++ /dev/null @@ -1,201 +0,0 @@ -#!/bin/bash - -rebootrequired=0 - -led_mode() { - mode="$1" - trigger=/sys/class/leds/led0/trigger - [ -e $trigger ] && echo "$mode" > $trigger -} - -log() { - echo "do_autorun:" "$@" -} - -find_script() { - base_name="$1" - - for ext in "" .sh .txt; do - script="$base_name$ext" - - if [ -e "$script" ]; then - echo "$script" - return - fi - done -} - -wifiunblock(){ - if [[ $(rfkill list wifi -o soft -n) == "blocked" ]]; then - rfkill unblock wifi - log "wifi unblocked" - fi -} - -autorunonce(){ - log "searching for autorunonce script" - script=$(find_script "$1/autorunonce") - - if [ -z "$script" ]; then - log "no autorunonce found" - return 1 - fi - - newname="$(basename "$script" | sed -e 's/run/ran/')" - newscript="$(dirname "$script")/$newname" - log "moving autorunonce script: $script -> $newscript" - mv -v "$script" "$newscript" - log "converting dos newlines to unix" - dos2unix "$newscript" - sync - log "running autorunonce script $script" - led_mode timer - bash "$newscript" - log "autorunonce script is done" -} - -autorun(){ - log "searching for autorun script" - script=$(find_script "$1/autorun") - - if [ -z "$script" ]; then - log "no autorun script found" - return 1 - fi - - log "converting dos newlines to unix" - dos2unix "$script" - - log "running autorun script $script" - led_mode heartbeat - sudo screen -dmS treehouses bash -c 'sudo '"$script" - log "autorun script started in screen" -} - -onenodeforall() { - arch=$(uname -m) - log "onenodeforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/node)" != "node-armv6l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv6l /usr/bin/node - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/node)" != "node-armv7l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv7l /usr/bin/node - fi - else - log "$arch - something went wrong" - fi -} - -onebalenaforall() { - arch=$(uname -m) - log "onebalenaforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/balena)" != "balena-engine-armv6l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv6l /usr/bin/balena-engine - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/balena-engine)" != "balena-engine-armv7l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv7l /usr/bin/balena-engine - fi - else - log "$arch - something went wrong" - fi -} - -usbgadget() { - case "$(treehouses detectrpi)" in - RPIZ|RPIZW) - if grep -q -w "^#dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/#dtoverlay=dwc2/dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q "#modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/#modules-load=dwc2,g_ether/modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - ;; - *) - if grep -q -w "^dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/dtoverlay=dwc2/#dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q " modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/ modules-load=dwc2,g_ether/ #modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - esac -} - -start() { - led_mode default-on - log "starting" - wifiunblock - usbgadget - onenodeforall - onebalenaforall - if [[ rebootrequired -eq 1 ]] - then - reboot - fi - mkdir -p /data - if [ -b /dev/sda1 ] - then - log "usb stick" - mountpoint -q /data || mount /dev/sda1 /data - cd /data || exit 1 - autorunonce /data || autorun /data - else - log "no usb stick" - cd /boot || exit 1 - autorunonce /boot || autorun /boot - fi -} - -stop() { - log "stopping" - sudo screen -X -S "treehouses" quit -} - - -# Some things that run always -touch /var/lock/autorun - -# Carry out specific functions when asked to by the system -case "$1" in - start) - start - ;; - stop) - stop - ;; - *) - echo "Usage: $0 {start|stop}" - exit 1 - ;; -esac - -exit 0 From 48d9051761a096691b02bd0a219e6ce7130ee8a0 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Fri, 7 Aug 2020 23:47:02 -0500 Subject: [PATCH 18/29] merge balena scripts --- scripts.d/20_balena.sh | 54 ++++++++++++++++++++++++++ scripts.d/20_install_balena_service.sh | 38 ------------------ scripts.d/20_install_balena_socket.sh | 16 -------- 3 files changed, 54 insertions(+), 54 deletions(-) delete mode 100755 scripts.d/20_install_balena_service.sh delete mode 100755 scripts.d/20_install_balena_socket.sh diff --git a/scripts.d/20_balena.sh b/scripts.d/20_balena.sh index ce7e1a55..9f9cb787 100755 --- a/scripts.d/20_balena.sh +++ b/scripts.d/20_balena.sh @@ -48,3 +48,57 @@ _op _chroot usermod -aG balena root _op _chroot rm -rf /var/lib/balena-engine _op _chroot ln -sr /var/lib/docker /var/lib/balena-engine + +#install balena service scripts + +cat << EOF > mnt/img_root/etc/systemd/system/balena.socket +[Unit] +Description=Balena Socket for the API +PartOf=balena.service + +[Socket] +ListenStream=/var/run/balena.sock +SocketMode=0660 +SocketUser=root +SocketGroup=balena + +[Install] +WantedBy=sockets.target +EOF + +cat << EOF > mnt/img_root/etc/systemd/system/balena.service +[Unit] +Description=Balena Application Container Engine +Documentation=https://www.balena.io/engine/ +After=network-online.target balena.socket firewalld.service +Wants=network-online.target +Requires=balena.socket + +[Service] +Type=notify +# the default is not to use systemd for cgroups because the delegate issues still +# exists and systemd currently does not support the cgroup feature set required +# for containers run by balena +ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=1048576 +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNPROC=infinity +LimitCORE=infinity +# Uncomment TasksMax if your systemd version supports it. +# Only systemd 226 and above support this version. +#TasksMax=infinity +TimeoutStartSec=0 +# set delegate yes so that systemd does not reset the cgroups of balena containers +Delegate=yes +# kill only the balena process, not all processes in the cgroup +KillMode=process +# restart the balena process if it exits prematurely +Restart=on-failure +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target +EOF \ No newline at end of file diff --git a/scripts.d/20_install_balena_service.sh b/scripts.d/20_install_balena_service.sh deleted file mode 100755 index a8e099d2..00000000 --- a/scripts.d/20_install_balena_service.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -cat << EOF > mnt/img_root/etc/systemd/system/balena.service -[Unit] -Description=Balena Application Container Engine -Documentation=https://www.balena.io/engine/ -After=network-online.target balena.socket firewalld.service -Wants=network-online.target -Requires=balena.socket - -[Service] -Type=notify -# the default is not to use systemd for cgroups because the delegate issues still -# exists and systemd currently does not support the cgroup feature set required -# for containers run by balena -ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock -ExecReload=/bin/kill -s HUP $MAINPID -LimitNOFILE=1048576 -# Having non-zero Limit*s causes performance problems due to accounting overhead -# in the kernel. We recommend using cgroups to do container-local accounting. -LimitNPROC=infinity -LimitCORE=infinity -# Uncomment TasksMax if your systemd version supports it. -# Only systemd 226 and above support this version. -#TasksMax=infinity -TimeoutStartSec=0 -# set delegate yes so that systemd does not reset the cgroups of balena containers -Delegate=yes -# kill only the balena process, not all processes in the cgroup -KillMode=process -# restart the balena process if it exits prematurely -Restart=on-failure -StartLimitBurst=3 -StartLimitInterval=60s - -[Install] -WantedBy=multi-user.target -EOF \ No newline at end of file diff --git a/scripts.d/20_install_balena_socket.sh b/scripts.d/20_install_balena_socket.sh deleted file mode 100755 index 60396d51..00000000 --- a/scripts.d/20_install_balena_socket.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -cat << EOF > mnt/img_root/etc/systemd/system/balena.socket -[Unit] -Description=Balena Socket for the API -PartOf=balena.service - -[Socket] -ListenStream=/var/run/balena.sock -SocketMode=0660 -SocketUser=root -SocketGroup=balena - -[Install] -WantedBy=sockets.target -EOF \ No newline at end of file From acf63d5e61aba48805664549958dcbee39931b9d Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Fri, 7 Aug 2020 23:54:13 -0500 Subject: [PATCH 19/29] fix link --- scripts.d/20_install_autorun.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts.d/20_install_autorun.sh b/scripts.d/20_install_autorun.sh index 7349b1b3..97b214d6 100755 --- a/scripts.d/20_install_autorun.sh +++ b/scripts.d/20_install_autorun.sh @@ -19,4 +19,4 @@ WantedBy=multi-user.target EOF mkdir -p "mnt/img_root/etc/systemd/system/multi-user.target.wants" -_op _chroot ln -sr mnt/img_root/etc/systemd/system/autorun.service mnt/img_root/etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file +_op _chroot ln -sr /etc/systemd/system/autorun.service /etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file From 7a31acffe7efb4191258674b016825cacf89b376 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 00:29:13 -0500 Subject: [PATCH 20/29] fix deploy --- .drone.yml | 58 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/.drone.yml b/.drone.yml index bed82bd9..b03ce4c7 100644 --- a/.drone.yml +++ b/.drone.yml @@ -23,7 +23,7 @@ steps: - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --armhf' # --arm64 or --armhf, need to implement in builder -- name: deploy-master +- name: deploy image: johndockenson/runner-armhf volumes: - name: dockersock @@ -66,32 +66,6 @@ steps: include: - tag -- name: deploy-experiment - image: johndockenson/runner-armhf - volumes: - - name: dockersock - path: /var/run/docker.sock - environment: - ssh_deploy_key: - from_secret: ssh_secret - privileged: true - commands: - - pwd - #- git fetch --tags - - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - - .drone/environment.sh - - echo "$experiment" - - echo "$image_path" - - .drone/compress.sh #split these steps! - - .drone/upload.sh - when: - branch: - exclude: - - master - event: - include: - - tag - - name: s3-experiment image: plugins/s3 settings: @@ -142,7 +116,7 @@ steps: - losetup -D - bash -c 'export GITHUB_KEY="$GITHUB_KEY";mkdir images && PATH=./node_modules/.bin:$PATH ./builder --noninteractive --arm64' -- name: deploy-master +- name: deploy image: johndockenson/runner-arm64 volumes: - name: dockersock @@ -161,8 +135,6 @@ steps: - .drone/compress.sh #split these steps! - .drone/upload.sh when: - branch: - - master event: include: - tag @@ -185,32 +157,6 @@ steps: include: - tag -- name: deploy-experiment - image: johndockenson/runner-arm64 - volumes: - - name: dockersock - path: /var/run/docker.sock - environment: - ssh_deploy_key: - from_secret: ssh_secret - privileged: true - commands: - - pwd - #- git fetch --tags - - echo "$ssh_deploy_key" | base64 --decode --ignore-garbage > .drone/id_deploy - - .drone/environment.sh - - echo "$experiment" - - echo "$image_path" - - .drone/compress.sh #split these steps! - - .drone/upload.sh - when: - branch: - exclude: - - master - event: - include: - - tag - - name: s3-experiment image: plugins/s3 settings: From 4ba6f4b2da14a84528b2f7d868bc0e826a53335e Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 01:56:43 -0500 Subject: [PATCH 21/29] fix link --- scripts.d/20_install_autorun.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts.d/20_install_autorun.sh b/scripts.d/20_install_autorun.sh index 97b214d6..6a5c10a4 100755 --- a/scripts.d/20_install_autorun.sh +++ b/scripts.d/20_install_autorun.sh @@ -19,4 +19,4 @@ WantedBy=multi-user.target EOF mkdir -p "mnt/img_root/etc/systemd/system/multi-user.target.wants" -_op _chroot ln -sr /etc/systemd/system/autorun.service /etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file +_op _chroot ln -sn /etc/systemd/system/autorun.service /etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file From 008cc09f488bf06b82d6e545ff413415967015fa Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 02:25:41 -0500 Subject: [PATCH 22/29] revert to old install folder --- .../etc/rc.local | 5 - install/etc/systemd/system/autorun.service | 12 + install/etc/systemd/system/balena.service | 34 +++ install/etc/systemd/system/balena.socket | 12 + scripts.d/20_install_autorun.sh | 22 -- scripts.d/20_install_bluetooth.sh | 20 -- scripts.d/20_install_do_autorun.sh | 206 ------------------ scripts.d/20_install_files copy.sh | 7 - scripts.d/20_install_files.sh | 7 +- 9 files changed, 60 insertions(+), 265 deletions(-) rename scripts.d/20_install_rclocal.sh => install/etc/rc.local (89%) mode change 100755 => 100644 create mode 100644 install/etc/systemd/system/autorun.service create mode 100644 install/etc/systemd/system/balena.service create mode 100644 install/etc/systemd/system/balena.socket delete mode 100755 scripts.d/20_install_autorun.sh delete mode 100755 scripts.d/20_install_bluetooth.sh delete mode 100755 scripts.d/20_install_do_autorun.sh delete mode 100755 scripts.d/20_install_files copy.sh mode change 100755 => 100644 scripts.d/20_install_files.sh diff --git a/scripts.d/20_install_rclocal.sh b/install/etc/rc.local old mode 100755 new mode 100644 similarity index 89% rename from scripts.d/20_install_rclocal.sh rename to install/etc/rc.local index 635ed729..f62409de --- a/scripts.d/20_install_rclocal.sh +++ b/install/etc/rc.local @@ -1,6 +1,3 @@ -#!/bin/bash - -cat << EOF > mnt/img_root/etc/rc.local #!/bin/sh -e # # rc.local @@ -26,5 +23,3 @@ then fi exit 0 - -EOF \ No newline at end of file diff --git a/install/etc/systemd/system/autorun.service b/install/etc/systemd/system/autorun.service new file mode 100644 index 00000000..5f30070a --- /dev/null +++ b/install/etc/systemd/system/autorun.service @@ -0,0 +1,12 @@ +[Unit] +Description=run autorun(once)(.sh) scripts from USB stick or in /boot +After=local_fs.target remote_fs.target network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/do_autorun start +Restart=no + +[Install] +WantedBy=multi-user.target diff --git a/install/etc/systemd/system/balena.service b/install/etc/systemd/system/balena.service new file mode 100644 index 00000000..4003289e --- /dev/null +++ b/install/etc/systemd/system/balena.service @@ -0,0 +1,34 @@ +[Unit] +Description=Balena Application Container Engine +Documentation=https://www.balena.io/engine/ +After=network-online.target balena.socket firewalld.service +Wants=network-online.target +Requires=balena.socket + +[Service] +Type=notify +# the default is not to use systemd for cgroups because the delegate issues still +# exists and systemd currently does not support the cgroup feature set required +# for containers run by balena +ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=1048576 +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNPROC=infinity +LimitCORE=infinity +# Uncomment TasksMax if your systemd version supports it. +# Only systemd 226 and above support this version. +#TasksMax=infinity +TimeoutStartSec=0 +# set delegate yes so that systemd does not reset the cgroups of balena containers +Delegate=yes +# kill only the balena process, not all processes in the cgroup +KillMode=process +# restart the balena process if it exits prematurely +Restart=on-failure +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/install/etc/systemd/system/balena.socket b/install/etc/systemd/system/balena.socket new file mode 100644 index 00000000..8583cad2 --- /dev/null +++ b/install/etc/systemd/system/balena.socket @@ -0,0 +1,12 @@ +[Unit] +Description=Balena Socket for the API +PartOf=balena.service + +[Socket] +ListenStream=/var/run/balena.sock +SocketMode=0660 +SocketUser=root +SocketGroup=balena + +[Install] +WantedBy=sockets.target \ No newline at end of file diff --git a/scripts.d/20_install_autorun.sh b/scripts.d/20_install_autorun.sh deleted file mode 100755 index 6a5c10a4..00000000 --- a/scripts.d/20_install_autorun.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -source lib.sh - -cat << EOF > mnt/img_root/etc/systemd/system/autorun.service -[Unit] -Description=run autorun(once)(.sh) scripts from USB stick or in /boot -After=local_fs.target remote_fs.target network-online.target - -[Service] -Type=oneshot -RemainAfterExit=yes -ExecStart=/usr/local/bin/do_autorun start -Restart=no - -[Install] -WantedBy=multi-user.target - -EOF - -mkdir -p "mnt/img_root/etc/systemd/system/multi-user.target.wants" -_op _chroot ln -sn /etc/systemd/system/autorun.service /etc/systemd/system/multi-user.target.wants/autorun.service \ No newline at end of file diff --git a/scripts.d/20_install_bluetooth.sh b/scripts.d/20_install_bluetooth.sh deleted file mode 100755 index 37c1e03e..00000000 --- a/scripts.d/20_install_bluetooth.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -cat << EOF > mnt/img_root/etc/systemd/system/rpibluetooth.service -[Unit] -Description=Bluetooth server -After=rpibluetooth.service -Requires=rpibluetooth.service bluetooth.service - -StartLimitIntervalSec=500 -StartLimitBurst=5 - -[Service] -Restart=always -RestartSec=5s - -ExecStart=/usr/bin/python3 /usr/local/bin/bluetooth-server.py & - -[Install] -WantedBy=multi-user.target -EOF \ No newline at end of file diff --git a/scripts.d/20_install_do_autorun.sh b/scripts.d/20_install_do_autorun.sh deleted file mode 100755 index 963951b2..00000000 --- a/scripts.d/20_install_do_autorun.sh +++ /dev/null @@ -1,206 +0,0 @@ -#!/bin/bash - -cat << EOF > mnt/img_root/usr/local/bin/do_autorun -#!/bin/bash - -rebootrequired=0 - -led_mode() { - mode="$1" - trigger=/sys/class/leds/led0/trigger - [ -e $trigger ] && echo "$mode" > $trigger -} - -log() { - echo "do_autorun:" "$@" -} - -find_script() { - base_name="$1" - - for ext in "" .sh .txt; do - script="$base_name$ext" - - if [ -e "$script" ]; then - echo "$script" - return - fi - done -} - -wifiunblock(){ - if [[ $(rfkill list wifi -o soft -n) == "blocked" ]]; then - rfkill unblock wifi - log "wifi unblocked" - fi -} - -autorunonce(){ - log "searching for autorunonce script" - script=$(find_script "$1/autorunonce") - - if [ -z "$script" ]; then - log "no autorunonce found" - return 1 - fi - - newname="$(basename "$script" | sed -e 's/run/ran/')" - newscript="$(dirname "$script")/$newname" - log "moving autorunonce script: $script -> $newscript" - mv -v "$script" "$newscript" - log "converting dos newlines to unix" - dos2unix "$newscript" - sync - log "running autorunonce script $script" - led_mode timer - bash "$newscript" - log "autorunonce script is done" -} - -autorun(){ - log "searching for autorun script" - script=$(find_script "$1/autorun") - - if [ -z "$script" ]; then - log "no autorun script found" - return 1 - fi - - log "converting dos newlines to unix" - dos2unix "$script" - - log "running autorun script $script" - led_mode heartbeat - sudo screen -dmS treehouses bash -c 'sudo '"$script" - log "autorun script started in screen" -} - -onenodeforall() { - arch=$(uname -m) - log "onenodeforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/node)" != "node-armv6l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv6l /usr/bin/node - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/node)" != "node-armv7l" ] - then - unlink /usr/bin/node - ln -sr /usr/bin/node-armv7l /usr/bin/node - fi - else - log "$arch - something went wrong" - fi -} - -onebalenaforall() { - arch=$(uname -m) - log "onebalenaforall" - if [ "$arch" == "armv6l" ] - then - log "$arch - rpi0/1" - if [ "$(readlink -- /usr/bin/balena)" != "balena-engine-armv6l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv6l /usr/bin/balena-engine - fi - elif [ "$arch" == "armv7l" ] - then - log "$arch - rpi2/3" - if [ "$(readlink -- /usr/bin/balena-engine)" != "balena-engine-armv7l" ] - then - unlink /usr/bin/balena-engine - ln -sr /usr/bin/balena-engine-armv7l /usr/bin/balena-engine - fi - else - log "$arch - something went wrong" - fi -} - -usbgadget() { - case "$(treehouses detectrpi)" in - RPIZ|RPIZW) - if grep -q -w "^#dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/#dtoverlay=dwc2/dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q "#modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/#modules-load=dwc2,g_ether/modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - ;; - *) - if grep -q -w "^dtoverlay=dwc2" /boot/config.txt - then - sed -i -e 's/dtoverlay=dwc2/#dtoverlay=dwc2/g' /boot/config.txt - rebootrequired=1 - fi - - if grep -q " modules-load=dwc2,g_ether" /boot/cmdline.txt - then - sed -i -e 's/ modules-load=dwc2,g_ether/ #modules-load=dwc2,g_ether/g' /boot/cmdline.txt - rebootrequired=1 - fi - esac -} - -start() { - led_mode default-on - log "starting" - wifiunblock - usbgadget - onenodeforall - onebalenaforall - if [[ rebootrequired -eq 1 ]] - then - reboot - fi - mkdir -p /data - if [ -b /dev/sda1 ] - then - log "usb stick" - mountpoint -q /data || mount /dev/sda1 /data - cd /data || exit 1 - autorunonce /data || autorun /data - else - log "no usb stick" - cd /boot || exit 1 - autorunonce /boot || autorun /boot - fi -} - -stop() { - log "stopping" - sudo screen -X -S "treehouses" quit -} - - -# Some things that run always -touch /var/lock/autorun - -# Carry out specific functions when asked to by the system -case "$1" in - start) - start - ;; - stop) - stop - ;; - *) - echo "Usage: $0 {start|stop}" - exit 1 - ;; -esac - -exit 0 - -EOF \ No newline at end of file diff --git a/scripts.d/20_install_files copy.sh b/scripts.d/20_install_files copy.sh deleted file mode 100755 index 05543824..00000000 --- a/scripts.d/20_install_files copy.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -exit 0 - -source lib.sh -echo "Installing files" -#(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root \ No newline at end of file diff --git a/scripts.d/20_install_files.sh b/scripts.d/20_install_files.sh old mode 100755 new mode 100644 index 5a2c027c..b2316eb8 --- a/scripts.d/20_install_files.sh +++ b/scripts.d/20_install_files.sh @@ -1,8 +1,5 @@ #!/bin/bash -#source lib.sh +source lib.sh echo "Installing files" - -exit 0 - -#(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root \ No newline at end of file +(cd install || die "ERROR: install folder doesn't exist, exiting"; tar c .) | _op _chroot tar vx --owner=root --group=root \ No newline at end of file From 9e48e242ed978f06d60b7090213cf759e5a03e6f Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 02:28:44 -0500 Subject: [PATCH 23/29] revert to old install folder --- install/etc/install/etc/rc.local | 25 +++ .../etc/systemd/system/autorun.service | 12 ++ .../install/etc/systemd/system/balena.service | 34 +++ .../install/etc/systemd/system/balena.socket | 12 ++ .../multi-user.target.wants/autorun.service | 1 + .../etc/systemd/system/rpibluetooth.service | 16 ++ install/usr/local/bin/do_autorun | 201 ++++++++++++++++++ 7 files changed, 301 insertions(+) create mode 100644 install/etc/install/etc/rc.local create mode 100644 install/etc/install/etc/systemd/system/autorun.service create mode 100644 install/etc/install/etc/systemd/system/balena.service create mode 100644 install/etc/install/etc/systemd/system/balena.socket create mode 120000 install/etc/systemd/system/multi-user.target.wants/autorun.service create mode 100644 install/etc/systemd/system/rpibluetooth.service create mode 100755 install/usr/local/bin/do_autorun diff --git a/install/etc/install/etc/rc.local b/install/etc/install/etc/rc.local new file mode 100644 index 00000000..f62409de --- /dev/null +++ b/install/etc/install/etc/rc.local @@ -0,0 +1,25 @@ +#!/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. + +# Print the IP address +_IP=$(hostname -I) || true +if [ "$_IP" ]; then + printf "My IP address is %s\n" "$_IP" +fi + +if [ -f "/etc/tunnel" ]; +then + /etc/tunnel +fi + +exit 0 diff --git a/install/etc/install/etc/systemd/system/autorun.service b/install/etc/install/etc/systemd/system/autorun.service new file mode 100644 index 00000000..5f30070a --- /dev/null +++ b/install/etc/install/etc/systemd/system/autorun.service @@ -0,0 +1,12 @@ +[Unit] +Description=run autorun(once)(.sh) scripts from USB stick or in /boot +After=local_fs.target remote_fs.target network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/local/bin/do_autorun start +Restart=no + +[Install] +WantedBy=multi-user.target diff --git a/install/etc/install/etc/systemd/system/balena.service b/install/etc/install/etc/systemd/system/balena.service new file mode 100644 index 00000000..4003289e --- /dev/null +++ b/install/etc/install/etc/systemd/system/balena.service @@ -0,0 +1,34 @@ +[Unit] +Description=Balena Application Container Engine +Documentation=https://www.balena.io/engine/ +After=network-online.target balena.socket firewalld.service +Wants=network-online.target +Requires=balena.socket + +[Service] +Type=notify +# the default is not to use systemd for cgroups because the delegate issues still +# exists and systemd currently does not support the cgroup feature set required +# for containers run by balena +ExecStart=/usr/bin/balena-engine-daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/balena-engine.sock +ExecReload=/bin/kill -s HUP $MAINPID +LimitNOFILE=1048576 +# Having non-zero Limit*s causes performance problems due to accounting overhead +# in the kernel. We recommend using cgroups to do container-local accounting. +LimitNPROC=infinity +LimitCORE=infinity +# Uncomment TasksMax if your systemd version supports it. +# Only systemd 226 and above support this version. +#TasksMax=infinity +TimeoutStartSec=0 +# set delegate yes so that systemd does not reset the cgroups of balena containers +Delegate=yes +# kill only the balena process, not all processes in the cgroup +KillMode=process +# restart the balena process if it exits prematurely +Restart=on-failure +StartLimitBurst=3 +StartLimitInterval=60s + +[Install] +WantedBy=multi-user.target diff --git a/install/etc/install/etc/systemd/system/balena.socket b/install/etc/install/etc/systemd/system/balena.socket new file mode 100644 index 00000000..8583cad2 --- /dev/null +++ b/install/etc/install/etc/systemd/system/balena.socket @@ -0,0 +1,12 @@ +[Unit] +Description=Balena Socket for the API +PartOf=balena.service + +[Socket] +ListenStream=/var/run/balena.sock +SocketMode=0660 +SocketUser=root +SocketGroup=balena + +[Install] +WantedBy=sockets.target \ No newline at end of file diff --git a/install/etc/systemd/system/multi-user.target.wants/autorun.service b/install/etc/systemd/system/multi-user.target.wants/autorun.service new file mode 120000 index 00000000..cf87e656 --- /dev/null +++ b/install/etc/systemd/system/multi-user.target.wants/autorun.service @@ -0,0 +1 @@ +/etc/systemd/system/autorun.service \ No newline at end of file diff --git a/install/etc/systemd/system/rpibluetooth.service b/install/etc/systemd/system/rpibluetooth.service new file mode 100644 index 00000000..47be8912 --- /dev/null +++ b/install/etc/systemd/system/rpibluetooth.service @@ -0,0 +1,16 @@ +[Unit] +Description=Bluetooth server +After=rpibluetooth.service +Requires=rpibluetooth.service bluetooth.service + +StartLimitIntervalSec=500 +StartLimitBurst=5 + +[Service] +Restart=always +RestartSec=5s + +ExecStart=/usr/bin/python3 /usr/local/bin/bluetooth-server.py & + +[Install] +WantedBy=multi-user.target diff --git a/install/usr/local/bin/do_autorun b/install/usr/local/bin/do_autorun new file mode 100755 index 00000000..174d1aca --- /dev/null +++ b/install/usr/local/bin/do_autorun @@ -0,0 +1,201 @@ +#!/bin/bash + +rebootrequired=0 + +led_mode() { + mode="$1" + trigger=/sys/class/leds/led0/trigger + [ -e $trigger ] && echo "$mode" > $trigger +} + +log() { + echo "do_autorun:" "$@" +} + +find_script() { + base_name="$1" + + for ext in "" .sh .txt; do + script="$base_name$ext" + + if [ -e "$script" ]; then + echo "$script" + return + fi + done +} + +wifiunblock(){ + if [[ $(rfkill list wifi -o soft -n) == "blocked" ]]; then + rfkill unblock wifi + log "wifi unblocked" + fi +} + +autorunonce(){ + log "searching for autorunonce script" + script=$(find_script "$1/autorunonce") + + if [ -z "$script" ]; then + log "no autorunonce found" + return 1 + fi + + newname="$(basename "$script" | sed -e 's/run/ran/')" + newscript="$(dirname "$script")/$newname" + log "moving autorunonce script: $script -> $newscript" + mv -v "$script" "$newscript" + log "converting dos newlines to unix" + dos2unix "$newscript" + sync + log "running autorunonce script $script" + led_mode timer + bash "$newscript" + log "autorunonce script is done" +} + +autorun(){ + log "searching for autorun script" + script=$(find_script "$1/autorun") + + if [ -z "$script" ]; then + log "no autorun script found" + return 1 + fi + + log "converting dos newlines to unix" + dos2unix "$script" + + log "running autorun script $script" + led_mode heartbeat + sudo screen -dmS treehouses bash -c 'sudo '"$script" + log "autorun script started in screen" +} + +onenodeforall() { + arch=$(uname -m) + log "onenodeforall" + if [ "$arch" == "armv6l" ] + then + log "$arch - rpi0/1" + if [ "$(readlink -- /usr/bin/node)" != "node-armv6l" ] + then + unlink /usr/bin/node + ln -sr /usr/bin/node-armv6l /usr/bin/node + fi + elif [ "$arch" == "armv7l" ] + then + log "$arch - rpi2/3" + if [ "$(readlink -- /usr/bin/node)" != "node-armv7l" ] + then + unlink /usr/bin/node + ln -sr /usr/bin/node-armv7l /usr/bin/node + fi + else + log "$arch - something went wrong" + fi +} + +onebalenaforall() { + arch=$(uname -m) + log "onebalenaforall" + if [ "$arch" == "armv6l" ] + then + log "$arch - rpi0/1" + if [ "$(readlink -- /usr/bin/balena)" != "balena-engine-armv6l" ] + then + unlink /usr/bin/balena-engine + ln -sr /usr/bin/balena-engine-armv6l /usr/bin/balena-engine + fi + elif [ "$arch" == "armv7l" ] + then + log "$arch - rpi2/3" + if [ "$(readlink -- /usr/bin/balena-engine)" != "balena-engine-armv7l" ] + then + unlink /usr/bin/balena-engine + ln -sr /usr/bin/balena-engine-armv7l /usr/bin/balena-engine + fi + else + log "$arch - something went wrong" + fi +} + +usbgadget() { + case "$(treehouses detectrpi)" in + RPIZ|RPIZW) + if grep -q -w "^#dtoverlay=dwc2" /boot/config.txt + then + sed -i -e 's/#dtoverlay=dwc2/dtoverlay=dwc2/g' /boot/config.txt + rebootrequired=1 + fi + + if grep -q "#modules-load=dwc2,g_ether" /boot/cmdline.txt + then + sed -i -e 's/#modules-load=dwc2,g_ether/modules-load=dwc2,g_ether/g' /boot/cmdline.txt + rebootrequired=1 + fi + ;; + *) + if grep -q -w "^dtoverlay=dwc2" /boot/config.txt + then + sed -i -e 's/dtoverlay=dwc2/#dtoverlay=dwc2/g' /boot/config.txt + rebootrequired=1 + fi + + if grep -q " modules-load=dwc2,g_ether" /boot/cmdline.txt + then + sed -i -e 's/ modules-load=dwc2,g_ether/ #modules-load=dwc2,g_ether/g' /boot/cmdline.txt + rebootrequired=1 + fi + esac +} + +start() { + led_mode default-on + log "starting" + wifiunblock + usbgadget + onenodeforall + onebalenaforall + if [[ rebootrequired -eq 1 ]] + then + reboot + fi + mkdir -p /data + if [ -b /dev/sda1 ] + then + log "usb stick" + mountpoint -q /data || mount /dev/sda1 /data + cd /data || exit 1 + autorunonce /data || autorun /data + else + log "no usb stick" + cd /boot || exit 1 + autorunonce /boot || autorun /boot + fi +} + +stop() { + log "stopping" + sudo screen -X -S "treehouses" quit +} + + +# Some things that run always +touch /var/lock/autorun + +# Carry out specific functions when asked to by the system +case "$1" in + start) + start + ;; + stop) + stop + ;; + *) + echo "Usage: $0 {start|stop}" + exit 1 + ;; +esac + +exit 0 From 4218e33049a41fc1eaa7071f65383c44341bf76a Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 02:31:27 -0500 Subject: [PATCH 24/29] revert to old install folder, chmod install script --- scripts.d/20_install_files.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts.d/20_install_files.sh diff --git a/scripts.d/20_install_files.sh b/scripts.d/20_install_files.sh old mode 100644 new mode 100755 From 6a5dfb0ca9084b24d65d1ab58de5bee9270e315c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 02:35:03 -0500 Subject: [PATCH 25/29] fix deploy oopsie --- .drone.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index b03ce4c7..5f0e685e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -42,8 +42,6 @@ steps: - .drone/compress.sh #split these steps! - .drone/upload.sh when: - branch: - - master event: include: - tag From 1ec24456893fcba935019d51f582e7ee362b9a58 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 04:41:42 -0500 Subject: [PATCH 26/29] try planet --- scripts.d/40_planet.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts.d/40_planet.sh b/scripts.d/40_planet.sh index 2276c40d..eb5c79f6 100755 --- a/scripts.d/40_planet.sh +++ b/scripts.d/40_planet.sh @@ -1,7 +1,5 @@ #!/bin/bash -exit 0 - source lib.sh planetdir='tenalp' From 3c349fc606c94f6c1465b27391a39cfab7cf9f61 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sat, 8 Aug 2020 04:55:15 -0500 Subject: [PATCH 27/29] netcat-openbsd --- scripts.d/16_pkg_install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts.d/16_pkg_install.sh b/scripts.d/16_pkg_install.sh index a2f5f80c..8dc594f8 100755 --- a/scripts.d/16_pkg_install.sh +++ b/scripts.d/16_pkg_install.sh @@ -39,6 +39,7 @@ INSTALL_PACKAGES=( libhdf5-dev libatlas-base-dev libqt4-test # opencv libjasper1 imagemagick # tiv python3-bcrypt python3-nacl # fix slow pip + netcat-openbsd # ssh ) ARMHF_PACKAGES=( #packages which do not work on arm64 From 1209971851e2416cf663d15b4fe5df40d096c03c Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sun, 9 Aug 2020 12:32:41 -0500 Subject: [PATCH 28/29] cleanup --- .drone.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5f0e685e..d59620e5 100644 --- a/.drone.yml +++ b/.drone.yml @@ -178,19 +178,6 @@ volumes: - name: dockersock host: path: /var/run/docker.sock - -#AWS SETUP -# steps: -# - name: upload -# image: plugins/s3 -# settings: -# bucket: my-bucket-name -# access_key: -# from_secret: aws_access_key_id -# secret_key: -# from_secret: aws_secret_access_key -# source: public/**/* -# target: /target/location --- kind: secret From a2b66759214ab428299b7cb5f14f162a20ab8d97 Mon Sep 17 00:00:00 2001 From: ComputerOnFire Date: Sun, 9 Aug 2020 13:16:00 -0500 Subject: [PATCH 29/29] cleanup, cancel planet --- scripts.d/40_planet.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts.d/40_planet.sh b/scripts.d/40_planet.sh index eb5c79f6..2276c40d 100755 --- a/scripts.d/40_planet.sh +++ b/scripts.d/40_planet.sh @@ -1,5 +1,7 @@ #!/bin/bash +exit 0 + source lib.sh planetdir='tenalp'