diff --git a/Makefile b/Makefile index 4b0185377..3908e51ca 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,19 @@ APPMGR_SRC := $(shell find appmgr/src) appmgr/Cargo.toml appmgr/Cargo.lock +LIFELINE_SRC := $(shell find lifeline/src) lifeline/Cargo.toml lifeline/Cargo.lock AGENT_SRC := $(shell find agent/src) $(shell find agent/config) agent/stack.yaml agent/package.yaml agent/build.sh - -.DELETE_ON_ERROR: +UI_SRC := $(shell find ui/src) \ + ui/angular.json \ + ui/browserslist \ + ui/client-manifest.yaml \ + ui/ionic.config.json \ + ui/postprocess.ts \ + ui/tsconfig.json \ + ui/tslint.json \ + ui/use-mocks.json all: embassy.img -embassy.img: buster.img product_key appmgr/target/armv7-unknown-linux-musleabihf/release/appmgr ui/www agent/dist/agent agent/config/agent.service +embassy.img: buster.img product_key appmgr/target/armv7-unknown-linux-musleabihf/release/appmgr ui/www agent/dist/agent agent/config/agent.service lifeline/target/armv7-unknown-linux-gnueabihf/release/lifeline lifeline/lifeline.service setup.sh setup.service docker-daemon.json ./make_image.sh buster.img: @@ -18,13 +26,28 @@ product_key: echo "X\c" > product_key cat /dev/random | base32 | head -c11 | tr '[:upper:]' '[:lower:]' >> product_key -appmgr/target/armv7-unknown-linux-musleabihf/release/appmgr: $(APPMGR_SRC) +appmgr/target/armv7-unknown-linux-gnueabihf/release/appmgr: $(APPMGR_SRC) docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)":/home/rust/src start9/rust-arm-cross:latest sh -c "(cd appmgr && cargo build --release --features=production)" docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)":/home/rust/src start9/rust-arm-cross:latest arm-linux-gnueabi-strip appmgr/target/armv7-unknown-linux-gnueabihf/release/appmgr -appmgr: appmgr/target/armv7-unknown-linux-musleabihf/release/appmgr +appmgr: appmgr/target/armv7-unknown-linux-gnueabihf/release/appmgr agent/dist/agent: $(AGENT_SRC) - (cd agent; ./build.sh) + (cd agent && ./build.sh) agent: agent/dist/agent + +ui/node_modules: ui/package.json + npm --prefix ui install + +ui/www: $(UI_SRC) ui/node_modules + npm --prefix ui run build-prod + +ui: ui/www + +lifeline/target/armv7-unknown-linux-gnueabihf/release/lifeline: $(LIFELINE_SRC) + docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)":/home/rust/src start9/rust-arm-cross:latest sh -c "(cd lifeline && cargo build --release)" + docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)":/home/rust/src start9/rust-arm-cross:latest arm-linux-gnueabi-strip lifeline/target/armv7-unknown-linux-gnueabihf/release/lifeline + +lifeline: lifeline/target/armv7-unknown-linux-gnueabihf/release/lifeline + diff --git a/README.md b/README.md index 723d40c52..8e98a63f8 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # Embassy OS + +## Building from Source diff --git a/docker-daemon.json b/docker-daemon.json new file mode 100644 index 000000000..ab8c7ad6d --- /dev/null +++ b/docker-daemon.json @@ -0,0 +1,3 @@ +{ + "log-driver": "journald" +} \ No newline at end of file diff --git a/make_image.sh b/make_image.sh index 72f0672c1..ef6e34596 100644 --- a/make_image.sh +++ b/make_image.sh @@ -1,5 +1,37 @@ -#!/bin/sh +#!/bin/bash ->&2 echo "As of 0.2.5, it is not possible to programmatically generate an Embassy image." ->&2 echo "The image must be setup manually by copying over the artifacts, and installing the necessary dependencies." -exit 1 \ No newline at end of file +mv buster.img embassy.img +product_key=$(cat product_key) +loopdev=$(losetup -f -P embassy.img --show) +root_mountpoint="/mnt/start9-${product_key}-root" +boot_mountpoint="/mnt/start9-${product_key}-boot" +mkdir -p "${root_mountpoint}" +mkdir -p "${boot_mountpoint}" +mount "${loopdev}p2" "${root_mountpoint}" +mount "${loopdev}p1" "${boot_mountpoint}" +echo "${product_key}" > "${root_mountpoint}/root/agent/product_key" +echo -n "start9-" > "${root_mountpoint}/etc/hostname" +echo -n "${product_key}" | shasum -t -a 256 | cut -c1-8 >> "${root_mountpoint}/etc/hostname" +cat "${root_mountpoint}/etc/hosts" | grep -v "127.0.1.1" > "${root_mountpoint}/etc/hosts.tmp" +echo -ne "127.0.1.1\tstart9-" >> "${root_mountpoint}/etc/hosts.tmp" +echo -n "${product_key}" | shasum -t -a 256 | cut -c1-8 >> "${root_mountpoint}/etc/hosts.tmp" +mv "${root_mountpoint}/etc/hosts.tmp" "${root_mountpoint}/etc/hosts" +cp agent/dist/agent "${root_mountpoint}/usr/local/bin/agent" +chmod 700 "${root_mountpoint}/usr/local/bin/agent" +cp appmgr/target/armv7-unknown-linux-musleabihf/release/appmgr "${root_mountpoint}/usr/local/bin/appmgr" +chmod 700 "${root_mountpoint}/usr/local/bin/appmgr" +cp lifeline/target/armv7-unknown-linux-musleabihf/release/lifeline "${root_mountpoint}/usr/local/bin/lifeline" +chmod 700 "${root_mountpoint}/usr/local/bin/lifeline" +cp docker-daemon.json "${root_mountpoint}/etc/docker/daemon.json" +cp setup.sh "${root_mountpoint}/root/setup.sh" +chmod 700 "${root_mountpoint}/root/setup.sh" +cp setup.service /etc/systemd/system/setup.service +cp lifeline/lifeline.service /etc/systemd/system/lifeline.service +cp agent/config/agent.service /etc/systemd/system/agent.service +cat "${boot_mountpoint}/config.txt" | grep -v "dtoverlay=pwm-2chan" > "${boot_mountpoint}/config.txt.tmp" +echo "dtoverlay=pwm-2chan" >> "${boot_mountpoint}/config.txt.tmp" +umount "${root_mountpoint}" +rm -r "${root_mountpoint}" +umount "${boot_mountpoint}" +rm -r "${boot_mountpoint}" +losetup -d ${loopdev} \ No newline at end of file diff --git a/setup.service b/setup.service new file mode 100644 index 000000000..b4e3c9b90 --- /dev/null +++ b/setup.service @@ -0,0 +1,10 @@ +[Unit] +Description=Boot process for system setup. + +[Service] +Type=oneshot +ExecStart=/root/setup.sh +RemainAfterExit=true + +[Install] +WantedBy=multi-user.target diff --git a/setup.sh b/setup.sh new file mode 100644 index 000000000..37ac26ccc --- /dev/null +++ b/setup.sh @@ -0,0 +1,21 @@ +#!/bin/bash +apt update +apt install -y libsecp256k1-0 +apt install -y tor +apt install -y docker.io +apt install -y iotop +apt install -y bmon +apt autoremove -y +mkdir -p /root/volumes +mkdir -p /root/tmp/appmgr +mkdir -p /root/agent +mkdir -p /root/appmgr/tor +systemctl enable lifeline +systemctl enable agent +systemctl enable ssh +systemctl enable avahi-daemon +passwd -l root +passwd -l pi +sync +systemctl disable setup.service +reboot \ No newline at end of file diff --git a/ui/build-send.sh b/ui/build-send.sh index 5f31a0b73..08dd3b920 100755 --- a/ui/build-send.sh +++ b/ui/build-send.sh @@ -10,14 +10,6 @@ rm -rf www echo "FILTER: ionic build" npm run build-prod -echo "FILTER: cp client-manifest.yaml www" -cp client-manifest.yaml www - -echo "FILTER: git hash" -touch git-hash.txt -git log | head -n1 > git-hash.txt -mv git-hash.txt www - echo "FILTER: ssh + rm -rf /var/www/html/start9-ambassador/" ssh root@start9-$1.local "rm -rf /var/www/html/start9-ambassador" diff --git a/ui/package.json b/ui/package.json index e5cf30783..d1ca80fe7 100644 --- a/ui/package.json +++ b/ui/package.json @@ -8,7 +8,7 @@ "ng": "ng", "start": "ng serve", "build": "ng build", - "build-prod": "ng build --prod && tsc postprocess.ts && node postprocess.js", + "build-prod": "ng build --prod && tsc postprocess.ts && node postprocess.js && cp client-manifest.yaml www && git log | head -n1 > www/git-hash.txt", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" @@ -58,4 +58,4 @@ "tslint": "^6.1.0", "typescript": "4.0.5" } -} +} \ No newline at end of file