feat: init
This commit is contained in:
commit
b1bfed4a2d
19 changed files with 176 additions and 0 deletions
61
rootfs/etc/s6-overlay/scripts/setup.sh
Executable file
61
rootfs/etc/s6-overlay/scripts/setup.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/command/with-contenv sh
|
||||
|
||||
# user defaults
|
||||
[ -e /homebridge/startup.sh ] || cp /defaults/startup.sh /homebridge/startup.sh
|
||||
|
||||
# setup homebridge
|
||||
mkdir -p /homebridge
|
||||
if [ "$(realpath /var/lib/homebridge)" != "/homebridge" ]; then
|
||||
rm -rf /var/lib/homebridge
|
||||
ln -sf /homebridge /var/lib/homebridge
|
||||
fi
|
||||
|
||||
# fix a mistake where we were creating a symlink loop
|
||||
if [ -h "/homebridge/homebridge" ] && [ "$(realpath /homebridge/homebridge)" = "/homebridge" ]; then
|
||||
rm /homebridge/homebridge
|
||||
fi
|
||||
|
||||
cd /homebridge
|
||||
|
||||
# set the .npmrc file
|
||||
cp /defaults/.npmrc /homebridge/.npmrc
|
||||
|
||||
# remove the package-lock.json
|
||||
if [ -e /homebridge/package-lock.json ]; then
|
||||
rm -rf /homebridge/package-lock.json
|
||||
fi
|
||||
|
||||
# if coming from an old pnpm based install, delete plugins so they are freshly installed
|
||||
if [ -e /homebridge/pnpm-lock.yaml ]; then
|
||||
rm -rf /homebridge/node_modules
|
||||
rm -rf /homebridge/pnpm-lock.yaml
|
||||
rm -rf /homebridge/package-lock.json
|
||||
fi
|
||||
|
||||
# setup initial package.json with homebridge
|
||||
if [ ! -e /homebridge/package.json ]; then
|
||||
HOMEBRIDGE_VERSION="$(curl -sf https://registry.npmjs.org/homebridge/latest | jq -r '.version')"
|
||||
echo "{ \"dependencies\": { \"homebridge\": \"$HOMEBRIDGE_VERSION\" }}" | jq . > /homebridge/package.json
|
||||
fi
|
||||
|
||||
# remove homebridge-config-ui-x from the package.json
|
||||
if [ -e /homebridge/package.json ]; then
|
||||
if [ "$(cat /homebridge/package.json | jq -r '.dependencies."homebridge-config-ui-x"')" != "null" ]; then
|
||||
packageJson="$(cat /homebridge/package.json | jq -rM 'del(."dependencies"."homebridge-config-ui-x")')"
|
||||
if [ "$?" = "0" ]; then
|
||||
printf "$packageJson" > /homebridge/package.json
|
||||
echo "Removed homebridge-config-ui-x from package.json"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# source the setup script
|
||||
if [ -f /opt/homebridge/source.sh ]; then
|
||||
. "/opt/homebridge/source.sh"
|
||||
fi
|
||||
|
||||
# install plugins
|
||||
echo "Installing Homebridge and user plugins, please wait..."
|
||||
npm --prefix /homebridge install
|
||||
|
||||
exit 0
|
15
rootfs/etc/s6-overlay/scripts/userdata.sh
Executable file
15
rootfs/etc/s6-overlay/scripts/userdata.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/command/with-contenv sh
|
||||
|
||||
if [ -f /opt/homebridge/source.sh ]; then
|
||||
. "/opt/homebridge/source.sh"
|
||||
fi
|
||||
|
||||
# run user defined custom startup script
|
||||
if [ -f /homebridge/startup.sh ]; then
|
||||
echo "Executing user startup script /homebridge/startup.sh"
|
||||
chmod +x /homebridge/startup.sh
|
||||
cd /homebridge
|
||||
/homebridge/startup.sh
|
||||
fi
|
||||
|
||||
exit 0
|
Loading…
Add table
Add a link
Reference in a new issue