From 7a7d5aae9efdd29215426a09b1fb0a6f2df304b6 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 9 Dec 2024 20:22:01 +0100 Subject: [PATCH 01/47] chore: format shell scripts (#17674) --- .prettierrc.js | 1 + package-lock.json | 41 ++++++++ package.json | 5 +- packaging/docker/bin/entrypoint.sh | 46 ++++----- packaging/gokrazy/run.sh | 161 ++++++++++++++--------------- packaging/scripts/postinstall.sh | 25 +++-- packaging/scripts/postremove.sh | 19 ++-- packaging/scripts/preinstall.sh | 158 ++++++++++++++-------------- packaging/scripts/preremove.sh | 2 +- 9 files changed, 249 insertions(+), 209 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index 5e206f17a6..6077f85847 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,5 @@ export default { printWidth: 100, trailingComma: "es5", + plugins: ["prettier-plugin-sh"], }; diff --git a/package-lock.json b/package-lock.json index e44995f9b1..273d0d2760 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "histoire": "^0.17.0", "markty-toml": "^0.1.1", "prettier": "^3.0.0", + "prettier-plugin-sh": "^0.14.0", "prettier-plugin-toml": "^2.0.1", "rollup-plugin-visualizer": "^5.8.3", "smoothscroll-polyfill": "^0.4.4", @@ -7317,6 +7318,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/mvdan-sh": { + "version": "0.10.1", + "resolved": "https://registry.npmjs.org/mvdan-sh/-/mvdan-sh-0.10.1.tgz", + "integrity": "sha512-kMbrH0EObaKmK3nVRKUIIya1dpASHIEusM13S4V1ViHFuxuNxCo+arxoa6j/dbV22YBGjl7UKJm9QQKJ2Crzhg==", + "license": "BSD-3-Clause" + }, "node_modules/nanoid": { "version": "3.3.8", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", @@ -7861,6 +7868,25 @@ "node": ">=6.0.0" } }, + "node_modules/prettier-plugin-sh": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-sh/-/prettier-plugin-sh-0.14.0.tgz", + "integrity": "sha512-hfXulj5+zEl/ulrO5kMuuTPKmXvOg0bnLHY1hKFNN/N+/903iZbNp8NyZBTsgI8dtkSgFfAEIQq0IQTyP1ZVFQ==", + "license": "MIT", + "dependencies": { + "mvdan-sh": "^0.10.1", + "sh-syntax": "^0.4.1" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + }, + "peerDependencies": { + "prettier": "^3.0.3" + } + }, "node_modules/prettier-plugin-toml": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/prettier-plugin-toml/-/prettier-plugin-toml-2.0.1.tgz", @@ -8390,6 +8416,21 @@ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", "license": "ISC" }, + "node_modules/sh-syntax": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/sh-syntax/-/sh-syntax-0.4.2.tgz", + "integrity": "sha512-/l2UZ5fhGZLVZa16XQM9/Vq/hezGGbdHeVEA01uWjOL1+7Ek/gt6FquW0iKKws4a9AYPYvlz6RyVvjh3JxOteg==", + "license": "MIT", + "dependencies": { + "tslib": "^2.6.2" + }, + "engines": { + "node": ">=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", diff --git a/package.json b/package.json index ed760c3a88..3c15108414 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "vite build", "test": "TZ=Europe/Berlin vitest", - "lint": "prettier assets './**/*.{yml,yaml}' --write && eslint assets/**/*.js assets/**/*.vue --fix --max-warnings=0", + "lint": "prettier assets './**/*.{yml,yaml,sh}' --write && eslint assets/**/*.js assets/**/*.vue --fix --max-warnings=0", "dev": "vite", "histoire": "histoire dev", "playwright": "playwright test --ui", @@ -47,6 +47,7 @@ "histoire": "^0.17.0", "markty-toml": "^0.1.1", "prettier": "^3.0.0", + "prettier-plugin-sh": "^0.14.0", "prettier-plugin-toml": "^2.0.1", "rollup-plugin-visualizer": "^5.8.3", "smoothscroll-polyfill": "^0.4.4", @@ -69,4 +70,4 @@ }, "license": "MIT", "repository": "github:evcc-io/evcc" -} +} \ No newline at end of file diff --git a/packaging/docker/bin/entrypoint.sh b/packaging/docker/bin/entrypoint.sh index 1fea90c3ed..6ea4936b8e 100755 --- a/packaging/docker/bin/entrypoint.sh +++ b/packaging/docker/bin/entrypoint.sh @@ -5,30 +5,30 @@ set -e HASSIO_OPTIONSFILE=/data/options.json if [ -f ${HASSIO_OPTIONSFILE} ]; then - CONFIG=$(grep -o '"config_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') - echo "Using config file: ${CONFIG}" + CONFIG=$(grep -o '"config_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') + echo "Using config file: ${CONFIG}" - SQLITE_FILE=$(grep -o '"sqlite_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') + SQLITE_FILE=$(grep -o '"sqlite_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') - if [ ! -f "${CONFIG}" ]; then - echo "Config not found. Please create a config under ${CONFIG}." - echo "For details see evcc documentation at https://github.com/evcc-io/evcc#readme." - else - if [ "${SQLITE_FILE}" ]; then - echo "starting evcc: 'EVCC_DATABASE_DSN=${SQLITE_FILE} evcc --config ${CONFIG}'" - exec env EVCC_DATABASE_DSN="${SQLITE_FILE}" evcc --config "${CONFIG}" - else - echo "starting evcc: 'evcc --config ${CONFIG}'" - exec evcc --config "${CONFIG}" - fi - fi + if [ ! -f "${CONFIG}" ]; then + echo "Config not found. Please create a config under ${CONFIG}." + echo "For details see evcc documentation at https://github.com/evcc-io/evcc#readme." + else + if [ "${SQLITE_FILE}" ]; then + echo "starting evcc: 'EVCC_DATABASE_DSN=${SQLITE_FILE} evcc --config ${CONFIG}'" + exec env EVCC_DATABASE_DSN="${SQLITE_FILE}" evcc --config "${CONFIG}" + else + echo "starting evcc: 'evcc --config ${CONFIG}'" + exec evcc --config "${CONFIG}" + fi + fi else - if [ "$1" = 'evcc' ]; then - shift - exec evcc "$@" - elif expr "$1" : '-.*' > /dev/null; then - exec evcc "$@" - else - exec "$@" - fi + if [ "$1" = 'evcc' ]; then + shift + exec evcc "$@" + elif expr "$1" : '-.*' > /dev/null; then + exec evcc "$@" + else + exec "$@" + fi fi diff --git a/packaging/gokrazy/run.sh b/packaging/gokrazy/run.sh index 90de1b669f..7b992ed17d 100755 --- a/packaging/gokrazy/run.sh +++ b/packaging/gokrazy/run.sh @@ -5,99 +5,98 @@ arch="${MACHINE:=amd64}" os="" if [ "$(uname)" == "Darwin" ]; then - os="darwin" + os="darwin" elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then - os="linux" + os="linux" fi - case $arch in - # arm64 emulator with kernel auto loading - arm64) - args=( - -name gokrazy-arm64 - -m 3G - -smp 2 - -M virt,highmem=off - -cpu cortex-a72 - -nographic - -drive file=${imagefile},format=raw - -bios ./packaging/gokrazy/QEMU_EFI.fd - ) + # arm64 emulator with kernel auto loading + arm64) + args=( + -name gokrazy-arm64 + -m 3G + -smp 2 + -M virt,highmem=off + -cpu cortex-a72 + -nographic + -drive file=${imagefile},format=raw + -bios ./packaging/gokrazy/QEMU_EFI.fd + ) - if [[ "$os" == "darwin" ]]; then - args+=(-nic vmnet-shared) - else - args+=(-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22) - args+=(-device e1000,netdev=net0) - fi - qemu-system-aarch64 "${args[@]}" - ;; + if [[ "$os" == "darwin" ]]; then + args+=(-nic vmnet-shared) + else + args+=(-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22) + args+=(-device e1000,netdev=net0) + fi + qemu-system-aarch64 "${args[@]}" + ;; - # raspi3b emulator with manual kernel loading - # requires kernel (./vmlinuz) and dtb file extraction from the drive.img, - # to be used as an arg (with -dtb, -kernel and -append) - # to instruct the vm on how to load the kernel - raspi3b) - if [[ "$os" == "darwin" ]]; then - args+=(-nic vmnet-shared) - fi + # raspi3b emulator with manual kernel loading + # requires kernel (./vmlinuz) and dtb file extraction from the drive.img, + # to be used as an arg (with -dtb, -kernel and -append) + # to instruct the vm on how to load the kernel + raspi3b) + if [[ "$os" == "darwin" ]]; then + args+=(-nic vmnet-shared) + fi - # Only works with qemu === v5.2.0 - # because for lower versions networking is missing. - # It was introduced in qemu v5.2.0 via usb networking (-device usb-net), but it is very very slow at the point that gokrazy network updates fail. - # For qemu versions >= v6.0.0, the /gokrazy/init process crashes early at gokrazy.Boot(). To be investigated. - qemu_version="$(qemu-system-aarch64 --version | sed -nr 's/^.*version\s([.0-9]*).*$/\1/p')" - if [[ "$qemu_version" != "5.2.0" ]]; then + # Only works with qemu === v5.2.0 + # because for lower versions networking is missing. + # It was introduced in qemu v5.2.0 via usb networking (-device usb-net), but it is very very slow at the point that gokrazy network updates fail. + # For qemu versions >= v6.0.0, the /gokrazy/init process crashes early at gokrazy.Boot(). To be investigated. + qemu_version="$(qemu-system-aarch64 --version | sed -nr 's/^.*version\s([.0-9]*).*$/\1/p')" + if [[ "$qemu_version" != "5.2.0" ]]; then echo "error: incompatible qemu-system-aarch64 version: $qemu_version. gokrazy on raspi3b can only run on 5.2.0" - exit 1; - fi + exit 1 + fi - # Extract the kernel (vmlinuz) and the dtb file from the drive.img first - ./extract_kernel.sh - args=( - -name gokrazy-arm64-raspi3b - -m 1024 - -no-reboot - -M raspi3b - -append "console=tty1 console=ttyAMA0,115200 dwc_otg.fiq_fsm_enable=0 root=/dev/mmcblk0p2 init=/gokrazy/init rootwait panic=10 oops=panic" - -dtb ./bcm2710-rpi-3-b-plus.dtb - -nographic - -serial mon:stdio - -drive file=${imagefile},format=raw - -kernel vmlinuz - -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22 - -device usb-net,netdev=net0 - ) + # Extract the kernel (vmlinuz) and the dtb file from the drive.img first + ./extract_kernel.sh + args=( + -name gokrazy-arm64-raspi3b + -m 1024 + -no-reboot + -M raspi3b + -append "console=tty1 console=ttyAMA0,115200 dwc_otg.fiq_fsm_enable=0 root=/dev/mmcblk0p2 init=/gokrazy/init rootwait panic=10 oops=panic" + -dtb ./bcm2710-rpi-3-b-plus.dtb + -nographic + -serial mon:stdio + -drive file=${imagefile},format=raw + -kernel vmlinuz + -netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22 + -device usb-net,netdev=net0 + ) - qemu-system-aarch64 "${args[@]}" - ;; + qemu-system-aarch64 "${args[@]}" + ;; - # amd64 emulator with kernel auto loading - amd64) - args=( - -name gokrazy-amd64 - -m 3G - -smp $(nproc) - -usb - -nographic - -serial mon:stdio - -boot order=d - -drive file=${imagefile},format=raw - ) + # amd64 emulator with kernel auto loading + amd64) + args=( + -name gokrazy-amd64 + -m 3G + -smp $(nproc) + -usb + -nographic + -serial mon:stdio + -boot order=d + -drive file=${imagefile},format=raw + ) - if [[ "$os" == "darwin" ]]; then - args+=(-nic vmnet-shared) - else - args+=(-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22) - args+=(-device e1000,netdev=net0) - fi + if [[ "$os" == "darwin" ]]; then + args+=(-nic vmnet-shared) + else + args+=(-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22) + args+=(-device e1000,netdev=net0) + fi - qemu-system-x86_64 "${args[@]}" - ;; + qemu-system-x86_64 "${args[@]}" + ;; - *) - echo -n "unsupported arch ${arch}" - exit - ;; + *) + echo -n "unsupported arch ${arch}" + exit + ;; esac diff --git a/packaging/scripts/postinstall.sh b/packaging/scripts/postinstall.sh index e484d920f1..89d7414c1d 100644 --- a/packaging/scripts/postinstall.sh +++ b/packaging/scripts/postinstall.sh @@ -13,16 +13,15 @@ askUserKeepFile() { echo "Shall '$1' be deleted? [Y/n]: " read answer case "$answer" in - n*|N*) + n* | N*) echo "Ok. We will keep that file. Keep in mind that you may need to alter it if any changes are done upstream. Your answer is saved for the future." return 1 ;; - y*|Y*|"") + y* | Y* | "") echo "The file will be deleted." return 0 ;; - *) - ;; + *) ;; esac done } @@ -53,7 +52,7 @@ if [ "$1" = "configure" ]; then askUserKeepFile "$USR_LOCAL_BIN" || KEEP_USR_LOCAL_BIN=$? fi # Save the user decision - cat > "$USER_CHOICE_CONFIG" < "$USER_CHOICE_CONFIG" << EOF #!/bin/sh KEEP_ETC_SERVICE=$KEEP_ETC_SERVICE KEEP_USR_LOCAL_BIN=$KEEP_USR_LOCAL_BIN @@ -71,31 +70,31 @@ EOF fi fi -if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then +if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ]; then # This will only remove masks created by d-s-h on package removal. - deb-systemd-helper unmask evcc.service >/dev/null || true + deb-systemd-helper unmask evcc.service > /dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled evcc.service; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. - deb-systemd-helper enable evcc.service >/dev/null || true + deb-systemd-helper enable evcc.service > /dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. - deb-systemd-helper update-state evcc.service >/dev/null || true + deb-systemd-helper update-state evcc.service > /dev/null || true fi # Restart only if it was already started if [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true + systemctl --system daemon-reload > /dev/null || true if [ -f $RESTART_FLAG_FILE ]; then - deb-systemd-invoke start evcc.service >/dev/null || true + deb-systemd-invoke start evcc.service > /dev/null || true rm $RESTART_FLAG_FILE elif [ -n "$2" ]; then - deb-systemd-invoke try-restart evcc.service >/dev/null || true + deb-systemd-invoke try-restart evcc.service > /dev/null || true else - deb-systemd-invoke start evcc.service >/dev/null || true + deb-systemd-invoke start evcc.service > /dev/null || true fi fi fi diff --git a/packaging/scripts/postremove.sh b/packaging/scripts/postremove.sh index 55d151721c..a0398ef775 100644 --- a/packaging/scripts/postremove.sh +++ b/packaging/scripts/postremove.sh @@ -2,25 +2,25 @@ set -e if [ -d /run/systemd/system ]; then - systemctl --system daemon-reload >/dev/null || true + systemctl --system daemon-reload > /dev/null || true fi if [ "$1" = "remove" ]; then if [ -x "/usr/bin/deb-systemd-helper" ]; then - deb-systemd-helper mask evcc.service >/dev/null || true + deb-systemd-helper mask evcc.service > /dev/null || true fi fi if [ "$1" = "purge" ]; then if [ -x "/usr/bin/deb-systemd-helper" ]; then - deb-systemd-helper purge evcc.service >/dev/null || true - deb-systemd-helper unmask evcc.service >/dev/null || true + deb-systemd-helper purge evcc.service > /dev/null || true + deb-systemd-helper unmask evcc.service > /dev/null || true fi fi # if interactive: call `/usr/bin/evcc checkconfig` and check the return code (newer version) # if return code is 0, do nothing -# else: Ask user if he wants to keep the old version (working) or the new version (not working) +# else: Ask user if he wants to keep the old version (working) or the new version (not working) # Remember the choice with /tmp/.evccrollback and fail new-postrm failed-upgrade old-version new-version to initiate dpkg's rollback if [ "$1" = "upgrade" ] && [ -t 0 ]; then if ! EVCC_DATABASE_DSN=/var/lib/evcc/evcc.db /usr/bin/evcc checkconfig > /dev/null; then @@ -34,22 +34,21 @@ if [ "$1" = "upgrade" ] && [ -t 0 ]; then echo "Do you want to keep your old (working) version? [Y/n]: " read choice case "$choice" in - n*|N*|"") + n* | N* | "") echo "We will keep the new version. Your configuration stays untouched!" break ;; - y*|Y*) + y* | Y*) echo "The old version will be restored. Your configuration stays untouched! Following errors are intended:" touch /tmp/.evccrollback exit 1 break ;; - *) - ;; + *) ;; esac done fi -fi +fi # if upgrade goal fails, new-postrm failed-upgrade old-version new-version is called. It should fail to initiate rollback if [ "$1" = "failed-upgrade" ]; then diff --git a/packaging/scripts/preinstall.sh b/packaging/scripts/preinstall.sh index 17ee90882a..7f0764c333 100644 --- a/packaging/scripts/preinstall.sh +++ b/packaging/scripts/preinstall.sh @@ -13,92 +13,92 @@ EVCC_HOME="/var/lib/$EVCC_USER" RESTART_FLAG_FILE="/tmp/.restartEvccOnUpgrade" copyDbToUserDir() { - CURRENT_USER=$(systemctl show -pUser evcc | cut -d= -f2) - if [ -z "$CURRENT_USER" ]; then - CURRENT_USER=root - fi - CURRENT_HOME=$(getent passwd "$CURRENT_USER" | cut -d: -f6) - COPIED_FLAG="$CURRENT_HOME/.evcc/.copiedToEvccUser" - if [ -f "$CURRENT_HOME/.evcc/evcc.db" ] && [ ! -f "$COPIED_FLAG" ]; then - if [ -f "$EVCC_HOME/evcc.db" ]; then - echo "--------------------------------------------------------------------------------" - echo "Not copying $CURRENT_HOME/.evcc/evcc.db to $EVCC_HOME/evcc.db, since there is" - echo "already a database there." - echo "Either delete one of the databases or run 'touch $COPIED_FLAG' to keep both," - echo "then restart installation." - echo "Hint: usually the larger one is the one to keep." - ls -la "$CURRENT_HOME/.evcc/evcc.db" "$EVCC_HOME/evcc.db" - echo "--------------------------------------------------------------------------------" - exit 1 - else - cp -Rp "$CURRENT_HOME"/.evcc/evcc.db "$EVCC_HOME" - fi - chown "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME/evcc.db" - touch "$COPIED_FLAG" - if [ -n "$(ls -A /etc/systemd/system/evcc.service.d 2>/dev/null)" ]; then - echo "--------------------------------------------------------------------------------" - echo "You have overrides defined in /etc/systemd/system/evcc.service.d." - echo "This update changes the evcc user to 'evcc' (from root) and the database file" - echo "to '/var/lib/evcc/evcc.db" - echo "Make sure that you neither override 'User' nor 'ExecStart'" - echo "Hint: you can delete all overrides with 'systemctl revert evcc'" - echo "As a precaution, evcc is not started even if it was previously started." - echo "--------------------------------------------------------------------------------" - rm -f "$RESTART_FLAG_FILE" - else - echo "--------------------------------------------------------------------------------" - echo "NOTE: evcc user has changed from $CURRENT_USER to $EVCC_USER, db has been copied to new" - echo "directory $EVCC_HOME/evcc.db, old db in $CURRENT_USER/.evcc has been retained." - echo "--------------------------------------------------------------------------------" - fi - fi - return 0 + CURRENT_USER=$(systemctl show -pUser evcc | cut -d= -f2) + if [ -z "$CURRENT_USER" ]; then + CURRENT_USER=root + fi + CURRENT_HOME=$(getent passwd "$CURRENT_USER" | cut -d: -f6) + COPIED_FLAG="$CURRENT_HOME/.evcc/.copiedToEvccUser" + if [ -f "$CURRENT_HOME/.evcc/evcc.db" ] && [ ! -f "$COPIED_FLAG" ]; then + if [ -f "$EVCC_HOME/evcc.db" ]; then + echo "--------------------------------------------------------------------------------" + echo "Not copying $CURRENT_HOME/.evcc/evcc.db to $EVCC_HOME/evcc.db, since there is" + echo "already a database there." + echo "Either delete one of the databases or run 'touch $COPIED_FLAG' to keep both," + echo "then restart installation." + echo "Hint: usually the larger one is the one to keep." + ls -la "$CURRENT_HOME/.evcc/evcc.db" "$EVCC_HOME/evcc.db" + echo "--------------------------------------------------------------------------------" + exit 1 + else + cp -Rp "$CURRENT_HOME"/.evcc/evcc.db "$EVCC_HOME" + fi + chown "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME/evcc.db" + touch "$COPIED_FLAG" + if [ -n "$(ls -A /etc/systemd/system/evcc.service.d 2> /dev/null)" ]; then + echo "--------------------------------------------------------------------------------" + echo "You have overrides defined in /etc/systemd/system/evcc.service.d." + echo "This update changes the evcc user to 'evcc' (from root) and the database file" + echo "to '/var/lib/evcc/evcc.db" + echo "Make sure that you neither override 'User' nor 'ExecStart'" + echo "Hint: you can delete all overrides with 'systemctl revert evcc'" + echo "As a precaution, evcc is not started even if it was previously started." + echo "--------------------------------------------------------------------------------" + rm -f "$RESTART_FLAG_FILE" + else + echo "--------------------------------------------------------------------------------" + echo "NOTE: evcc user has changed from $CURRENT_USER to $EVCC_USER, db has been copied to new" + echo "directory $EVCC_HOME/evcc.db, old db in $CURRENT_USER/.evcc has been retained." + echo "--------------------------------------------------------------------------------" + fi + fi + return 0 } if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then if [ -d /run/systemd/system ] && /bin/systemctl status evcc.service > /dev/null 2>&1; then - deb-systemd-invoke stop evcc.service >/dev/null || true - touch "$RESTART_FLAG_FILE" + deb-systemd-invoke stop evcc.service > /dev/null || true + touch "$RESTART_FLAG_FILE" + fi + if ! getent group "$EVCC_GROUP" > /dev/null 2>&1; then + addgroup --system "$EVCC_GROUP" --quiet + fi + if ! getent passwd "$EVCC_USER" > /dev/null 2>&1; then + adduser --quiet --system --ingroup "$EVCC_GROUP" \ + --disabled-password --shell /bin/false \ + --gecos "evcc runtime user" --home "$EVCC_HOME" "$EVCC_USER" + chown -R "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME" + adduser --quiet "$EVCC_USER" dialout + else + adduser --quiet "$EVCC_USER" dialout + homedir=$(getent passwd "$EVCC_USER" | cut -d: -f6) + if [ "$homedir" != "$EVCC_HOME" ]; then + mkdir -p "$EVCC_HOME" + chown "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME" + process=$(pgrep -u "$EVCC_USER") || true + if [ -z "$process" ]; then + usermod -d "$EVCC_HOME" "$EVCC_USER" + if [ -f "$homedir/.evcc/evcc.db" ]; then + cp "$homedir/.evcc/evcc.db" "$EVCC_HOME" && touch "$homedir/.evcc/.copiedToEvccUser" + fi + else + echo "--------------------------------------------------------------------------------" + echo "Warning: evcc's home directory is incorrect ($homedir)" + echo "but can't be changed because at least one other process is using it." + echo "Stop offending process(es), then restart installation." + echo "Hint: You can list the offending processes using 'pgrep -u $EVCC_USER -a'" + echo "Note that you should NOT use the evcc user as login user, since that will" + echo "inevitably lead to this error." + echo "in that case, please create a different user as login user." + echo "--------------------------------------------------------------------------------" + exit 1 + fi + fi fi - if ! getent group "$EVCC_GROUP" > /dev/null 2>&1 ; then - addgroup --system "$EVCC_GROUP" --quiet - fi - if ! getent passwd "$EVCC_USER" > /dev/null 2>&1 ; then - adduser --quiet --system --ingroup "$EVCC_GROUP" \ - --disabled-password --shell /bin/false \ - --gecos "evcc runtime user" --home "$EVCC_HOME" "$EVCC_USER" - chown -R "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME" - adduser --quiet "$EVCC_USER" dialout - else - adduser --quiet "$EVCC_USER" dialout - homedir=$(getent passwd "$EVCC_USER" | cut -d: -f6) - if [ "$homedir" != "$EVCC_HOME" ]; then - mkdir -p "$EVCC_HOME" - chown "$EVCC_USER:$EVCC_GROUP" "$EVCC_HOME" - process=$(pgrep -u "$EVCC_USER") || true - if [ -z "$process" ]; then - usermod -d "$EVCC_HOME" "$EVCC_USER" - if [ -f "$homedir/.evcc/evcc.db" ]; then - cp "$homedir/.evcc/evcc.db" "$EVCC_HOME" && touch "$homedir/.evcc/.copiedToEvccUser" - fi - else - echo "--------------------------------------------------------------------------------" - echo "Warning: evcc's home directory is incorrect ($homedir)" - echo "but can't be changed because at least one other process is using it." - echo "Stop offending process(es), then restart installation." - echo "Hint: You can list the offending processes using 'pgrep -u $EVCC_USER -a'" - echo "Note that you should NOT use the evcc user as login user, since that will" - echo "inevitably lead to this error." - echo "in that case, please create a different user as login user." - echo "--------------------------------------------------------------------------------" - exit 1 - fi - fi - fi fi if [ "$1" = "upgrade" ]; then - copyDbToUserDir + copyDbToUserDir fi -exit 0 \ No newline at end of file +exit 0 diff --git a/packaging/scripts/preremove.sh b/packaging/scripts/preremove.sh index 3a2eb0adaf..60be03546f 100644 --- a/packaging/scripts/preremove.sh +++ b/packaging/scripts/preremove.sh @@ -2,5 +2,5 @@ set -e if [ -d /run/systemd/system ] && [ "$1" = remove ]; then - deb-systemd-invoke stop evcc.service >/dev/null || true + deb-systemd-invoke stop evcc.service > /dev/null || true fi From 7b7f16d935a8006d05aca5dcc96a955f7fa1f4d6 Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 9 Dec 2024 20:58:22 +0100 Subject: [PATCH 02/47] chore: prepare deprecating legacy apt repo (#17660) --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 832337dd0f..3c1c7ce574 100644 --- a/Makefile +++ b/Makefile @@ -97,11 +97,13 @@ publish-release:: apt-nightly:: $(foreach file, $(wildcard $(PACKAGES)/*.deb), \ cloudsmith push deb evcc/unstable/any-distro/any-version $(file); \ + cloudsmith push deb evcc/unstable-cached/any-distro/any-version $(file); \ ) apt-release:: $(foreach file, $(wildcard $(PACKAGES)/*.deb), \ cloudsmith push deb evcc/stable/any-distro/any-version $(file); \ + cloudsmith push deb evcc/stable-cached/any-distro/any-version $(file); \ ) # gokrazy image From e839dd74237c61c149f01fa8353f6f8a69b427ea Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 9 Dec 2024 20:59:10 +0100 Subject: [PATCH 03/47] Revert "chore: prepare deprecating legacy apt repo (#17660)" This reverts commit 7b7f16d935a8006d05aca5dcc96a955f7fa1f4d6. --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index 3c1c7ce574..832337dd0f 100644 --- a/Makefile +++ b/Makefile @@ -97,13 +97,11 @@ publish-release:: apt-nightly:: $(foreach file, $(wildcard $(PACKAGES)/*.deb), \ cloudsmith push deb evcc/unstable/any-distro/any-version $(file); \ - cloudsmith push deb evcc/unstable-cached/any-distro/any-version $(file); \ ) apt-release:: $(foreach file, $(wildcard $(PACKAGES)/*.deb), \ cloudsmith push deb evcc/stable/any-distro/any-version $(file); \ - cloudsmith push deb evcc/stable-cached/any-distro/any-version $(file); \ ) # gokrazy image From d79f823f5b2ff98fb317bf8392afbd869604b2a5 Mon Sep 17 00:00:00 2001 From: premultiply <4681172+premultiply@users.noreply.github.com> Date: Mon, 9 Dec 2024 21:02:59 +0100 Subject: [PATCH 04/47] chore: fix (#17556) --- .devcontainer/devcontainer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2f67200fca..48745c6f41 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,15 +7,19 @@ "ghcr.io/devcontainers/features/docker-outside-of-docker:1": { "moby": true, "installDockerBuildx": true, + "installDockerComposeSwitch": true, "version": "latest", "dockerDashComposeVersion": "v2" }, "ghcr.io/devcontainers/features/node:1": { "nodeGypDependencies": true, "installYarnUsingApt": true, - "version": "latest", + "version": "lts", "pnpmVersion": "latest", "nvmVersion": "latest" + }, + "ghcr.io/devcontainers/features/go:1": { + "version": "latest" } }, "postCreateCommand": "make install-ui && make install", From dda47c4455b0ac37d489e8d711f38f579eec336d Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Tue, 10 Dec 2024 14:38:02 +0100 Subject: [PATCH 05/47] Repeating plan: fixed finish behaviour --- core/loadpoint.go | 9 +++++++++ core/loadpoint_plan.go | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/core/loadpoint.go b/core/loadpoint.go index 0a2a1e579a..0ce6854283 100644 --- a/core/loadpoint.go +++ b/core/loadpoint.go @@ -939,6 +939,15 @@ func (lp *Loadpoint) socBasedPlanning() bool { return (v != nil && v.Capacity() > 0) && (lp.vehicleHasSoc() || lp.vehicleSoc > 0) } +// repeatingPlanning returns true if the current plan is a repeating plan +func (lp *Loadpoint) repeatingPlanning() bool { + if !lp.socBasedPlanning() { + return false + } + _, _, id := lp.nextVehiclePlan() + return id > 1 +} + // vehicleHasSoc returns true if active vehicle supports returning soc, i.e. it is not an offline vehicle func (lp *Loadpoint) vehicleHasSoc() bool { return lp.GetVehicle() != nil && !lp.vehicleHasFeature(api.Offline) diff --git a/core/loadpoint_plan.go b/core/loadpoint_plan.go index 90010ac128..2b4ec38130 100644 --- a/core/loadpoint_plan.go +++ b/core/loadpoint_plan.go @@ -28,9 +28,11 @@ func (lp *Loadpoint) setPlanActive(active bool) { } } -// deletePlan deletes the charging plan, either loadpoint or vehicle -func (lp *Loadpoint) deletePlan() { - if !lp.socBasedPlanning() { +// finishedPlan deletes the charging plan, either loadpoint or vehicle +func (lp *Loadpoint) finishedPlan() { + if lp.repeatingPlanning() { + return // noting to do + } else if !lp.socBasedPlanning() { lp.setPlanEnergy(time.Time{}, 0) } else if v := lp.GetVehicle(); v != nil { vehicle.Settings(lp.log, v).SetPlanSoc(time.Time{}, 0) @@ -104,7 +106,7 @@ func (lp *Loadpoint) plannerActive() (active bool) { // keep overrunning plans as long as a vehicle is connected if lp.clock.Until(planTime) < 0 && (!lp.planActive || !lp.connected()) { lp.log.DEBUG.Println("plan: deleting expired plan") - lp.deletePlan() + lp.finishedPlan() return false } @@ -117,7 +119,7 @@ func (lp *Loadpoint) plannerActive() (active bool) { return true } - lp.deletePlan() + lp.finishedPlan() return false } From 3aa2915cb997784090dd047b18066e72e1f33142 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Tue, 10 Dec 2024 14:42:43 +0100 Subject: [PATCH 06/47] Vehicle status: improve wrap behavior (#17667) --- assets/js/components/VehicleStatus.story.vue | 5 ++--- assets/js/components/VehicleStatus.vue | 11 ++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/assets/js/components/VehicleStatus.story.vue b/assets/js/components/VehicleStatus.story.vue index 5e75a69cf9..df3c82b3c8 100644 --- a/assets/js/components/VehicleStatus.story.vue +++ b/assets/js/components/VehicleStatus.story.vue @@ -14,7 +14,7 @@ const planProjectedEnd = getFutureTime(5, 43);