diff --git a/.prettierrc.js b/.prettierrc.js index 5e206f17a..6077f8584 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 e44995f9b..273d0d276 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 ed760c3a8..3c1510841 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 1fea90c3e..6ea4936b8 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 90de1b669..7b992ed17 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 e484d920f..89d7414c1 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 55d151721..a0398ef77 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 17ee90882..7f0764c33 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 3a2eb0ada..60be03546 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