Skip to content

Commit

Permalink
handle https-enabled ui during migration
Browse files Browse the repository at this point in the history
  • Loading branch information
oznu committed May 7, 2022
1 parent 1b408e2 commit d30318d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions deb/debian/preinst
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ if [ "$1" = "install" ]; then
payload=$(echo -n '{"username":"homebridge-apt-pkg","name":"homebridge-apt-pkg","admin":true,"instanceId":"xxxxxxxx"}' | openssl base64 -e -A | sed s/\+/-/g | sed -E s/=+$// | sed 's/\//_/g')
signature=$(echo -n "${header}.${payload}"| openssl dgst -sha256 -hmac $secret -binary | openssl base64 -e -A | sed s/\+/-/g | sed -E s/=+$// | sed 's/\//_/g')
token="${header}.${payload}.${signature}"

# get the list of installed plugins from the running instance of the Homebridge UI
output=$(curl -sfk -H "Authorization: bearer ${token}" http://localhost:${ui_port}/api/plugins 2> /dev/null)
if [ "$?" = "0" ]; then
output=""
getPluginStatus="fail"
for protocol in "http" "https"; do
output=$(curl -sfk -H "Authorization: bearer ${token}" $protocol://localhost:${ui_port}/api/plugins 2> /dev/null)
if [ "$?" = "0" ]; then
getPluginStatus="success"
break
fi
done

if [ "$getPluginStatus" = "success" ]; then
# build a package.json like format containing the list of plugins the user has installed
dependencies=$(echo $output | jq -rM '. | map({(.name) : .installedVersion }) | add | del(."homebridge-config-ui-x") | del(."homebridge")')
packageJson=$(jq ".dependencies += $dependencies" <<< '{ "dependencies": {} }')
Expand Down

0 comments on commit d30318d

Please sign in to comment.