diff --git a/.github/workflows/startos-iso.yaml b/.github/workflows/startos-iso.yaml index 079f28caa..473294e22 100644 --- a/.github/workflows/startos-iso.yaml +++ b/.github/workflows/startos-iso.yaml @@ -72,8 +72,7 @@ jobs: - run: | cp -r debian embassyos-0.3.x/ VERSION=0.3.x ./control.sh - cp embassyos-0.3.x/backend/embassyd.service embassyos-0.3.x/debian/embassyos.embassyd.service - cp embassyos-0.3.x/backend/embassy-init.service embassyos-0.3.x/debian/embassyos.embassy-init.service + cp embassyos-0.3.x/backend/startd.service embassyos-0.3.x/debian/embassyos.startd.service working-directory: embassy-os-deb - uses: actions/setup-node@v3 diff --git a/Makefile b/Makefile index 23abc2a30..d45bf6557 100644 --- a/Makefile +++ b/Makefile @@ -3,20 +3,20 @@ ARCH := $(shell if [ "$(OS_ARCH)" = "raspberrypi" ]; then echo aarch64; else ech ENVIRONMENT_FILE = $(shell ./check-environment.sh) GIT_HASH_FILE = $(shell ./check-git-hash.sh) VERSION_FILE = $(shell ./check-version.sh) -EMBASSY_BINS := backend/target/$(ARCH)-unknown-linux-gnu/release/embassyd backend/target/$(ARCH)-unknown-linux-gnu/release/embassy-init backend/target/$(ARCH)-unknown-linux-gnu/release/embassy-cli backend/target/$(ARCH)-unknown-linux-gnu/release/embassy-sdk backend/target/$(ARCH)-unknown-linux-gnu/release/avahi-alias libs/target/aarch64-unknown-linux-musl/release/embassy_container_init libs/target/x86_64-unknown-linux-musl/release/embassy_container_init -EMBASSY_UIS := frontend/dist/ui frontend/dist/setup-wizard frontend/dist/diagnostic-ui frontend/dist/install-wizard +EMBASSY_BINS := backend/target/$(ARCH)-unknown-linux-gnu/release/startbox libs/target/aarch64-unknown-linux-musl/release/embassy_container_init libs/target/x86_64-unknown-linux-musl/release/embassy_container_init +EMBASSY_UIS := frontend/dist/raw/ui frontend/dist/raw/setup-wizard frontend/dist/raw/diagnostic-ui frontend/dist/raw/install-wizard BUILD_SRC := $(shell find build) -EMBASSY_SRC := backend/embassyd.service backend/embassy-init.service $(EMBASSY_UIS) $(BUILD_SRC) +EMBASSY_SRC := backend/startd.service $(BUILD_SRC) COMPAT_SRC := $(shell find system-images/compat/ -not -path 'system-images/compat/target/*' -and -not -name *.tar -and -not -name target) UTILS_SRC := $(shell find system-images/utils/ -not -name *.tar) BINFMT_SRC := $(shell find system-images/binfmt/ -not -name *.tar) -BACKEND_SRC := $(shell find backend/src) $(shell find backend/migrations) $(shell find patch-db/*/src) $(shell find libs/*/src) libs/*/Cargo.toml backend/Cargo.toml backend/Cargo.lock +BACKEND_SRC := $(shell find backend/src) $(shell find backend/migrations) $(shell find patch-db/*/src) $(shell find libs/*/src) libs/*/Cargo.toml backend/Cargo.toml backend/Cargo.lock frontend/dist/static FRONTEND_SHARED_SRC := $(shell find frontend/projects/shared) $(shell ls -p frontend/ | grep -v / | sed 's/^/frontend\//g') frontend/package.json frontend/node_modules frontend/config.json patch-db/client/dist frontend/patchdb-ui-seed.json FRONTEND_UI_SRC := $(shell find frontend/projects/ui) FRONTEND_SETUP_WIZARD_SRC := $(shell find frontend/projects/setup-wizard) FRONTEND_DIAGNOSTIC_UI_SRC := $(shell find frontend/projects/diagnostic-ui) FRONTEND_INSTALL_WIZARD_SRC := $(shell find frontend/projects/install-wizard) -PATCH_DB_CLIENT_SRC := $(shell find patch-db/client -not -path patch-db/client/dist) +PATCH_DB_CLIENT_SRC := $(shell find patch-db/client -not -path patch-db/client/dist -and -not -path patch-db/client/node_modules) GZIP_BIN := $(shell which pigz || which gzip) ALL_TARGETS := $(EMBASSY_BINS) system-images/compat/docker-images/$(ARCH).tar system-images/utils/docker-images/$(ARCH).tar system-images/binfmt/docker-images/$(ARCH).tar $(EMBASSY_SRC) $(shell if [ "$(OS_ARCH)" = "raspberrypi" ]; then echo cargo-deps/aarch64-unknown-linux-gnu/release/pi-beep; fi) $(ENVIRONMENT_FILE) $(GIT_HASH_FILE) $(VERSION_FILE) @@ -24,9 +24,11 @@ ifeq ($(REMOTE),) mkdir = mkdir -p $1 rm = rm -rf $1 cp = cp -r $1 $2 + ln = ln -sf $1 $2 else mkdir = ssh $(REMOTE) 'mkdir -p $1' rm = ssh $(REMOTE) 'sudo rm -rf $1' + ln = ssh $(REMOTE) 'sudo ln -sf $1 $2' define cp tar --transform "s|^$1|x|" -czv -f- $1 | ssh $(REMOTE) "sudo tar --transform 's|^x|$2|' -xzv -f- -C /" endef @@ -71,10 +73,12 @@ startos_raspberrypi.img: $(BUILD_SRC) startos.raspberrypi.squashfs $(VERSION_FIL # For creating os images. DO NOT USE install: $(ALL_TARGETS) $(call mkdir,$(DESTDIR)/usr/bin) - $(call cp,backend/target/$(ARCH)-unknown-linux-gnu/release/embassy-init,$(DESTDIR)/usr/bin/embassy-init) - $(call cp,backend/target/$(ARCH)-unknown-linux-gnu/release/embassyd,$(DESTDIR)/usr/bin/embassyd) - $(call cp,backend/target/$(ARCH)-unknown-linux-gnu/release/embassy-cli,$(DESTDIR)/usr/bin/embassy-cli) - $(call cp,backend/target/$(ARCH)-unknown-linux-gnu/release/avahi-alias,$(DESTDIR)/usr/bin/avahi-alias) + $(call cp,backend/target/$(ARCH)-unknown-linux-gnu/release/startbox,$(DESTDIR)/usr/bin/startbox) + $(call ln,/usr/bin/startbox,$(DESTDIR)/usr/bin/startd) + $(call ln,/usr/bin/startbox,$(DESTDIR)/usr/bin/start-cli) + $(call ln,/usr/bin/startbox,$(DESTDIR)/usr/bin/start-sdk) + $(call ln,/usr/bin/startbox,$(DESTDIR)/usr/bin/avahi-alias) + $(call ln,/usr/bin/startbox,$(DESTDIR)/usr/bin/embassy-cli) if [ "$(OS_ARCH)" = "raspberrypi" ]; then $(call cp,cargo-deps/aarch64-unknown-linux-gnu/release/pi-beep,$(DESTDIR)/usr/bin/pi-beep); fi $(call mkdir,$(DESTDIR)/usr/lib) @@ -94,18 +98,11 @@ install: $(ALL_TARGETS) $(call cp,system-images/utils/docker-images/$(ARCH).tar,$(DESTDIR)/usr/lib/embassy/system-images/utils.tar) $(call cp,system-images/binfmt/docker-images/$(ARCH).tar,$(DESTDIR)/usr/lib/embassy/system-images/binfmt.tar) - $(call mkdir,$(DESTDIR)/var/www/html) - $(call cp,frontend/dist/diagnostic-ui,$(DESTDIR)/var/www/html/diagnostic) - $(call cp,frontend/dist/setup-wizard,$(DESTDIR)/var/www/html/setup) - $(call cp,frontend/dist/install-wizard,$(DESTDIR)/var/www/html/install) - $(call cp,frontend/dist/ui,$(DESTDIR)/var/www/html/main) - $(call cp,index.html,$(DESTDIR)/var/www/html/index.html) - update-overlay: @echo "\033[33m!!! THIS WILL ONLY REFLASH YOUR DEVICE IN MEMORY !!!\033[0m" @echo "\033[33mALL CHANGES WILL BE REVERTED IF YOU RESTART THE DEVICE\033[0m" @if [ -z "$(REMOTE)" ]; then >&2 echo "Must specify REMOTE" && false; fi - @if [ "`ssh $(REMOTE) 'cat /usr/lib/embassy/VERSION.txt'`" != "`cat ./VERSION.txt`" ]; then >&2 echo "Embassy requires migrations: update-overlay is unavailable." && false; fi + @if [ "`ssh $(REMOTE) 'cat /usr/lib/embassy/VERSION.txt'`" != "`cat ./VERSION.txt`" ]; then >&2 echo "StartOS requires migrations: update-overlay is unavailable." && false; fi @if ssh $(REMOTE) "pidof embassy-init"; then >&2 echo "Embassy in INIT: update-overlay is unavailable." && false; fi ssh $(REMOTE) "sudo systemctl stop embassyd" $(MAKE) install REMOTE=$(REMOTE) OS_ARCH=$(OS_ARCH) @@ -132,11 +129,6 @@ system-images/utils/docker-images/aarch64.tar system-images/utils/docker-images/ system-images/binfmt/docker-images/aarch64.tar system-images/binfmt/docker-images/x86_64.tar: $(BINFMT_SRC) cd system-images/binfmt && make -raspios.img: - wget --continue https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2022-01-28/2022-01-28-raspios-bullseye-arm64-lite.zip - unzip 2022-01-28-raspios-bullseye-arm64-lite.zip - mv 2022-01-28-raspios-bullseye-arm64-lite.img raspios.img - snapshots: libs/snapshot_creator/Cargo.toml cd libs/ && ./build-v8-snapshot.sh cd libs/ && ./build-arm-v8-snapshot.sh @@ -148,18 +140,21 @@ $(EMBASSY_BINS): $(BACKEND_SRC) $(ENVIRONMENT_FILE) $(GIT_HASH_FILE) frontend/pa frontend/node_modules: frontend/package.json npm --prefix frontend ci -frontend/dist/ui: $(FRONTEND_UI_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) +frontend/dist/raw/ui: $(FRONTEND_UI_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) npm --prefix frontend run build:ui -frontend/dist/setup-wizard: $(FRONTEND_SETUP_WIZARD_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) +frontend/dist/raw/setup-wizard: $(FRONTEND_SETUP_WIZARD_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) npm --prefix frontend run build:setup -frontend/dist/diagnostic-ui: $(FRONTEND_DIAGNOSTIC_UI_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) +frontend/dist/raw/diagnostic-ui: $(FRONTEND_DIAGNOSTIC_UI_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) npm --prefix frontend run build:dui -frontend/dist/install-wizard: $(FRONTEND_INSTALL_WIZARD_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) +frontend/dist/raw/install-wizard: $(FRONTEND_INSTALL_WIZARD_SRC) $(FRONTEND_SHARED_SRC) $(ENVIRONMENT_FILE) npm --prefix frontend run build:install-wiz +frontend/dist/static: $(EMBASSY_UIS) + ./compress-uis.sh + frontend/config.json: $(GIT_HASH_FILE) frontend/config-sample.json jq '.useMocks = false' frontend/config-sample.json > frontend/config.json jq '.packageArch = "$(ARCH)"' frontend/config.json > frontend/config.json.tmp diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 95f92bef2..3bdbd65f2 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -128,8 +128,8 @@ checksum = "bc4c00309ed1c8104732df4a5fa9acc3b796b6f8531dfbd5ce0078c86f997244" dependencies = [ "darling 0.10.2", "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -175,8 +175,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -186,8 +186,8 @@ version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -322,8 +322,8 @@ dependencies = [ "lazycell", "log", "peeking_take_while", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "regex", "rustc-hash", "shlex", @@ -937,8 +937,8 @@ dependencies = [ "cc", "codespan-reporting", "once_cell", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "scratch", "syn 1.0.107", ] @@ -955,8 +955,8 @@ version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebf883b7aacd7b2aeb2a7b338648ee19f57c140d4ee8e52c68979c6b2f7f2263" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -998,8 +998,8 @@ checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "strsim 0.9.3", "syn 1.0.107", ] @@ -1012,8 +1012,8 @@ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "strsim 0.10.0", "syn 1.0.107", ] @@ -1026,8 +1026,8 @@ checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ "fnv", "ident_case", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "strsim 0.10.0", "syn 1.0.107", ] @@ -1039,7 +1039,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core 0.10.2", - "quote 1.0.23", + "quote 1.0.29", "syn 1.0.107", ] @@ -1050,7 +1050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core 0.13.4", - "quote 1.0.23", + "quote 1.0.29", "syn 1.0.107", ] @@ -1061,7 +1061,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ "darling_core 0.14.3", - "quote 1.0.23", + "quote 1.0.29", "syn 1.0.107", ] @@ -1148,8 +1148,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05520711837dd592d2861319ea3cf2dfd81e39bb92e41758ee9172f3623daebd" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -1171,8 +1171,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "rustc_version 0.4.0", "syn 1.0.107", ] @@ -1352,114 +1352,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "embassy-os" -version = "0.3.4-rev.3" -dependencies = [ - "aes", - "async-compression", - "async-stream", - "async-trait", - "avahi-sys", - "base32", - "base64 0.13.1", - "base64ct", - "basic-cookies", - "bollard", - "bytes", - "chrono", - "ciborium", - "clap 3.2.23", - "color-eyre", - "cookie", - "cookie_store 0.19.0", - "current_platform", - "digest 0.10.6", - "digest 0.9.0", - "divrem", - "ed25519", - "ed25519-dalek", - "embassy_container_init", - "emver", - "fd-lock-rs", - "futures", - "git-version", - "gpt", - "helpers", - "hex", - "hmac 0.12.1", - "http", - "hyper", - "hyper-ws-listener", - "imbl 2.0.0", - "indexmap", - "ipnet", - "iprange", - "isocountry", - "itertools 0.10.5", - "josekit", - "js_engine", - "jsonpath_lib", - "lazy_static", - "libc", - "log", - "mbrman", - "models", - "nix 0.25.1", - "nom 7.1.3", - "num", - "num_enum", - "openssh-keys", - "openssl", - "p256 0.12.0", - "patch-db", - "pbkdf2", - "pin-project", - "pkcs8", - "prettytable-rs", - "proptest", - "proptest-derive", - "rand 0.7.3", - "rand 0.8.5", - "regex", - "reqwest", - "reqwest_cookie_store", - "rpassword", - "rpc-toolkit", - "rust-argon2", - "scopeguard", - "serde", - "serde_json", - "serde_with 2.2.0", - "serde_yaml", - "sha2 0.10.6", - "sha2 0.9.9", - "simple-logging", - "sqlx", - "ssh-key", - "stderrlog", - "tar", - "thiserror", - "tokio", - "tokio-rustls", - "tokio-socks", - "tokio-stream", - "tokio-tar", - "tokio-tungstenite", - "tokio-util", - "toml", - "torut", - "tracing", - "tracing-error 0.2.0", - "tracing-futures", - "tracing-subscriber 0.3.16", - "trust-dns-server", - "typed-builder", - "url", - "uuid 1.3.0", - "zeroize", -] - [[package]] name = "embassy_container_init" version = "0.1.0" @@ -1530,8 +1422,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" dependencies = [ "heck 0.4.1", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -1542,7 +1434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b940da354ae81ef0926c5eaa428207b8f4f091d3956c891dfbd124162bed99" dependencies = [ "pmutil", - "proc-macro2 1.0.51", + "proc-macro2 1.0.64", "swc_macros_common", "syn 1.0.107", ] @@ -1712,7 +1604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0981e470d2ab9f643df3921d54f1952ea100c39fdb6a3fdc820e20d2291df6c" dependencies = [ "pmutil", - "proc-macro2 1.0.51", + "proc-macro2 1.0.64", "swc_macros_common", "syn 1.0.107", ] @@ -1798,8 +1690,8 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -1888,8 +1780,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe69f1cbdb6e28af2bac214e943b99ce8a0a06b447d15d3e61161b0423139f3f" dependencies = [ "proc-macro-hack", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -2267,6 +2159,25 @@ dependencies = [ "bitmaps 3.2.0", ] +[[package]] +name = "include_dir" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +dependencies = [ + "proc-macro2 1.0.64", + "quote 1.0.29", +] + [[package]] name = "indenter" version = "0.3.3" @@ -2344,8 +2255,8 @@ checksum = "1c068d4c6b922cd6284c609cfa6dec0e41615c9c5a1a4ba729a970d8daba05fb" dependencies = [ "Inflector", "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -2843,6 +2754,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "new_mime_guess" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d684d1b59e0dc07b37e2203ef576987473288f530082512aff850585c61b1f" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -3051,8 +2972,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2be1598bf1c313dcdd12092e3f1920f463462525a21b7b4e11b4168353d0123e" dependencies = [ "proc-macro-crate", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3111,8 +3032,8 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3289,7 +3210,7 @@ name = "patch-db-macro" version = "0.1.0" dependencies = [ "patch-db-macro-internals", - "proc-macro2 1.0.51", + "proc-macro2 1.0.64", "syn 1.0.107", ] @@ -3298,8 +3219,8 @@ name = "patch-db-macro-internals" version = "0.1.0" dependencies = [ "heck 0.3.3", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3376,8 +3297,8 @@ dependencies = [ "phf_generator", "phf_shared", "proc-macro-hack", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3411,8 +3332,8 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3462,8 +3383,8 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3894e5d549cccbe44afecf72922f277f603cd4bb0219c8342631ef18fffbe004" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -3529,9 +3450,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "78803b62cbf1f46fde80d7c0e803111524b9877184cfe7c3033659490ac7a7da" dependencies = [ "unicode-ident", ] @@ -3622,11 +3543,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.23" +version = "1.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" dependencies = [ - "proc-macro2 1.0.51", + "proc-macro2 1.0.64", ] [[package]] @@ -3915,7 +3836,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8e4b9cb00baf2d61bcd35e98d67dcb760382a3b4540df7e63b38d053c8a7b8b" dependencies = [ - "proc-macro2 1.0.51", + "proc-macro2 1.0.64", "rpc-toolkit-macro-internals", "syn 1.0.107", ] @@ -3926,8 +3847,8 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e2ce21b936feaecdab9c9a8e75b9dca64374ccc11951a58045ad6559b75f42" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -4209,8 +4130,8 @@ version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -4283,8 +4204,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" dependencies = [ "darling 0.13.4", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -4295,8 +4216,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e" dependencies = [ "darling 0.14.3", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -4585,8 +4506,8 @@ dependencies = [ "heck 0.4.1", "hex", "once_cell", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "serde", "serde_json", "sha2 0.10.6", @@ -4636,6 +4557,116 @@ dependencies = [ "zeroize", ] +[[package]] +name = "start-os" +version = "0.3.4-rev.3" +dependencies = [ + "aes", + "async-compression", + "async-stream", + "async-trait", + "avahi-sys", + "base32", + "base64 0.13.1", + "base64ct", + "basic-cookies", + "bollard", + "bytes", + "chrono", + "ciborium", + "clap 3.2.23", + "color-eyre", + "cookie", + "cookie_store 0.19.0", + "current_platform", + "digest 0.10.6", + "digest 0.9.0", + "divrem", + "ed25519", + "ed25519-dalek", + "embassy_container_init", + "emver", + "fd-lock-rs", + "futures", + "git-version", + "gpt", + "helpers", + "hex", + "hmac 0.12.1", + "http", + "hyper", + "hyper-ws-listener", + "imbl 2.0.0", + "include_dir", + "indexmap", + "ipnet", + "iprange", + "isocountry", + "itertools 0.10.5", + "josekit", + "js_engine", + "jsonpath_lib", + "lazy_static", + "libc", + "log", + "mbrman", + "models", + "new_mime_guess", + "nix 0.25.1", + "nom 7.1.3", + "num", + "num_enum", + "openssh-keys", + "openssl", + "p256 0.12.0", + "patch-db", + "pbkdf2", + "pin-project", + "pkcs8", + "prettytable-rs", + "proptest", + "proptest-derive", + "rand 0.7.3", + "rand 0.8.5", + "regex", + "reqwest", + "reqwest_cookie_store", + "rpassword", + "rpc-toolkit", + "rust-argon2", + "scopeguard", + "serde", + "serde_json", + "serde_with 2.2.0", + "serde_yaml", + "sha2 0.10.6", + "sha2 0.9.9", + "simple-logging", + "sqlx", + "ssh-key", + "stderrlog", + "tar", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-socks", + "tokio-stream", + "tokio-tar", + "tokio-tungstenite", + "tokio-util", + "toml", + "torut", + "tracing", + "tracing-error 0.2.0", + "tracing-futures", + "tracing-subscriber 0.3.16", + "trust-dns-server", + "typed-builder", + "url", + "uuid 1.3.0", + "zeroize", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -4677,8 +4708,8 @@ checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" dependencies = [ "phf_generator", "phf_shared", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", ] [[package]] @@ -4688,8 +4719,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "994453cd270ad0265796eb24abf5540091ed03e681c5f3c12bc33e4db33253e1" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -4785,8 +4816,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb64bc03d90fd5c90d6ab917bb2b1d7fbd31957df39e31ea24a3f554b4372251" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -4833,8 +4864,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59949619b2ef45eedb6c399d05f2c3c7bc678b5074b3103bb670f9e05bb99042" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -4917,8 +4948,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18712e4aab969c6508dff3540ade6358f1e013464aa58b3d30da2ab2d9fcbbed" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -5034,8 +5065,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c8f200a2eaed938e7c1a685faaa66e6d42fa9e17da5f62572d3cbc335898f5e" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5046,8 +5077,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5dca3f08d02da4684c3373150f7c045128f81ea00f0c434b1b012bc65a6cce3" dependencies = [ "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5069,8 +5100,8 @@ checksum = "c3b9b72892df873972549838bf84d6c56234c7502148a7e23b5a3da6e0fedfb8" dependencies = [ "Inflector", "pmutil", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "swc_macros_common", "syn 1.0.107", ] @@ -5092,8 +5123,8 @@ version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "unicode-ident", ] @@ -5103,8 +5134,8 @@ version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", "unicode-xid 0.2.4", ] @@ -5199,8 +5230,8 @@ version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5313,8 +5344,8 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5475,8 +5506,8 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5674,8 +5705,8 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", ] @@ -5691,6 +5722,15 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.10" @@ -5904,8 +5944,8 @@ dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", "wasm-bindgen-shared", ] @@ -5928,7 +5968,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ - "quote 1.0.23", + "quote 1.0.29", "wasm-bindgen-macro-support", ] @@ -5938,8 +5978,8 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -6200,8 +6240,8 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ - "proc-macro2 1.0.51", - "quote 1.0.23", + "proc-macro2 1.0.64", + "quote 1.0.29", "syn 1.0.107", "synstructure", ] diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 5f7e4cc90..ea8496880 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Aiden McClelland "] description = "The core of StartOS" -documentation = "https://docs.rs/embassy-os" +documentation = "https://docs.rs/start-os" edition = "2021" keywords = [ "self-hosted", @@ -11,40 +11,28 @@ keywords = [ "full-node", "lightning", ] -name = "embassy-os" +name = "start-os" readme = "README.md" repository = "https://github.com/Start9Labs/start-os" version = "0.3.4-rev.3" [lib] -name = "embassy" +name = "startos" path = "src/lib.rs" [[bin]] -name = "embassyd" -path = "src/bin/embassyd.rs" - -[[bin]] -name = "embassy-init" -path = "src/bin/embassy-init.rs" - -[[bin]] -name = "embassy-sdk" -path = "src/bin/embassy-sdk.rs" - -[[bin]] -name = "embassy-cli" -path = "src/bin/embassy-cli.rs" - -[[bin]] -name = "avahi-alias" -path = "src/bin/avahi-alias.rs" +name = "startbox" +path = "src/main.rs" [features] avahi = ["avahi-sys"] -default = ["avahi", "js_engine"] +default = ["avahi-alias", "cli", "sdk", "daemon", "js_engine"] dev = [] unstable = ["patch-db/unstable"] +avahi-alias = ["avahi"] +cli = [] +sdk = [] +daemon = [] [dependencies] aes = { version = "0.7.5", features = ["ctr"] } @@ -90,6 +78,7 @@ http = "0.2.8" hyper = { version = "0.14.20", features = ["full"] } hyper-ws-listener = "0.2.0" imbl = "2.0.0" +include_dir = "0.7.3" indexmap = { version = "1.9.1", features = ["serde"] } ipnet = { version = "2.7.1", features = ["serde"] } iprange = { version = "0.6.7", features = ["serde"] } @@ -103,6 +92,7 @@ libc = "0.2.126" log = "0.4.17" mbrman = "0.5.0" models = { version = "*", path = "../libs/models" } +new_mime_guess = "4" nix = "0.25.0" nom = "7.1.1" num = "0.4.0" diff --git a/backend/build-dev.sh b/backend/build-dev.sh deleted file mode 100755 index 80bfb44c0..000000000 --- a/backend/build-dev.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -set -e -shopt -s expand_aliases - -if [ "$0" != "./build-dev.sh" ]; then - >&2 echo "Must be run from backend directory" - exit 1 -fi - -USE_TTY= -if tty -s; then - USE_TTY="-it" -fi - -alias 'rust-arm64-builder'='docker run $USE_TTY --rm -v "$HOME/.cargo/registry":/root/.cargo/registry -v "$(pwd)":/home/rust/src start9/rust-arm-cross:aarch64' - -cd .. -rust-arm64-builder sh -c "(cd backend && cargo build --locked)" -cd backend - -sudo chown -R $USER target -sudo chown -R $USER ~/.cargo -#rust-arm64-builder aarch64-linux-gnu-strip target/aarch64-unknown-linux-gnu/release/embassyd diff --git a/backend/build-portable-dev.sh b/backend/build-portable-dev.sh deleted file mode 100755 index cdeb2b6d3..000000000 --- a/backend/build-portable-dev.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -set -e -shopt -s expand_aliases - -if [ "$0" != "./build-portable-dev.sh" ]; then - >&2 echo "Must be run from backend directory" - exit 1 -fi - -USE_TTY= -if tty -s; then - USE_TTY="-it" -fi - -alias 'rust-musl-builder'='docker run $USE_TTY --rm -v "$HOME"/.cargo/registry:/root/.cargo/registry -v "$(pwd)":/home/rust/src start9/rust-musl-cross:x86_64-musl' - -cd .. -rust-musl-builder sh -c "(cd backend && cargo +beta build --target=x86_64-unknown-linux-musl --no-default-features --locked)" -cd backend - -sudo chown -R $USER target -sudo chown -R $USER ~/.cargo \ No newline at end of file diff --git a/backend/embassy-init.service b/backend/embassy-init.service deleted file mode 100644 index 416791d58..000000000 --- a/backend/embassy-init.service +++ /dev/null @@ -1,15 +0,0 @@ -[Unit] -Description=Embassy Init -After=network-online.target -Requires=network-online.target -Wants=avahi-daemon.service - -[Service] -Type=oneshot -Environment=RUST_LOG=embassy_init=debug,embassy=debug,js_engine=debug,patch_db=warn -ExecStart=/usr/bin/embassy-init -RemainAfterExit=true -StandardOutput=append:/var/log/embassy-init.log - -[Install] -WantedBy=embassyd.service diff --git a/backend/embassyd.service b/backend/embassyd.service deleted file mode 100644 index f9bec7a7f..000000000 --- a/backend/embassyd.service +++ /dev/null @@ -1,17 +0,0 @@ -[Unit] -Description=Embassy Daemon -After=embassy-init.service -Requires=embassy-init.service - -[Service] -Type=simple -Environment=RUST_LOG=embassyd=debug,embassy=debug,js_engine=debug,patch_db=warn -ExecStart=/usr/bin/embassyd -Restart=always -RestartSec=3 -ManagedOOMPreference=avoid -CPUAccounting=true -CPUWeight=1000 - -[Install] -WantedBy=multi-user.target diff --git a/backend/install-sdk.sh b/backend/install-sdk.sh index 10388c5a3..2f5177a8d 100755 --- a/backend/install-sdk.sh +++ b/backend/install-sdk.sh @@ -9,7 +9,10 @@ if [ "$0" != "./install-sdk.sh" ]; then fi if [ -z "$OS_ARCH" ]; then - OS_ARCH=$(uname -m) + export OS_ARCH=$(uname -m) fi -cargo install --bin=embassy-sdk --bin=embassy-cli --path=. --no-default-features --features=js_engine --locked +cargo install --path=. --no-default-features --features=js_engine,sdk,cli --locked +startbox_loc=$(which startbox) +ln -sf $startbox_loc $(dirname $startbox_loc)/start-cli +ln -sf $startbox_loc $(dirname $startbox_loc)/start-sdk \ No newline at end of file diff --git a/backend/src/bin/avahi-alias.rs b/backend/src/bins/avahi_alias.rs similarity index 99% rename from backend/src/bin/avahi-alias.rs rename to backend/src/bins/avahi_alias.rs index 22349a927..3c4a4fe7e 100644 --- a/backend/src/bin/avahi-alias.rs +++ b/backend/src/bins/avahi_alias.rs @@ -14,7 +14,7 @@ fn log_str_error(action: &str, e: i32) { } } -fn main() { +pub fn main() { let aliases: Vec<_> = std::env::args().skip(1).collect(); unsafe { let simple_poll = avahi_sys::avahi_simple_poll_new(); diff --git a/backend/src/bins/deprecated.rs b/backend/src/bins/deprecated.rs new file mode 100644 index 000000000..13e0290db --- /dev/null +++ b/backend/src/bins/deprecated.rs @@ -0,0 +1,9 @@ +pub fn renamed(old: &str, new: &str) -> ! { + eprintln!("{old} has been renamed to {new}"); + std::process::exit(1) +} + +pub fn removed(name: &str) -> ! { + eprintln!("{name} has been removed"); + std::process::exit(1) +} diff --git a/backend/src/bin/embassy-cli.rs b/backend/src/bins/embassy_cli.rs similarity index 88% rename from backend/src/bin/embassy-cli.rs rename to backend/src/bins/embassy_cli.rs index 2cfd0dde8..3ef64096e 100644 --- a/backend/src/bin/embassy-cli.rs +++ b/backend/src/bins/embassy_cli.rs @@ -1,21 +1,22 @@ use clap::Arg; -use embassy::context::CliContext; -use embassy::util::logger::EmbassyLogger; -use embassy::version::{Current, VersionT}; -use embassy::Error; use rpc_toolkit::run_cli; use rpc_toolkit::yajrc::RpcError; use serde_json::Value; +use crate::context::CliContext; +use crate::util::logger::EmbassyLogger; +use crate::version::{Current, VersionT}; +use crate::Error; + lazy_static::lazy_static! { static ref VERSION_STRING: String = Current::new().semver().to_string(); } fn inner_main() -> Result<(), Error> { run_cli!({ - command: embassy::main_api, + command: crate::main_api, app: app => app - .name("Embassy CLI") + .name("StartOS CLI") .version(&**VERSION_STRING) .arg( clap::Arg::with_name("config") @@ -48,7 +49,7 @@ fn inner_main() -> Result<(), Error> { Ok(()) } -fn main() { +pub fn main() { match inner_main() { Ok(_) => (), Err(e) => { diff --git a/backend/src/bin/embassy-init.rs b/backend/src/bins/embassy_init.rs similarity index 87% rename from backend/src/bin/embassy-init.rs rename to backend/src/bins/embassy_init.rs index 2f680de05..d423c6ba2 100644 --- a/backend/src/bin/embassy-init.rs +++ b/backend/src/bins/embassy_init.rs @@ -3,21 +3,22 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::Duration; -use embassy::context::rpc::RpcContextConfig; -use embassy::context::{DiagnosticContext, InstallContext, SetupContext}; -use embassy::disk::fsck::RepairStrategy; -use embassy::disk::main::DEFAULT_PASSWORD; -use embassy::disk::REPAIR_DISK_PATH; -use embassy::init::STANDBY_MODE_PATH; -use embassy::net::web_server::WebServer; -use embassy::shutdown::Shutdown; -use embassy::sound::CHIME; -use embassy::util::logger::EmbassyLogger; -use embassy::util::Invoke; -use embassy::{Error, ErrorKind, ResultExt, OS_ARCH}; use tokio::process::Command; use tracing::instrument; +use crate::context::rpc::RpcContextConfig; +use crate::context::{DiagnosticContext, InstallContext, SetupContext}; +use crate::disk::fsck::RepairStrategy; +use crate::disk::main::DEFAULT_PASSWORD; +use crate::disk::REPAIR_DISK_PATH; +use crate::init::STANDBY_MODE_PATH; +use crate::net::web_server::WebServer; +use crate::shutdown::Shutdown; +use crate::sound::CHIME; +use crate::util::logger::EmbassyLogger; +use crate::util::Invoke; +use crate::{Error, ErrorKind, ResultExt, OS_ARCH}; + #[instrument(skip_all)] async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { Command::new("ln") @@ -78,7 +79,7 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { server.shutdown().await; Command::new("reboot") - .invoke(embassy::ErrorKind::Unknown) + .invoke(crate::ErrorKind::Unknown) .await?; } else if tokio::fs::metadata("/media/embassy/config/disk.guid") .await @@ -116,7 +117,7 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { let guid_string = tokio::fs::read_to_string("/media/embassy/config/disk.guid") // unique identifier for volume group - keeps track of the disk that goes with your embassy .await?; let guid = guid_string.trim(); - let requires_reboot = embassy::disk::main::import( + let requires_reboot = crate::disk::main::import( guid, cfg.datadir(), if tokio::fs::metadata(REPAIR_DISK_PATH).await.is_ok() { @@ -130,16 +131,16 @@ async fn setup_or_init(cfg_path: Option) -> Result<(), Error> { if tokio::fs::metadata(REPAIR_DISK_PATH).await.is_ok() { tokio::fs::remove_file(REPAIR_DISK_PATH) .await - .with_ctx(|_| (embassy::ErrorKind::Filesystem, REPAIR_DISK_PATH))?; + .with_ctx(|_| (crate::ErrorKind::Filesystem, REPAIR_DISK_PATH))?; } if requires_reboot.0 { - embassy::disk::main::export(guid, cfg.datadir()).await?; + crate::disk::main::export(guid, cfg.datadir()).await?; Command::new("reboot") - .invoke(embassy::ErrorKind::Unknown) + .invoke(crate::ErrorKind::Unknown) .await?; } tracing::info!("Loaded Disk"); - embassy::init::init(&cfg).await?; + crate::init::init(&cfg).await?; } Ok(()) @@ -168,11 +169,11 @@ async fn inner_main(cfg_path: Option) -> Result, Error if OS_ARCH == "raspberrypi" && tokio::fs::metadata(STANDBY_MODE_PATH).await.is_ok() { tokio::fs::remove_file(STANDBY_MODE_PATH).await?; Command::new("sync").invoke(ErrorKind::Filesystem).await?; - embassy::sound::SHUTDOWN.play().await?; + crate::sound::SHUTDOWN.play().await?; futures::future::pending::<()>().await; } - embassy::sound::BEP.play().await?; + crate::sound::BEP.play().await?; run_script_if_exists("/media/embassy/config/preinit.sh").await; @@ -180,7 +181,7 @@ async fn inner_main(cfg_path: Option) -> Result, Error async move { tracing::error!("{}", e.source); tracing::debug!("{}", e.source); - embassy::sound::BEETHOVEN.play().await?; + crate::sound::BEETHOVEN.play().await?; let ctx = DiagnosticContext::init( cfg_path, @@ -223,7 +224,7 @@ async fn inner_main(cfg_path: Option) -> Result, Error res } -fn main() { +pub fn main() { let matches = clap::App::new("embassy-init") .arg( clap::Arg::with_name("config") @@ -233,8 +234,6 @@ fn main() { ) .get_matches(); - EmbassyLogger::init(); - let cfg_path = matches.value_of("config").map(|p| Path::new(p).to_owned()); let res = { let rt = tokio::runtime::Builder::new_multi_thread() diff --git a/backend/src/bin/embassy-sdk.rs b/backend/src/bins/embassy_sdk.rs similarity index 88% rename from backend/src/bin/embassy-sdk.rs rename to backend/src/bins/embassy_sdk.rs index 56c462f53..10219c485 100644 --- a/backend/src/bin/embassy-sdk.rs +++ b/backend/src/bins/embassy_sdk.rs @@ -1,20 +1,21 @@ -use embassy::context::SdkContext; -use embassy::util::logger::EmbassyLogger; -use embassy::version::{Current, VersionT}; -use embassy::Error; use rpc_toolkit::run_cli; use rpc_toolkit::yajrc::RpcError; use serde_json::Value; +use crate::context::SdkContext; +use crate::util::logger::EmbassyLogger; +use crate::version::{Current, VersionT}; +use crate::Error; + lazy_static::lazy_static! { static ref VERSION_STRING: String = Current::new().semver().to_string(); } fn inner_main() -> Result<(), Error> { run_cli!({ - command: embassy::portable_api, + command: crate::portable_api, app: app => app - .name("Embassy SDK") + .name("StartOS SDK") .version(&**VERSION_STRING) .arg( clap::Arg::with_name("config") @@ -47,7 +48,7 @@ fn inner_main() -> Result<(), Error> { Ok(()) } -fn main() { +pub fn main() { match inner_main() { Ok(_) => (), Err(e) => { diff --git a/backend/src/bin/embassyd.rs b/backend/src/bins/embassyd.rs similarity index 89% rename from backend/src/bin/embassyd.rs rename to backend/src/bins/embassyd.rs index 7bfffe717..ac9836511 100644 --- a/backend/src/bin/embassyd.rs +++ b/backend/src/bins/embassyd.rs @@ -3,16 +3,17 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use color_eyre::eyre::eyre; -use embassy::context::{DiagnosticContext, RpcContext}; -use embassy::net::web_server::WebServer; -use embassy::shutdown::Shutdown; -use embassy::system::launch_metrics_task; -use embassy::util::logger::EmbassyLogger; -use embassy::{Error, ErrorKind, ResultExt}; use futures::{FutureExt, TryFutureExt}; use tokio::signal::unix::signal; use tracing::instrument; +use crate::context::{DiagnosticContext, RpcContext}; +use crate::net::web_server::WebServer; +use crate::shutdown::Shutdown; +use crate::system::launch_metrics_task; +use crate::util::logger::EmbassyLogger; +use crate::{Error, ErrorKind, ResultExt}; + #[instrument(skip_all)] async fn inner_main(cfg_path: Option) -> Result, Error> { let (rpc_ctx, server, shutdown) = { @@ -26,7 +27,7 @@ async fn inner_main(cfg_path: Option) -> Result, Error ), ) .await?; - embassy::hostname::sync_hostname(&rpc_ctx.account.read().await.hostname).await?; + crate::hostname::sync_hostname(&rpc_ctx.account.read().await.hostname).await?; let server = WebServer::main( SocketAddr::new(Ipv6Addr::UNSPECIFIED.into(), 80), rpc_ctx.clone(), @@ -71,7 +72,7 @@ async fn inner_main(cfg_path: Option) -> Result, Error .await }); - embassy::sound::CHIME.play().await?; + crate::sound::CHIME.play().await?; metrics_task .map_err(|e| { @@ -100,7 +101,14 @@ async fn inner_main(cfg_path: Option) -> Result, Error Ok(shutdown) } -fn main() { +pub fn main() { + EmbassyLogger::init(); + + if !Path::new("/run/embassy/initialized").exists() { + super::embassy_init::main(); + std::fs::write("/run/embassy/initialized", "").unwrap(); + } + let matches = clap::App::new("embassyd") .arg( clap::Arg::with_name("config") @@ -110,8 +118,6 @@ fn main() { ) .get_matches(); - EmbassyLogger::init(); - let cfg_path = matches.value_of("config").map(|p| Path::new(p).to_owned()); let res = { @@ -126,7 +132,7 @@ fn main() { async { tracing::error!("{}", e.source); tracing::debug!("{:?}", e.source); - embassy::sound::BEETHOVEN.play().await?; + crate::sound::BEETHOVEN.play().await?; let ctx = DiagnosticContext::init( cfg_path, if tokio::fs::metadata("/media/embassy/config/disk.guid") diff --git a/backend/src/bins/mod.rs b/backend/src/bins/mod.rs new file mode 100644 index 000000000..24972cef5 --- /dev/null +++ b/backend/src/bins/mod.rs @@ -0,0 +1,55 @@ +use std::path::Path; + +#[cfg(feature = "avahi-alias")] +pub mod avahi_alias; +pub mod deprecated; +#[cfg(feature = "cli")] +pub mod embassy_cli; +#[cfg(feature = "daemon")] +pub mod embassy_init; +#[cfg(feature = "sdk")] +pub mod embassy_sdk; +#[cfg(feature = "daemon")] +pub mod embassyd; + +fn select_executable(name: &str) -> Option { + match name { + #[cfg(feature = "avahi-alias")] + "avahi-alias" => Some(avahi_alias::main), + #[cfg(feature = "cli")] + "start-cli" => Some(embassy_cli::main), + #[cfg(feature = "sdk")] + "start-sdk" => Some(embassy_sdk::main), + #[cfg(feature = "daemon")] + "startd" => Some(embassyd::main), + "embassy-cli" => Some(|| deprecated::renamed("embassy-cli", "start-cli")), + "embassy-sdk" => Some(|| deprecated::renamed("embassy-sdk", "start-sdk")), + "embassyd" => Some(|| deprecated::renamed("embassyd", "startd")), + "embassy-init" => Some(|| deprecated::removed("embassy-init")), + _ => None, + } +} + +pub fn startbox() { + let args = std::env::args().take(2).collect::>(); + if let Some(x) = args + .get(0) + .and_then(|s| Path::new(&*s).file_name()) + .and_then(|s| s.to_str()) + .and_then(|s| select_executable(&s)) + { + x() + } else if let Some(x) = args.get(1).and_then(|s| select_executable(&s)) { + x() + } else { + eprintln!( + "unknown executable: {}", + args.get(0) + .filter(|x| &**x != "startbox") + .or_else(|| args.get(1)) + .map(|s| s.as_str()) + .unwrap_or("N/A") + ); + std::process::exit(1); + } +} diff --git a/backend/src/lib.rs b/backend/src/lib.rs index a5b64164e..4e4b1619a 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -17,6 +17,7 @@ pub mod account; pub mod action; pub mod auth; pub mod backup; +pub mod bins; pub mod config; pub mod context; pub mod control; diff --git a/backend/src/main.rs b/backend/src/main.rs new file mode 100644 index 000000000..371cd5e7d --- /dev/null +++ b/backend/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + startos::bins::startbox() +} diff --git a/backend/src/net/static_server.rs b/backend/src/net/static_server.rs index 616cd2f39..e640d49e9 100644 --- a/backend/src/net/static_server.rs +++ b/backend/src/net/static_server.rs @@ -1,16 +1,19 @@ +use std::borrow::Cow; use std::fs::Metadata; -use std::path::Path; +use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::UNIX_EPOCH; -use async_compression::tokio::bufread::{BrotliEncoder, GzipEncoder}; +use async_compression::tokio::bufread::GzipEncoder; use color_eyre::eyre::eyre; use digest::Digest; use futures::FutureExt; -use http::header::{ACCEPT_ENCODING, CONTENT_ENCODING}; +use http::header::ACCEPT_ENCODING; use http::request::Parts as RequestParts; use http::response::Builder; use hyper::{Body, Method, Request, Response, StatusCode}; +use include_dir::{include_dir, Dir}; +use new_mime_guess::MimeGuess; use openssl::hash::MessageDigest; use openssl::x509::X509; use rpc_toolkit::rpc_handler; @@ -33,10 +36,7 @@ static NOT_FOUND: &[u8] = b"Not Found"; static METHOD_NOT_ALLOWED: &[u8] = b"Method Not Allowed"; static NOT_AUTHORIZED: &[u8] = b"Not Authorized"; -pub const MAIN_UI_WWW_DIR: &str = "/var/www/html/main"; -pub const SETUP_UI_WWW_DIR: &str = "/var/www/html/setup"; -pub const DIAG_UI_WWW_DIR: &str = "/var/www/html/diagnostic"; -pub const INSTALL_UI_WWW_DIR: &str = "/var/www/html/install"; +static EMBEDDED_UIS: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/../frontend/dist/static"); fn status_fn(_: i32) -> StatusCode { StatusCode::OK @@ -50,6 +50,17 @@ pub enum UiMode { Main, } +impl UiMode { + fn path(&self, path: &str) -> PathBuf { + match self { + Self::Setup => Path::new("setup-wizard").join(path), + Self::Diag => Path::new("diagnostic-ui").join(path), + Self::Install => Path::new("install-wizard").join(path), + Self::Main => Path::new("ui").join(path), + } + } +} + pub async fn setup_ui_file_router(ctx: SetupContext) -> Result { let handler: HttpHandler = Arc::new(move |req| { let ctx = ctx.clone(); @@ -224,13 +235,6 @@ pub async fn main_ui_server_router(ctx: RpcContext) -> Result, ui_mode: UiMode) -> Result, Error> { - let selected_root_dir = match ui_mode { - UiMode::Setup => SETUP_UI_WWW_DIR, - UiMode::Diag => DIAG_UI_WWW_DIR, - UiMode::Install => INSTALL_UI_WWW_DIR, - UiMode::Main => MAIN_UI_WWW_DIR, - }; - let (request_parts, _body) = req.into_parts(); let accept_encoding = request_parts .headers @@ -243,46 +247,32 @@ async fn alt_ui(req: Request, ui_mode: UiMode) -> Result, E .collect::>(); match &request_parts.method { &Method::GET => { - let uri_path = request_parts - .uri - .path() - .strip_prefix('/') - .unwrap_or(request_parts.uri.path()); - - let full_path = Path::new(selected_root_dir).join(uri_path); - file_send( - &request_parts, - if tokio::fs::metadata(&full_path) + let uri_path = ui_mode.path( + request_parts + .uri + .path() + .strip_prefix('/') + .unwrap_or(request_parts.uri.path()), + ); + + let file = EMBEDDED_UIS + .get_file(&*uri_path) + .or_else(|| EMBEDDED_UIS.get_file(&*ui_mode.path("index.html"))); + + if let Some(file) = file { + FileData::from_embedded(&request_parts, file) + .into_response(&request_parts) .await - .ok() - .map(|f| f.is_file()) - .unwrap_or(false) - { - full_path - } else { - Path::new(selected_root_dir).join("index.html") - }, - &accept_encoding, - ) - .await + } else { + Ok(not_found()) + } } _ => Ok(method_not_allowed()), } } async fn main_embassy_ui(req: Request, ctx: RpcContext) -> Result, Error> { - let selected_root_dir = MAIN_UI_WWW_DIR; - let (request_parts, _body) = req.into_parts(); - let accept_encoding = request_parts - .headers - .get_all(ACCEPT_ENCODING) - .into_iter() - .filter_map(|h| h.to_str().ok()) - .flat_map(|s| s.split(",")) - .filter_map(|s| s.split(";").next()) - .map(|s| s.trim()) - .collect::>(); match ( &request_parts.method, request_parts @@ -297,11 +287,12 @@ async fn main_embassy_ui(req: Request, ctx: RpcContext) -> Result { let sub_path = Path::new(path); if let Ok(rest) = sub_path.strip_prefix("package-data") { - file_send( + FileData::from_path( &request_parts, - ctx.datadir.join(PKG_PUBLIC_DIR).join(rest), - &accept_encoding, + &ctx.datadir.join(PKG_PUBLIC_DIR).join(rest), ) + .await? + .into_response(&request_parts) .await } else if let Ok(rest) = sub_path.strip_prefix("eos") { match rest.to_str() { @@ -323,28 +314,25 @@ async fn main_embassy_ui(req: Request, ctx: RpcContext) -> Result { - let uri_path = request_parts - .uri - .path() - .strip_prefix('/') - .unwrap_or(request_parts.uri.path()); - - let full_path = Path::new(selected_root_dir).join(uri_path); - file_send( - &request_parts, - if tokio::fs::metadata(&full_path) + let uri_path = UiMode::Main.path( + request_parts + .uri + .path() + .strip_prefix('/') + .unwrap_or(request_parts.uri.path()), + ); + + let file = EMBEDDED_UIS + .get_file(&*uri_path) + .or_else(|| EMBEDDED_UIS.get_file(&*UiMode::Main.path("index.html"))); + + if let Some(file) = file { + FileData::from_embedded(&request_parts, file) + .into_response(&request_parts) .await - .ok() - .map(|f| f.is_file()) - .unwrap_or(false) - { - full_path - } else { - Path::new(selected_root_dir).join("index.html") - }, - &accept_encoding, - ) - .await + } else { + Ok(not_found()) + } } _ => Ok(method_not_allowed()), } @@ -407,118 +395,163 @@ fn cert_send(cert: &X509) -> Result, Error> { .with_kind(ErrorKind::Network) } -async fn file_send( - req: &RequestParts, - path: impl AsRef, - accept_encoding: &[&str], -) -> Result, Error> { - // Serve a file by asynchronously reading it by chunks using tokio-util crate. - - let path = path.as_ref(); - - let file = File::open(path) - .await - .with_ctx(|_| (ErrorKind::Filesystem, path.display().to_string()))?; - let metadata = file - .metadata() - .await - .with_ctx(|_| (ErrorKind::Filesystem, path.display().to_string()))?; - - let e_tag = e_tag(path, &metadata)?; - - let mut builder = Response::builder(); - builder = with_content_type(path, builder); - builder = builder.header(http::header::ETAG, &e_tag); - builder = builder.header( - http::header::CACHE_CONTROL, - "public, max-age=21000000, immutable", - ); - - if req - .headers - .get_all(http::header::CONNECTION) - .iter() - .flat_map(|s| s.to_str().ok()) - .flat_map(|s| s.split(",")) - .any(|s| s.trim() == "keep-alive") - { - builder = builder.header(http::header::CONNECTION, "keep-alive"); +struct FileData { + data: Body, + len: Option, + encoding: Option<&'static str>, + e_tag: String, + mime: Option, +} +impl FileData { + fn from_embedded(req: &RequestParts, file: &'static include_dir::File<'static>) -> Self { + let path = file.path(); + let (encoding, data) = req + .headers + .get_all(ACCEPT_ENCODING) + .into_iter() + .filter_map(|h| h.to_str().ok()) + .flat_map(|s| s.split(",")) + .filter_map(|s| s.split(";").next()) + .map(|s| s.trim()) + .fold((None, file.contents()), |acc, e| { + if let Some(file) = (e == "br") + .then_some(()) + .and_then(|_| EMBEDDED_UIS.get_file(format!("{}.br", path.display()))) + { + (Some("br"), file.contents()) + } else if let Some(file) = (e == "gzip" && acc.0 != Some("br")) + .then_some(()) + .and_then(|_| EMBEDDED_UIS.get_file(format!("{}.gz", path.display()))) + { + (Some("gzip"), file.contents()) + } else { + acc + } + }); + + Self { + len: Some(data.len() as u64), + encoding, + data: data.into(), + e_tag: e_tag(path, None), + mime: MimeGuess::from_path(path) + .first() + .map(|m| m.essence_str().to_owned()), + } } - if req - .headers - .get("if-none-match") - .and_then(|h| h.to_str().ok()) - == Some(e_tag.as_str()) - { - builder = builder.status(StatusCode::NOT_MODIFIED); - builder.body(Body::empty()) - } else { - let body = if false && accept_encoding.contains(&"br") && metadata.len() > u16::MAX as u64 { - builder = builder.header(CONTENT_ENCODING, "br"); - Body::wrap_stream(ReaderStream::new(BrotliEncoder::new(BufReader::new(file)))) - } else if accept_encoding.contains(&"gzip") && metadata.len() > u16::MAX as u64 { - builder = builder.header(CONTENT_ENCODING, "gzip"); - Body::wrap_stream(ReaderStream::new(GzipEncoder::new(BufReader::new(file)))) + async fn from_path(req: &RequestParts, path: &Path) -> Result { + let encoding = req + .headers + .get_all(ACCEPT_ENCODING) + .into_iter() + .filter_map(|h| h.to_str().ok()) + .flat_map(|s| s.split(",")) + .filter_map(|s| s.split(";").next()) + .map(|s| s.trim()) + .any(|e| e == "gzip") + .then_some("gzip"); + + let file = File::open(path) + .await + .with_ctx(|_| (ErrorKind::Filesystem, path.display().to_string()))?; + let metadata = file + .metadata() + .await + .with_ctx(|_| (ErrorKind::Filesystem, path.display().to_string()))?; + + let e_tag = e_tag(path, Some(&metadata)); + + let (len, data) = if encoding == Some("gzip") { + ( + None, + Body::wrap_stream(ReaderStream::new(GzipEncoder::new(BufReader::new(file)))), + ) } else { - builder = with_content_length(&metadata, builder); - Body::wrap_stream(ReaderStream::new(file)) + ( + Some(metadata.len()), + Body::wrap_stream(ReaderStream::new(file)), + ) }; - builder.body(body) + + Ok(Self { + data, + len, + encoding, + e_tag, + mime: MimeGuess::from_path(path) + .first() + .map(|m| m.essence_str().to_owned()), + }) + } + + async fn into_response(self, req: &RequestParts) -> Result, Error> { + let mut builder = Response::builder(); + if let Some(mime) = self.mime { + builder = builder.header(http::header::CONTENT_TYPE, &*mime); + } + builder = builder.header(http::header::ETAG, &*self.e_tag); + builder = builder.header( + http::header::CACHE_CONTROL, + "public, max-age=21000000, immutable", + ); + + if req + .headers + .get_all(http::header::CONNECTION) + .iter() + .flat_map(|s| s.to_str().ok()) + .flat_map(|s| s.split(",")) + .any(|s| s.trim() == "keep-alive") + { + builder = builder.header(http::header::CONNECTION, "keep-alive"); + } + + if req + .headers + .get("if-none-match") + .and_then(|h| h.to_str().ok()) + == Some(self.e_tag.as_ref()) + { + builder = builder.status(StatusCode::NOT_MODIFIED); + builder.body(Body::empty()) + } else { + if let Some(len) = self.len { + builder = builder.header(http::header::CONTENT_LENGTH, len); + } + if let Some(encoding) = self.encoding { + builder = builder.header(http::header::CONTENT_ENCODING, encoding); + } + + builder.body(self.data) + } + .with_kind(ErrorKind::Network) } - .with_kind(ErrorKind::Network) } -fn e_tag(path: &Path, metadata: &Metadata) -> Result { - let modified = metadata.modified().with_kind(ErrorKind::Filesystem)?; +fn e_tag(path: &Path, metadata: Option<&Metadata>) -> String { let mut hasher = sha2::Sha256::new(); hasher.update(format!("{:?}", path).as_bytes()); - hasher.update( - format!( - "{}", - modified - .duration_since(UNIX_EPOCH) - .unwrap_or_default() - .as_secs() - ) - .as_bytes(), - ); + if let Some(modified) = metadata.and_then(|m| m.modified().ok()) { + hasher.update( + format!( + "{}", + modified + .duration_since(UNIX_EPOCH) + .unwrap_or_default() + .as_secs() + ) + .as_bytes(), + ); + } let res = hasher.finalize(); - Ok(format!( + format!( "\"{}\"", base32::encode(base32::Alphabet::RFC4648 { padding: false }, res.as_slice()).to_lowercase() - )) -} - -///https://en.wikipedia.org/wiki/Media_type -fn with_content_type(path: &Path, builder: Builder) -> Builder { - let content_type = match path.extension() { - Some(os_str) => match os_str.to_str() { - Some("apng") => "image/apng", - Some("avif") => "image/avif", - Some("flif") => "image/flif", - Some("gif") => "image/gif", - Some("jpg") | Some("jpeg") | Some("jfif") | Some("pjpeg") | Some("pjp") => "image/jpeg", - Some("jxl") => "image/jxl", - Some("png") => "image/png", - Some("svg") => "image/svg+xml", - Some("webp") => "image/webp", - Some("mng") | Some("x-mng") => "image/x-mng", - Some("css") => "text/css", - Some("csv") => "text/csv", - Some("html") => "text/html", - Some("php") => "text/php", - Some("plain") | Some("md") | Some("txt") => "text/plain", - Some("xml") => "text/xml", - Some("js") => "text/javascript", - Some("wasm") => "application/wasm", - None | Some(_) => "text/plain", - }, - None => "text/plain", - }; - builder.header(http::header::CONTENT_TYPE, content_type) + ) } -fn with_content_length(metadata: &Metadata, builder: Builder) -> Builder { - builder.header(http::header::CONTENT_LENGTH, metadata.len()) +#[test] +fn test_packed_html() { + assert!(MainUi::get("index.html").is_some()) } diff --git a/backend/startd.service b/backend/startd.service new file mode 100644 index 000000000..2bebd23b8 --- /dev/null +++ b/backend/startd.service @@ -0,0 +1,18 @@ +[Unit] +Description=StartOS Daemon +After=network-online.target +Requires=network-online.target +Wants=avahi-daemon.service + +[Service] +Type=simple +Environment=RUST_LOG=startos=debug,js_engine=debug,patch_db=warn +ExecStart=/usr/bin/startd +Restart=always +RestartSec=3 +ManagedOOMPreference=avoid +CPUAccounting=true +CPUWeight=1000 + +[Install] +WantedBy=multi-user.target diff --git a/build/lib/motd b/build/lib/motd index fc07a2ceb..b4a4d255c 100644 --- a/build/lib/motd +++ b/build/lib/motd @@ -10,7 +10,7 @@ cat << "ASCII" ╰ ━ ━ ━ ╯ ╰ ━ ┻ ╯ ╰ ┻ ╯ ╰ ━ ┻ ━ ━ ━ ┻ ━ ━ ━ ╯ ASCII printf " %s (%s %s)\n" "$(uname -o)" "$(uname -r)" "$(uname -m)" -printf " $(embassy-cli --version | sed 's/Embassy CLI /StartOS v/g') - $(embassy-cli git-info)" +printf " $(embassy-cli --version | sed 's/StartOS CLI /StartOS v/g') - $(embassy-cli git-info)" if [ -n "$(cat /usr/lib/embassy/ENVIRONMENT.txt)" ]; then printf " ~ $(cat /usr/lib/embassy/ENVIRONMENT.txt)\n" else diff --git a/compress-uis.sh b/compress-uis.sh new file mode 100755 index 000000000..964ddeb57 --- /dev/null +++ b/compress-uis.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +rm -rf frontend/dist/static + +find frontend/dist/raw -type f -not -name '*.gz' -and -not -name '*.br' | xargs -n 1 -P 0 gzip -kf +find frontend/dist/raw -type f -not -name '*.gz' -and -not -name '*.br' | xargs -n 1 -P 0 brotli -kf + +for file in $(find frontend/dist/raw -type f -not -name '*.gz' -and -not -name '*.br'); do + raw_size=$(du --bytes $file | awk '{print $1}') + gz_size=$(du --bytes $file.gz | awk '{print $1}') + br_size=$(du --bytes $file.br | awk '{print $1}') + if [ $((gz_size * 100 / raw_size)) -gt 70 ]; then + rm $file.gz + fi + if [ $((br_size * 100 / raw_size)) -gt 70 ]; then + rm $file.br + fi +done + +cp -r frontend/dist/raw frontend/dist/static \ No newline at end of file diff --git a/frontend/angular.json b/frontend/angular.json index 43d138d9c..a2e161ba1 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -14,7 +14,7 @@ "builder": "@angular-devkit/build-angular:browser", "options": { "preserveSymlinks": true, - "outputPath": "dist/ui", + "outputPath": "dist/raw/ui", "index": "projects/ui/src/index.html", "main": "projects/ui/src/main.ts", "polyfills": "projects/ui/src/polyfills.ts", @@ -39,7 +39,7 @@ "projects/ui/src/manifest.webmanifest", { "glob": "ngsw.json", - "input": "dist/ui", + "input": "dist/raw/ui", "output": "projects/ui/src" } ], @@ -147,7 +147,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/install-wizard", + "outputPath": "dist/raw/install-wizard", "index": "projects/install-wizard/src/index.html", "main": "projects/install-wizard/src/main.ts", "polyfills": "projects/install-wizard/src/polyfills.ts", @@ -277,7 +277,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/setup-wizard", + "outputPath": "dist/raw/setup-wizard", "index": "projects/setup-wizard/src/index.html", "main": "projects/setup-wizard/src/main.ts", "polyfills": "projects/setup-wizard/src/polyfills.ts", @@ -397,7 +397,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/diagnostic-ui", + "outputPath": "dist/raw/diagnostic-ui", "index": "projects/diagnostic-ui/src/index.html", "main": "projects/diagnostic-ui/src/main.ts", "polyfills": "projects/diagnostic-ui/src/polyfills.ts", diff --git a/frontend/package.json b/frontend/package.json index 18e485234..20a0ea90a 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -22,7 +22,7 @@ "build:all": "npm run build:deps && npm run build:dui && npm run build:setup && npm run build:ui && npm run build:install-wiz", "build:shared": "ng build shared", "build:marketplace": "npm run build:shared && ng build marketplace", - "analyze:ui": "webpack-bundle-analyzer dist/ui/stats.json", + "analyze:ui": "webpack-bundle-analyzer dist/raw/ui/stats.json", "publish:shared": "npm run build:shared && npm publish ./dist/shared --access public", "publish:marketplace": "npm run build:marketplace && npm publish ./dist/marketplace --access public", "start:dui": "npm run-script build-config && ionic serve --project diagnostic-ui --host 0.0.0.0", diff --git a/libs/embassy_container_init/src/main.rs b/libs/embassy_container_init/src/main.rs index 0764382c0..17db5d74c 100644 --- a/libs/embassy_container_init/src/main.rs +++ b/libs/embassy_container_init/src/main.rs @@ -371,7 +371,7 @@ async fn main() { tracing::error!("Error sending to {id:?}", id = req.id); } } - Err(e) => + Err(e) => if let Err(err) = w .lock() .await diff --git a/libs/js_engine/src/lib.rs b/libs/js_engine/src/lib.rs index b00f4c5eb..c4cd85f11 100644 --- a/libs/js_engine/src/lib.rs +++ b/libs/js_engine/src/lib.rs @@ -167,7 +167,7 @@ impl ModuleLoader for ModsLoader { } match &maybe_referrer { Some(x) if x.as_str() == "file:///embassy.js" => { - bail!("Embassy is not allowed to import") + bail!("StartJS is not allowed to import") } _ => (), } diff --git a/system-images/compat/Cargo.lock b/system-images/compat/Cargo.lock index 6f3e60289..b3f185406 100644 --- a/system-images/compat/Cargo.lock +++ b/system-images/compat/Cargo.lock @@ -598,7 +598,6 @@ dependencies = [ "beau_collector", "clap 2.34.0", "dashmap", - "embassy-os", "emver", "failure", "indexmap", @@ -615,6 +614,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml 0.8.26", + "start-os", ] [[package]] @@ -1169,112 +1169,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "embassy-os" -version = "0.3.4-rev.3" -dependencies = [ - "aes", - "async-compression", - "async-stream", - "async-trait", - "base32", - "base64 0.13.1", - "base64ct", - "basic-cookies", - "bollard", - "bytes", - "chrono", - "ciborium", - "clap 3.2.23", - "color-eyre", - "cookie", - "cookie_store 0.19.0", - "current_platform", - "digest 0.10.6", - "digest 0.9.0", - "divrem", - "ed25519", - "ed25519-dalek", - "embassy_container_init", - "emver", - "fd-lock-rs", - "futures", - "git-version", - "gpt", - "helpers", - "hex", - "hmac 0.12.1", - "http", - "hyper", - "hyper-ws-listener", - "imbl 2.0.0", - "indexmap", - "ipnet", - "iprange", - "isocountry", - "itertools 0.10.5", - "josekit", - "jsonpath_lib", - "lazy_static", - "libc", - "log", - "mbrman", - "models", - "nix 0.25.1", - "nom", - "num", - "num_enum", - "openssh-keys", - "openssl", - "p256 0.12.0", - "patch-db", - "pbkdf2", - "pin-project", - "pkcs8", - "prettytable-rs", - "proptest", - "proptest-derive", - "rand 0.7.3", - "rand 0.8.5", - "regex", - "reqwest", - "reqwest_cookie_store", - "rpassword", - "rpc-toolkit", - "rust-argon2", - "scopeguard", - "serde", - "serde_json", - "serde_with 2.2.0", - "serde_yaml 0.9.16", - "sha2 0.10.6", - "sha2 0.9.9", - "simple-logging", - "sqlx", - "ssh-key", - "stderrlog", - "tar", - "thiserror", - "tokio", - "tokio-rustls", - "tokio-socks", - "tokio-stream", - "tokio-tar", - "tokio-tungstenite", - "tokio-util", - "toml", - "torut", - "tracing", - "tracing-error 0.2.0", - "tracing-futures", - "tracing-subscriber 0.3.16", - "trust-dns-server", - "typed-builder", - "url", - "uuid 1.2.2", - "zeroize", -] - [[package]] name = "embassy_container_init" version = "0.1.0" @@ -2036,6 +1930,25 @@ dependencies = [ "bitmaps 3.2.0", ] +[[package]] +name = "include_dir" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +dependencies = [ + "proc-macro2 1.0.50", + "quote 1.0.23", +] + [[package]] name = "indenter" version = "0.3.3" @@ -2492,6 +2405,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "new_mime_guess" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2d684d1b59e0dc07b37e2203ef576987473288f530082512aff850585c61b1f" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -4208,6 +4131,114 @@ dependencies = [ "zeroize", ] +[[package]] +name = "start-os" +version = "0.3.4-rev.3" +dependencies = [ + "aes", + "async-compression", + "async-stream", + "async-trait", + "base32", + "base64 0.13.1", + "base64ct", + "basic-cookies", + "bollard", + "bytes", + "chrono", + "ciborium", + "clap 3.2.23", + "color-eyre", + "cookie", + "cookie_store 0.19.0", + "current_platform", + "digest 0.10.6", + "digest 0.9.0", + "divrem", + "ed25519", + "ed25519-dalek", + "embassy_container_init", + "emver", + "fd-lock-rs", + "futures", + "git-version", + "gpt", + "helpers", + "hex", + "hmac 0.12.1", + "http", + "hyper", + "hyper-ws-listener", + "imbl 2.0.0", + "include_dir", + "indexmap", + "ipnet", + "iprange", + "isocountry", + "itertools 0.10.5", + "josekit", + "jsonpath_lib", + "lazy_static", + "libc", + "log", + "mbrman", + "models", + "new_mime_guess", + "nix 0.25.1", + "nom", + "num", + "num_enum", + "openssh-keys", + "openssl", + "p256 0.12.0", + "patch-db", + "pbkdf2", + "pin-project", + "pkcs8", + "prettytable-rs", + "proptest", + "proptest-derive", + "rand 0.7.3", + "rand 0.8.5", + "regex", + "reqwest", + "reqwest_cookie_store", + "rpassword", + "rpc-toolkit", + "rust-argon2", + "scopeguard", + "serde", + "serde_json", + "serde_with 2.2.0", + "serde_yaml 0.9.16", + "sha2 0.10.6", + "sha2 0.9.9", + "simple-logging", + "sqlx", + "ssh-key", + "stderrlog", + "tar", + "thiserror", + "tokio", + "tokio-rustls", + "tokio-socks", + "tokio-stream", + "tokio-tar", + "tokio-tungstenite", + "tokio-util", + "toml", + "torut", + "tracing", + "tracing-error 0.2.0", + "tracing-futures", + "tracing-subscriber 0.3.16", + "trust-dns-server", + "typed-builder", + "url", + "uuid 1.2.2", + "zeroize", +] + [[package]] name = "stderrlog" version = "0.5.4" @@ -4845,6 +4876,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.8" diff --git a/system-images/compat/Cargo.toml b/system-images/compat/Cargo.toml index 1dc735fb4..735667a36 100644 --- a/system-images/compat/Cargo.toml +++ b/system-images/compat/Cargo.toml @@ -11,7 +11,7 @@ anyhow = { version = "1.0.40", features = ["backtrace"] } beau_collector = "0.2.1" clap = "2.33.3" dashmap = "5.3.2" -embassy-os = { path = "../../backend", default-features = false } +start-os = { path = "../../backend", default-features = false } emver = { version = "0.1.7", git = "https://github.com/Start9Labs/emver-rs.git", features = [ "serde", ] } diff --git a/system-images/compat/src/backup.rs b/system-images/compat/src/backup.rs index 2899b52fb..9e54100f8 100644 --- a/system-images/compat/src/backup.rs +++ b/system-images/compat/src/backup.rs @@ -1,6 +1,6 @@ use std::{path::Path, process::Stdio}; -use embassy::disk::main::DEFAULT_PASSWORD; +use startos::disk::main::DEFAULT_PASSWORD; pub fn create_backup( mountpoint: impl AsRef, @@ -19,17 +19,21 @@ pub fn create_backup( let mut data_cmd = std::process::Command::new("duplicity"); for exclude in exclude.lines().map(|s| s.trim()).filter(|s| !s.is_empty()) { if exclude.to_string().starts_with('!') { - data_cmd.arg(format!( - "--include={}", - data_path - .join(exclude.to_string().trim_start_matches('!')) - .display() - )).arg("--allow-source-mismatch"); + data_cmd + .arg(format!( + "--include={}", + data_path + .join(exclude.to_string().trim_start_matches('!')) + .display() + )) + .arg("--allow-source-mismatch"); } else { - data_cmd.arg(format!( - "--exclude={}", - data_path.join(exclude.to_string()).display() - )).arg("--allow-source-mismatch"); + data_cmd + .arg(format!( + "--exclude={}", + data_path.join(exclude.to_string()).display() + )) + .arg("--allow-source-mismatch"); } } let data_output = data_cmd diff --git a/system-images/compat/src/config/mod.rs b/system-images/compat/src/config/mod.rs index 1240f801a..b80af0cf1 100644 --- a/system-images/compat/src/config/mod.rs +++ b/system-images/compat/src/config/mod.rs @@ -3,11 +3,11 @@ use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::path::Path; use beau_collector::BeauCollector; -use embassy::config::action::SetResult; -use embassy::config::{spec, Config}; -use embassy::s9pk::manifest::PackageId; -use embassy::status::health_check::HealthCheckId; use linear_map::LinearMap; +use startos::config::action::SetResult; +use startos::config::{spec, Config}; +use startos::s9pk::manifest::PackageId; +use startos::status::health_check::HealthCheckId; pub mod rules; diff --git a/system-images/compat/src/config/rules.rs b/system-images/compat/src/config/rules.rs index d3df0b7cf..ea2650237 100644 --- a/system-images/compat/src/config/rules.rs +++ b/system-images/compat/src/config/rules.rs @@ -7,8 +7,8 @@ use pest::Parser; use rand::SeedableRng; use serde_json::Value; -use embassy::config::util::STATIC_NULL; -use embassy::config::Config; +use startos::config::util::STATIC_NULL; +use startos::config::Config; #[derive(Parser)] #[grammar = "config/rule_parser.pest"] diff --git a/system-images/compat/src/main.rs b/system-images/compat/src/main.rs index dcd723882..338e01f5b 100644 --- a/system-images/compat/src/main.rs +++ b/system-images/compat/src/main.rs @@ -19,8 +19,8 @@ use clap::{App, Arg, SubCommand}; use config::{ apply_dependency_configuration, validate_configuration, validate_dependency_configuration, }; -use embassy::config::action::ConfigRes; use serde_json::json; +use startos::config::action::ConfigRes; const PROPERTIES_FALLBACK_MESSAGE: &str = "Could not find properties. The service might still be starting";