Skip to content

Commit

Permalink
store app in /opt rather than /usr/lib
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed Apr 25, 2022
1 parent e8799b6 commit 04046a4
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deb/debian/homebridge.install
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var/lib/homebridge var/lib
usr/lib/homebridge usr/lib
opt/homebridge opt
4 changes: 2 additions & 2 deletions deb/debian/homebridge.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions deb/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions deb/debian/postrm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions deb/opt/homebridge/bashrc-hb-shell
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# bashrc file for the hb-shell command

source "/opt/homebridge/source.sh"
source "/opt/homebridge/bashrc"
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 0 additions & 6 deletions deb/usr/lib/homebridge/bashrc-hb-shell

This file was deleted.

3 changes: 1 addition & 2 deletions purge.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 04046a4

Please sign in to comment.