diff --git a/.gitignore b/.gitignore index a6883c2049..fa5e1d68e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,3 @@ -deploy/* -work/* -config -postrun.sh -SKIP -SKIP_IMAGES -.pc -*-pc -apt-cacher-ng/ +*.secret +work/ +deploy/ diff --git a/README.md b/README.md index 19c2615391..4a6434a4ba 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,28 @@ Upon execution, `build.sh` will source the file `config` in the current working directory. This bash shell fragment is intended to set needed environment variables. +You can use your own configs with the command line switch +`sudo ./build.sh -c config.path.secret`. If the suffix is `.secret` +it'll be ignored by git, via .gitignore. + +A sample config is as follows: + +```bash +. config + +IMG_NAME="${IMG_NAME}-sample" + +TARGET_HOSTNAME=sth-pi +FIRST_USER_NAME=pi +ENABLE_SSH=1 +# PUBKEY_SSH_FIRST_USER="" +PUBKEY_ONLY_SSH=1 + +WPA_ESSID="" +WPA_PASSWORD="" +WPA_COUNTRY=PL +``` + The following environment variables are supported: * `IMG_NAME` **required** (Default: unset) diff --git a/README2.md b/README2.md new file mode 100644 index 0000000000..0c3c7f736f --- /dev/null +++ b/README2.md @@ -0,0 +1,73 @@ +## Preparing the environment for image building + +Linux will be required to build the image, so WSL is recommended for windows users. + + +## Dependencies +The whole process need to be started with the installation of all required dependecies: + + +```bash +apt-get install coreutils quilt parted qemu-user-static debootstrap zerofree zip \ +dosfstools libarchive-tools libcap2-bin grep rsync xz-utils file git curl bc \ +qemu-utils kpartx gpg pigz +``` + +The file depends contains a list of tools needed. The format of this package is [:]. + + +## Getting started with building your images + +Getting started is as simple as cloning this scramjet's fork on your build machine. You can do so with: + +```bash +git clone git@github.com:scramjetorg/pi-gen.git +``` + +We then proceed to build the image. The whole process is done with the command, this may take a while: + + + +```bash +./build.sh -c config +``` + +## Burning disc image +After the successful build, "deploy" folder will appear with the images. + +Now use the [Imager](https://www.raspberrypi.com/software/) and under "Select OS" select "Custom OS" and then select the "-rasppi-os-sth.img" file from the deploy folder you created. +Also, remember to set your network access for the device in the imager options. + +Once the process is complete, two partitions should appear on your drive - boot and deploy. + +## Config self-hosted-hub + +Go to the scramjet cloud platform panel page and generate a configuration file for self-hosted-hub. Copy its contents and paste it into the file contained in the directory deploy/config/sth-config.json + +![1](./assets/1.1.png) +![2](./assets/1.2.png) +![3](./assets/1.3.png) +![4](./assets/1.4.png) + + +Load the card with the configured image into your device and connect it to the power supply. After a while, a new self-hosted-hub should appear in your panel. + + +Now to control the hub using the command line, you need to install "cli" and generate the appropriate config, which will allow access to the hub. + +![1 1](./assets/2.1.png) +![2 1](./assets/2.2.png) +![3 1](./assets/2.3.png) + + + + + + + +## :boom: Troubleshooting :boom:: +1. WSL, there may be a problem with WSL, because of the lack of the certain function. This problem is often associated with the "HyperV". +So to fix it, there is a need to enable HyperV in "Turn Windows features on or off" section. + +2. After burning the image on SD card there may be a problem with accessing the partition with the "conf" folder. To solve this problem, there is a need +to add a new letter for the partition of the disk in "Disk management" diff --git a/assets/1.1.png b/assets/1.1.png new file mode 100644 index 0000000000..5abf49a573 Binary files /dev/null and b/assets/1.1.png differ diff --git a/assets/1.2.png b/assets/1.2.png new file mode 100644 index 0000000000..c41a6d8aa1 Binary files /dev/null and b/assets/1.2.png differ diff --git a/assets/1.3.png b/assets/1.3.png new file mode 100644 index 0000000000..5e5c86a819 Binary files /dev/null and b/assets/1.3.png differ diff --git a/assets/1.4.png b/assets/1.4.png new file mode 100644 index 0000000000..0c1fc16188 Binary files /dev/null and b/assets/1.4.png differ diff --git a/assets/2.1.png b/assets/2.1.png new file mode 100644 index 0000000000..3fe3714d9b Binary files /dev/null and b/assets/2.1.png differ diff --git a/assets/2.2.png b/assets/2.2.png new file mode 100644 index 0000000000..e807a7d972 Binary files /dev/null and b/assets/2.2.png differ diff --git a/assets/2.3.png b/assets/2.3.png new file mode 100644 index 0000000000..bbe8cf54a8 Binary files /dev/null and b/assets/2.3.png differ diff --git a/build.sh b/build.sh index 986f81cc3b..f737c5dc1f 100755 --- a/build.sh +++ b/build.sh @@ -242,6 +242,10 @@ export TIMEZONE_DEFAULT="${TIMEZONE_DEFAULT:-Europe/London}" export GIT_HASH=${GIT_HASH:-"$(git rev-parse HEAD)"} +export WORK_PARTITION_SIZE=${WORK_PARTITION_SIZE:-8192} +export DEPLOY_PARTITION_SIZE=${DEPLOY_PARTITION_SIZE:-4096} +export ROOT_PART_EXTRA_SPACE=${ROOT_PART_EXTRA_SPACE:-8192} + export PUBKEY_SSH_FIRST_USER export CLEAN diff --git a/config b/config new file mode 100644 index 0000000000..1ddbc80926 --- /dev/null +++ b/config @@ -0,0 +1,7 @@ +IMG_NAME="rasppi-os" +STAGE_LIST=${STAGE_LIST:-"stage0 stage1 stage2 stage99-sth"} + +WORK_PARTITION_SIZE=8192 +DEPLOY_PARTITION_SIZE=1024 + +DEPLOY_COMPRESSION=none diff --git a/export-image/04-set-partuuid/00-run.sh b/export-image/04-set-partuuid/00-run.sh index 16e1b158ef..e8a70d7326 100755 --- a/export-image/04-set-partuuid/00-run.sh +++ b/export-image/04-set-partuuid/00-run.sh @@ -7,10 +7,14 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then IMGID="$(dd if="${IMG_FILE}" skip=440 bs=1 count=4 2>/dev/null | xxd -e | cut -f 2 -d' ')" BOOT_PARTUUID="${IMGID}-01" - ROOT_PARTUUID="${IMGID}-02" + ROOT_PARTUUID="${IMGID}-04" + DEPLOY_PARTUUID="${IMGID}-02" + WORK_PARTUUID="${IMGID}-03" sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" + sed -i "s/DEPLOYDEV/PARTUUID=${DEPLOY_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" + sed -i "s/WORKDEV/PARTUUID=${WORK_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${ROOTFS_DIR}/boot/cmdline.txt" diff --git a/export-image/prerun.sh b/export-image/prerun.sh index 2d8e1bbe27..8512072284 100755 --- a/export-image/prerun.sh +++ b/export-image/prerun.sh @@ -10,8 +10,12 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then rm -rf "${ROOTFS_DIR}" mkdir -p "${ROOTFS_DIR}" - BOOT_SIZE="$((256 * 1024 * 1024))" + MEGABYTE="$((1024 * 1024))" + + BOOT_SIZE="$((256 * $MEGABYTE))" ROOT_SIZE=$(du --apparent-size -s "${EXPORT_ROOTFS_DIR}" --exclude var/cache/apt/archives --exclude boot --block-size=1 | cut -f 1) + WORK_SIZE="$(($WORK_PARTITION_SIZE * $MEGABYTE))" + DEPLOY_SIZE="$(($DEPLOY_PARTITION_SIZE * $MEGABYTE))" # All partition sizes and starts will be aligned to this size ALIGN="$((4 * 1024 * 1024))" @@ -19,20 +23,35 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then # some overhead (since actual space usage is usually rounded up to the # filesystem block size) and gives some free space on the resulting # image. - ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + 200 * 1024 * 1024) / 1" | bc)" + ROOT_MARGIN="$(echo "($ROOT_SIZE * 0.2 + $ROOT_PART_EXTRA_SPACE * ${MEGABYTE}) / 1" | bc)" BOOT_PART_START=$((ALIGN)) BOOT_PART_SIZE=$(((BOOT_SIZE + ALIGN - 1) / ALIGN * ALIGN)) - ROOT_PART_START=$((BOOT_PART_START + BOOT_PART_SIZE)) + DEPLOY_PART_START=$((BOOT_PART_START + BOOT_PART_SIZE)) + DEPLOY_PART_SIZE=$(((DEPLOY_SIZE + ALIGN - 1) / ALIGN * ALIGN)) + WORK_PART_START=$((DEPLOY_PART_START + DEPLOY_PART_SIZE)) + WORK_PART_SIZE=$(((WORK_SIZE + ALIGN - 1) / ALIGN * ALIGN)) + ROOT_PART_START=$((WORK_PART_START + WORK_PART_SIZE)) ROOT_PART_SIZE=$(((ROOT_SIZE + ROOT_MARGIN + ALIGN - 1) / ALIGN * ALIGN)) - IMG_SIZE=$((BOOT_PART_START + BOOT_PART_SIZE + ROOT_PART_SIZE)) + IMG_SIZE=$((BOOT_PART_START + BOOT_PART_SIZE + DEPLOY_PART_SIZE + WORK_PART_SIZE + ROOT_PART_SIZE)) + + echo Creating paritions: + truncate -s "${IMG_SIZE}" "${IMG_FILE}" parted --script "${IMG_FILE}" mklabel msdos + echo BOOT: start="$(($BOOT_PART_START / $MEGABYTE))"MB size="$(( (BOOT_PART_SIZE - 1 ) / $MEGABYTE))"MB parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${BOOT_PART_START}" "$((BOOT_PART_START + BOOT_PART_SIZE - 1))" + echo DEPLOY: start="$(($DEPLOY_PART_START / $MEGABYTE))"MB size="$(( (DEPLOY_PART_SIZE - 1 ) / $MEGABYTE))"MB + parted --script "${IMG_FILE}" unit B mkpart primary fat32 "${DEPLOY_PART_START}" "$((DEPLOY_PART_START + DEPLOY_PART_SIZE - 1))" + echo WORK: start="$(($WORK_PART_START / $MEGABYTE))"MB size="$(( (WORK_PART_SIZE - 1 ) / $MEGABYTE))"MB + parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${WORK_PART_START}" "$((WORK_PART_START + WORK_PART_SIZE - 1))" + echo ROOT: start="$(($ROOT_PART_START / $MEGABYTE))"MB size="$(( (ROOT_PART_SIZE - 1 ) / $MEGABYTE))"MB parted --script "${IMG_FILE}" unit B mkpart primary ext4 "${ROOT_PART_START}" "$((ROOT_PART_START + ROOT_PART_SIZE - 1))" + echo TOTAL IMAGE SIZE: $(($IMG_SIZE / $MEGABYTE))MB + echo "Creating loop device..." cnt=0 until LOOP_DEV="$(losetup --show --find --partscan "$IMG_FILE")"; do @@ -47,7 +66,9 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then done BOOT_DEV="${LOOP_DEV}p1" - ROOT_DEV="${LOOP_DEV}p2" + ROOT_DEV="${LOOP_DEV}p4" + DEPLOY_DEV="${LOOP_DEV}p2" + WORK_DEV="${LOOP_DEV}p3" ROOT_FEATURES="^huge_file" for FEATURE in 64bit; do @@ -55,13 +76,27 @@ if [ "${NO_PRERUN_QCOW2}" = "0" ]; then ROOT_FEATURES="^$FEATURE,$ROOT_FEATURES" fi done + + echo "Formatting filesystems..." mkdosfs -n bootfs -F 32 -s 4 -v "$BOOT_DEV" > /dev/null + mkdosfs -n deploy -F 32 -s 4 -v "$DEPLOY_DEV" > /dev/null + mkfs.ext4 -L work -O "$ROOT_FEATURES" "$WORK_DEV" > /dev/null mkfs.ext4 -L rootfs -O "$ROOT_FEATURES" "$ROOT_DEV" > /dev/null mount -v "$ROOT_DEV" "${ROOTFS_DIR}" -t ext4 mkdir -p "${ROOTFS_DIR}/boot" mount -v "$BOOT_DEV" "${ROOTFS_DIR}/boot" -t vfat - - rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/" + + rsync -aHAXx --exclude /var/cache/apt/archives --exclude /boot --exclude /srv --exclude /opt/sth/deploy "${EXPORT_ROOTFS_DIR}/" "${ROOTFS_DIR}/" rsync -rtx "${EXPORT_ROOTFS_DIR}/boot/" "${ROOTFS_DIR}/boot/" + + if [[ -d "${EXPORT_ROOTFS_DIR}/srv/sth" ]]; then + mkdir "${ROOTFS_DIR}/srv" + mkdir "${ROOTFS_DIR}/opt/sth/deploy" + + mount -v "$WORK_DEV" "${ROOTFS_DIR}/srv" -t ext4 + mount -v "$DEPLOY_DEV" "${ROOTFS_DIR}/opt/sth/deploy" -t vfat + rsync -artx "${EXPORT_ROOTFS_DIR}/srv/" "${ROOTFS_DIR}/srv" + rsync -rtx "${EXPORT_ROOTFS_DIR}/opt/sth/deploy/" "${ROOTFS_DIR}/opt/sth/deploy" + fi fi diff --git a/scripts/qcow2_handling b/scripts/qcow2_handling index 66708e710e..df6763d551 100644 --- a/scripts/qcow2_handling +++ b/scripts/qcow2_handling @@ -225,13 +225,21 @@ function make_bootable_image() { mkdir -p $MOUNTROOT MOUNTPT=$MOUNTROOT - PARTITION=2 + PARTITION=4 mount "${EXPORT_IMAGE}" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ],sizelimit=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*size=[ ]*//' | sed 's/,.*//'` * 512 ] || exit 1 MOUNTPT=$MOUNTROOT/boot PARTITION=1 mount "${EXPORT_IMAGE}" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ],sizelimit=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*size=[ ]*//' | sed 's/,.*//'` * 512 ] || exit 1 + MOUNTPT=$MOUNTROOT/opt/sth/deploy + PARTITION=2 + mount "${EXPORT_IMAGE}" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ],sizelimit=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*size=[ ]*//' | sed 's/,.*//'` * 512 ] || exit 1 + + MOUNTPT=$MOUNTROOT/srv/sth + PARTITION=3 + mount "${EXPORT_IMAGE}" "$MOUNTPT" -o loop,offset=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*start=[ ]*//' | sed 's/,.*//'` * 512 ],sizelimit=$[ `/sbin/sfdisk -d "${EXPORT_IMAGE}" | grep "start=" | head -n $PARTITION | tail -n1 | sed 's/.*size=[ ]*//' | sed 's/,.*//'` * 512 ] || exit 1 + if [ ! -d "${MOUNTROOT}/root" ]; then echo "Image damaged or not mounted. Exit." exit 1 @@ -242,6 +250,8 @@ function make_bootable_image() { echo "Set UUIDs to make it bootable" sed -i "s/BOOTDEV/PARTUUID=${BOOT_PARTUUID}/" "${MOUNTROOT}/etc/fstab" sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${MOUNTROOT}/etc/fstab" + sed -i "s/DEPLOYDEV/PARTUUID=${DEPLOY_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" + sed -i "s/WORKDEV/PARTUUID=${WORK_PARTUUID}/" "${ROOTFS_DIR}/etc/fstab" sed -i "s/ROOTDEV/PARTUUID=${ROOT_PARTUUID}/" "${MOUNTROOT}/boot/cmdline.txt" fi diff --git a/stage1/01-sys-tweaks/files/fstab b/stage1/01-sys-tweaks/files/fstab index f16e3fb8aa..4d75301b59 100644 --- a/stage1/01-sys-tweaks/files/fstab +++ b/stage1/01-sys-tweaks/files/fstab @@ -1,3 +1,5 @@ -proc /proc proc defaults 0 0 -BOOTDEV /boot vfat defaults 0 2 -ROOTDEV / ext4 defaults,noatime 0 1 +proc /proc proc defaults 0 0 +BOOTDEV /boot vfat defaults 0 2 +ROOTDEV / ext4 defaults,noatime 0 1 +WORKDEV /srv ext4 defaults,noatime 0 1 +DEPLOYDEV /opt/sth/deploy vfat defaults,noatime 0 1 diff --git a/stage2/EXPORT_NOOBS b/stage2/EXPORT_NOOBS deleted file mode 100644 index c1e03be21c..0000000000 --- a/stage2/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspberry Pi OS Lite (64-bit)" -NOOBS_DESCRIPTION="A port of Debian with no desktop environment" diff --git a/stage3/SKIP b/stage3/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage4/SKIP b/stage4/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage5/SKIP b/stage5/SKIP new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stage99-sth/01-setup-user/00-run.sh b/stage99-sth/01-setup-user/00-run.sh new file mode 100755 index 0000000000..3bb5423419 --- /dev/null +++ b/stage99-sth/01-setup-user/00-run.sh @@ -0,0 +1,16 @@ +#!/bin/bash -e + +echo "## Creating STH user" + +on_chroot << EOF +adduser sth --system --home /usr/lib/sth +addgroup sth --system + +# Add them to groups +usermod -aG sudo sth +usermod -aG gpio sth + +# Create a sth-owned folder to put the app in +# You call this whatever you like, probably the name of your application +mkdir -p /usr/lib/sth +EOF diff --git a/stage99-sth/02-install-node/00-run.sh b/stage99-sth/02-install-node/00-run.sh new file mode 100755 index 0000000000..df3fe67dfc --- /dev/null +++ b/stage99-sth/02-install-node/00-run.sh @@ -0,0 +1,10 @@ +#!/bin/bash -e + +NODE_VERSION=18 + +echo "Installing node.js $NODE_VERSION" + +on_chroot << EOF + curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | bash - + sudo apt-get install -y nodejs jq python3-pip python-is-python3 +EOF diff --git a/stage99-sth/03-install-sth/00-run.sh b/stage99-sth/03-install-sth/00-run.sh new file mode 100755 index 0000000000..a68e88a0e3 --- /dev/null +++ b/stage99-sth/03-install-sth/00-run.sh @@ -0,0 +1,6 @@ +#!/bin/bash -e + +on_chroot << EOF + npm i -g @scramjet/sth + pip install pyee==9.0.4 scramjet-framework-py +EOF diff --git a/stage99-sth/04-setup-systemd/00-run.sh b/stage99-sth/04-setup-systemd/00-run.sh new file mode 100755 index 0000000000..61ce7f6404 --- /dev/null +++ b/stage99-sth/04-setup-systemd/00-run.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +install -d "${ROOTFS_DIR}/srv/sth" +install -d "${ROOTFS_DIR}/var/log/sth" +install -d "${ROOTFS_DIR}/opt/sth/deploy" +install -d "${ROOTFS_DIR}/opt/sth/deploy/conf" +install -d "${ROOTFS_DIR}/opt/sth/deploy/sequences" + +install -m 755 files/start-sth "${ROOTFS_DIR}/usr/bin/start-sth" +install -d "${ROOTFS_DIR}/etc/sth" +install -d "${ROOTFS_DIR}/etc/sth/sequences" +install -m 644 files/sth-config "${ROOTFS_DIR}/etc/sth/" +install -m 644 files/sth.service "${ROOTFS_DIR}/etc/systemd/system/" +install -m 644 files/sth-config-deploy.json "${ROOTFS_DIR}/opt/sth/deploy/conf/sth-config.json" + +on_chroot << EOF +chown -R sth:sth /usr/lib/sth +chown -R sth:sth /srv/sth +chown -R sth:sth /var/log/sth +systemctl enable sth +EOF diff --git a/stage99-sth/04-setup-systemd/files/start-sth b/stage99-sth/04-setup-systemd/files/start-sth new file mode 100644 index 0000000000..cc6649cb8a --- /dev/null +++ b/stage99-sth/04-setup-systemd/files/start-sth @@ -0,0 +1,78 @@ +#!/bin/bash + +. /etc/sth/sth-config + +shopt -s extglob + +findfirstconf () { + TARGET=$1 + for FILE in "${TARGET%%/}".{json,yaml,yml}; do + [[ -e "$FILE" ]] && echo $FILE && break; + done +} + +findsequences() { + TARGET=$1 + for FILE in "${TARGET%%/}"/*.{tgz,tar.gz}; do + [[ -e "$FILE" ]] && echo $FILE + done +} + +settargetname () { + BASE=$(basename "$1") + TARGET=$2 + + echo ${TARGET%%/}/$BASE +} + +DEPLOY_CONFIG_LOCATION=$(findfirstconf "${DEPLOY_PATH}/conf/sth-config") +HAS_SEQUENCES=0 +EXTRA_OPTS=("--no-colors" "-D" "$WORK_PATH/sequences") + +if [[ -n "${DEPLOY_CONFIG_LOCATION}" ]]; then + RUNTIME_CONFIG_LOCATION=$(settargetname "$DEPLOY_CONFIG_LOCATION" "$WORK_PATH") + cp "${DEPLOY_CONFIG_LOCATION}" "${RUNTIME_CONFIG_LOCATION}" + EXTRA_OPTS+=("--config=${RUNTIME_CONFIG_LOCATION}") + + echo "Using STH config from ${DEPLOY_CONFIG_LOCATION}" | logger -e +fi + +if [[ -e "${DEPLOY_PATH}/conf/purge.txt" ]]; then + echo "Purging all sequences" | logger -e + rm -rf "$WORK_PATH/sequences" + mkdir "$WORK_PATH/sequences" +fi + +SEQUENCES="$(findsequences ${DEPLOY_PATH}/sequences/)" +if [[ -n "$SEQUENCES" ]]; then + function unpack() { + PACKAGE=$1 + TARGET=$2 + + mkdir -p "$TARGET" + tar -C "$TARGET" -zxf "$PACKAGE" + } + + STARTUP_CONFIG=$(findfirstconf "${DEPLOY_PATH}/conf/startup-config") + if [[ -n "${STARTUP_CONFIG}" ]]; then + RUNTIME_CONFIG_LOCATION=$(settargetname "$STARTUP_CONFIG" "$WORK_PATH") + cp "${STARTUP_CONFIG}" "${RUNTIME_CONFIG_LOCATION}" + EXTRA_OPTS+=("--startup-config=${RUNTIME_CONFIG_LOCATION}") + + echo "Using startup config from ${DEPLOY_CONFIG_LOCATION}" | logger -e + fi + + + for SEQ_FILE in "$(findsequences ${DEPLOY_PATH}/sequences/)"; do + BASENAME=`basename "${SEQ_FILE}"` + TARGET="${BASENAME%.@(tar.gz|tgz)}" + + echo "Unpacking sequence '${BASENAME}' to '$WORK_PATH/sequences/$TARGET'" | logger -e + unpack "$SEQ_FILE" "$WORK_PATH/sequences/$TARGET" + + EXTRA_OPTS+=("-E") + done +fi + +echo Running STH with opts: "${EXTRA_OPTS[@]}" +sth "${EXTRA_OPTS[@]}" 2>&1 | logger -e diff --git a/stage99-sth/04-setup-systemd/files/sth-config b/stage99-sth/04-setup-systemd/files/sth-config new file mode 100644 index 0000000000..460e00f8ab --- /dev/null +++ b/stage99-sth/04-setup-systemd/files/sth-config @@ -0,0 +1,4 @@ +LOGCOLORS="--no-colors" +SEQUENCES_ROOT="/srv/sth/sequences" +DEPLOY_PATH=/opt/sth/deploy +WORK_PATH=/srv/sth diff --git a/stage99-sth/04-setup-systemd/files/sth-config-deploy.json b/stage99-sth/04-setup-systemd/files/sth-config-deploy.json new file mode 100644 index 0000000000..89fc811b1d --- /dev/null +++ b/stage99-sth/04-setup-systemd/files/sth-config-deploy.json @@ -0,0 +1,13 @@ +{ + "host": { + "id": "mini-pi-1" + }, + "safeOperationLimit": 64, + "instanceRequirements": { + "freeMem": 128 + }, + "telemetry": { + "status": true, + "environment": "raspberry-pi-sth" + } +} diff --git a/stage99-sth/04-setup-systemd/files/sth.service b/stage99-sth/04-setup-systemd/files/sth.service new file mode 100644 index 0000000000..b4aca60ad6 --- /dev/null +++ b/stage99-sth/04-setup-systemd/files/sth.service @@ -0,0 +1,14 @@ +[Unit] +Description=Scramjet Transform Hub +Documentation=https://docs.scramjet.org/ +After=network.target + +[Service] +Type=simple +User=sth +ExecStart=/usr/bin/start-sth +WorkingDirectory=/usr/lib/sth +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/stage99-sth/EXPORT_IMAGE b/stage99-sth/EXPORT_IMAGE new file mode 100644 index 0000000000..8d81528db4 --- /dev/null +++ b/stage99-sth/EXPORT_IMAGE @@ -0,0 +1,4 @@ +IMG_SUFFIX="-sth" +if [ "${USE_QEMU}" = "1" ]; then + export IMG_SUFFIX="${IMG_SUFFIX}-qemu" +fi diff --git a/stage99-sth/prerun.sh b/stage99-sth/prerun.sh new file mode 100755 index 0000000000..6986417e74 --- /dev/null +++ b/stage99-sth/prerun.sh @@ -0,0 +1,7 @@ +#!/bin/bash -e + +echo "Copying previous" + +if [ ! -d "${ROOTFS_DIR}" ]; then + copy_previous +fi diff --git a/test.json b/test.json new file mode 100644 index 0000000000..f7a21b9601 --- /dev/null +++ b/test.json @@ -0,0 +1 @@ +{"a":{"b":1}} diff --git a/test1.json b/test1.json new file mode 100644 index 0000000000..44113ec8bd --- /dev/null +++ b/test1.json @@ -0,0 +1 @@ +{"a":{"b":2, "c":0}}