From 04046a4438abe275c9164ace58ebb2d42e00bd3c Mon Sep 17 00:00:00 2001 From: "oz.nu" Date: Mon, 25 Apr 2022 09:57:44 +0000 Subject: [PATCH] store app in /opt rather than /usr/lib --- README.md | 6 +++--- build.sh | 6 +++--- deb/debian/homebridge.install | 2 +- deb/debian/homebridge.service | 4 ++-- deb/debian/postinst | 8 ++++---- deb/debian/postrm | 4 ++-- deb/{usr/lib => opt}/homebridge/bashrc | 0 deb/opt/homebridge/bashrc-hb-shell | 6 ++++++ deb/{usr/lib => opt}/homebridge/hb-shell | 2 +- deb/{usr/lib => opt}/homebridge/source.sh | 4 ++-- deb/{usr/lib => opt}/homebridge/start.sh | 4 ++-- deb/usr/lib/homebridge/bashrc-hb-shell | 6 ------ purge.sh | 3 +-- 13 files changed, 27 insertions(+), 28 deletions(-) rename deb/{usr/lib => opt}/homebridge/bashrc (100%) create mode 100755 deb/opt/homebridge/bashrc-hb-shell rename deb/{usr/lib => opt}/homebridge/hb-shell (72%) rename deb/{usr/lib => opt}/homebridge/source.sh (85%) rename deb/{usr/lib => opt}/homebridge/start.sh (88%) delete mode 100755 deb/usr/lib/homebridge/bashrc-hb-shell diff --git a/README.md b/README.md index aef4de4..17198d5 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ The bundled Node.js runtime is isolated and not exposed on the default PATH. To assist in debugging, a shell command `hb-shell` is added to the default PATH to allow the user to enter the Homebridge Shell Environment. When in the Homebridge Shell, users will have access to `node` and `pnpm` as they would expect. ```shell -# Node.js and package scripts are stored in /usr/lib/homebridge +# Node.js and package scripts are stored in /opt/homebridge -/usr/lib/homebridge +/opt/homebridge |-- bin | |-- corepack | |-- node @@ -107,7 +107,7 @@ To assist in debugging, a shell command `hb-shell` is added to the default PATH # "hb-shell" command to allow user access to the Homebridge env from the cli /usr/bin - |-- hb-shell -> /usr/lib/homebridge/hb-shell + |-- hb-shell -> /opt/homebridge/hb-shell # homebridge storage directory, plugins are stored in node_modules /var/lib/homebridge diff --git a/build.sh b/build.sh index e2fe56f..4368875 100755 --- a/build.sh +++ b/build.sh @@ -32,10 +32,10 @@ if [ ! -f "node-$NODE_VERSION-linux-$NODE_ARCH.tar.gz" ]; then curl -SLO "https://unofficial-builds.nodejs.org/download/release/$NODE_VERSION/node-$NODE_VERSION-linux-$NODE_ARCH.tar.gz" || curl -SLO "https://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-$NODE_ARCH.tar.gz" fi -tar xzf "node-$NODE_VERSION-linux-$NODE_ARCH.tar.gz" -C staging/usr/lib/homebridge/ --strip-components=1 --no-same-owner +tar xzf "node-$NODE_VERSION-linux-$NODE_ARCH.tar.gz" -C staging/opt/homebridge/ --strip-components=1 --no-same-owner -PATH="$(pwd)/staging/usr/lib/homebridge/bin:$PATH" -export npm_config_prefix=$(pwd)/staging/usr/lib/homebridge +PATH="$(pwd)/staging/opt/homebridge/bin:$PATH" +export npm_config_prefix=$(pwd)/staging/opt/homebridge export npm_config_store_dir=/var/lib/homebridge/node_modules/.pnpm-store npm install -g pnpm diff --git a/deb/debian/homebridge.install b/deb/debian/homebridge.install index 809ee46..c964192 100644 --- a/deb/debian/homebridge.install +++ b/deb/debian/homebridge.install @@ -1,2 +1,2 @@ var/lib/homebridge var/lib -usr/lib/homebridge usr/lib +opt/homebridge opt diff --git a/deb/debian/homebridge.service b/deb/debian/homebridge.service index d5cff38..7de3eae 100644 --- a/deb/debian/homebridge.service +++ b/deb/debian/homebridge.service @@ -4,10 +4,10 @@ Wants=network-online.target After=syslog.target network-online.target [Service] -User=homebridge Type=simple +User=homebridge WorkingDirectory=/var/lib/homebridge -ExecStart=/usr/lib/homebridge/start.sh +ExecStart=/opt/homebridge/start.sh Restart=always RestartSec=3 KillMode=process diff --git a/deb/debian/postinst b/deb/debian/postinst index 852d853..4f4a256 100755 --- a/deb/debian/postinst +++ b/deb/debian/postinst @@ -15,7 +15,7 @@ if [ "$1" = "configure" ] && [ $2 ]; then echo "Merging package.json file..." # enter homebridge env - . "/usr/lib/homebridge/source.sh" + . "/opt/homebridge/source.sh" # merge the new package.json into the old one, and save PACKAGE_JSON=$(jq -M -s '.[0] * .[1]' /tmp/homebridge-tmp/package.json /var/lib/homebridge/package.json) > /var/lib/homebridge/package.json @@ -40,10 +40,10 @@ if [ "$1" = "configure" ]; then adduser --system homebridge 2> /dev/null # copy .bashrc to service user home - cp /usr/lib/homebridge/bashrc /home/homebridge/.bashrc + cp /opt/homebridge/bashrc /home/homebridge/.bashrc # fix permissions - chown -R homebridge: /var/lib/homebridge /usr/lib/homebridge /home/homebridge/.bashrc + chown -R homebridge: /var/lib/homebridge /opt/homebridge /home/homebridge/.bashrc # clear any masks on the homebridge service systemctl unmask homebridge.service 2> /dev/null @@ -59,7 +59,7 @@ if [ "$1" = "configure" ]; then systemctl restart homebridge.service # create symlink to hb-shell - ln -fs /usr/lib/homebridge/hb-shell /usr/bin/hb-shell + ln -fs /opt/homebridge/hb-shell /usr/local/bin/hb-shell # add user to default groups if running on raspbian . /etc/os-release diff --git a/deb/debian/postrm b/deb/debian/postrm index f44cecf..8aeac69 100755 --- a/deb/debian/postrm +++ b/deb/debian/postrm @@ -10,11 +10,11 @@ if [ "$1" = "remove" ]; then systemctl disable homebridge.service 2> /dev/null # remove symlink to hb-shell - rm -rf /usr/bin/hb-shell + rm -rf /usr/local/bin/hb-shell # ensure package is completely gone rm -rf /var/lib/homebridge/node_modules /var/lib/homebridge/package.json /var/lib/homebridge/pnpm-lock.yaml - rm -rf /usr/lib/homebridge + rm -rf /opt/homebridge fi # if purging - delete the /var/lib/homebridge folder entirely diff --git a/deb/usr/lib/homebridge/bashrc b/deb/opt/homebridge/bashrc similarity index 100% rename from deb/usr/lib/homebridge/bashrc rename to deb/opt/homebridge/bashrc diff --git a/deb/opt/homebridge/bashrc-hb-shell b/deb/opt/homebridge/bashrc-hb-shell new file mode 100755 index 0000000..692ec76 --- /dev/null +++ b/deb/opt/homebridge/bashrc-hb-shell @@ -0,0 +1,6 @@ +#!/bin/sh + +# bashrc file for the hb-shell command + +source "/opt/homebridge/source.sh" +source "/opt/homebridge/bashrc" diff --git a/deb/usr/lib/homebridge/hb-shell b/deb/opt/homebridge/hb-shell similarity index 72% rename from deb/usr/lib/homebridge/hb-shell rename to deb/opt/homebridge/hb-shell index 1706315..92966d7 100755 --- a/deb/usr/lib/homebridge/hb-shell +++ b/deb/opt/homebridge/hb-shell @@ -9,4 +9,4 @@ printf "Entering Homebridge Shell. To exit type 'exit'.\n\n" cd "/var/lib/homebridge" -exec sudo --user homebridge bash --rcfile /usr/lib/homebridge/bashrc-hb-shell +exec sudo --user homebridge bash --rcfile /opt/homebridge/bashrc-hb-shell diff --git a/deb/usr/lib/homebridge/source.sh b/deb/opt/homebridge/source.sh similarity index 85% rename from deb/usr/lib/homebridge/source.sh rename to deb/opt/homebridge/source.sh index 874298b..a778814 100755 --- a/deb/usr/lib/homebridge/source.sh +++ b/deb/opt/homebridge/source.sh @@ -1,6 +1,6 @@ #!/bin/sh -nodeBin="/usr/lib/homebridge/bin" +nodeBin="/opt/homebridge/bin" HB_SERVICE_STORAGE_PATH="/var/lib/homebridge" export PATH="$nodeBin:$HB_SERVICE_STORAGE_PATH/node_modules/.bin:$PATH" @@ -10,7 +10,7 @@ export npm_config_global_style=true export npm_config_audit=false export npm_config_fund=false export npm_config_store_dir=$HB_SERVICE_STORAGE_PATH/node_modules/.pnpm-store -export npm_config_prefix=/usr/lib/homebridge +export npm_config_prefix=/opt/homebridge export HOMEBRIDGE_APT_PACKAGE=1 export UIX_BASE_PATH_OVERRIDE=$HB_SERVICE_STORAGE_PATH/node_modules/homebridge-config-ui-x diff --git a/deb/usr/lib/homebridge/start.sh b/deb/opt/homebridge/start.sh similarity index 88% rename from deb/usr/lib/homebridge/start.sh rename to deb/opt/homebridge/start.sh index 6bd91dd..23ec334 100755 --- a/deb/usr/lib/homebridge/start.sh +++ b/deb/opt/homebridge/start.sh @@ -1,10 +1,10 @@ #!/bin/sh HB_SERVICE_STORAGE_PATH="/var/lib/homebridge" -HB_SERVICE_NODE_EXEC_PATH="/usr/lib/homebridge/bin/node" +HB_SERVICE_NODE_EXEC_PATH="/opt/homebridge/bin/node" HB_SERVICE_EXEC_PATH="$HB_SERVICE_STORAGE_PATH/node_modules/homebridge-config-ui-x/dist/bin/hb-service.js" -. "/usr/lib/homebridge/source.sh" +. "/opt/homebridge/source.sh" # check for missing homebridge-config-ui-x if [ ! -f "$HB_SERVICE_EXEC_PATH" ]; then diff --git a/deb/usr/lib/homebridge/bashrc-hb-shell b/deb/usr/lib/homebridge/bashrc-hb-shell deleted file mode 100755 index 82c602c..0000000 --- a/deb/usr/lib/homebridge/bashrc-hb-shell +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -# bashrc file for the hb-shell command - -source "/usr/lib/homebridge/source.sh" -source "/usr/lib/homebridge/bashrc" diff --git a/purge.sh b/purge.sh index 6bea045..7d24048 100755 --- a/purge.sh +++ b/purge.sh @@ -1,7 +1,7 @@ #!/bin/bash # -# This script is to purge the s3 of older versions +# This script is to purge s3 of older package versions # # minimum version to keep @@ -58,6 +58,5 @@ for i in $(aws s3api list-objects --region $S3_REGION --bucket "$S3_BUCKET" --pr key=$(echo "$i" | tr -d '"') echo "Removing ($version) from s3 at $key" aws s3api delete-object --region $S3_REGION --bucket "$S3_BUCKET" --key="$key" --output=json - echo $? fi done