Skip to content

Instantly share code, notes, and snippets.

@throwaway96
Last active September 8, 2024 17:11
Show Gist options
  • Save throwaway96/1558bc833029224005b794009a2aa8b1 to your computer and use it in GitHub Desktop.
Save throwaway96/1558bc833029224005b794009a2aa8b1 to your computer and use it in GitHub Desktop.
Little webOS scripts

This is a collection of a few of my smaller webOS scripts.

License: AGPL v3 or later

#!/bin/sh
# backup-part.sh
# usage: backup-part.sh <partition id>
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
if test "${#}" -ne 1; then
echo >&2 "${0}: <partition id>"
exit 1
fi
partid="${1}"
# check that partid is numeric with POSIX-compatible regex (implicit ^ at start)
if ! expr "${partid}" : '[1-9][0-9]*$' >/dev/null; then
echo >&2 'error: invalid partition id'
exit 2
fi
# simpler
#partname="$(grep -e "^part${partid}:" -- '/proc/partinfo' | cut -d '"' -f 2)"
# single process, stricter
partname="$(sed -n -e "s/^part${partid}: [0-9a-f]\\{8,\\} [0-9a-f]\\{8,\\} \"\\(.*\\)\"\$/\\1/p" -- '/proc/partinfo')"
if test -z "${partname}"; then
echo >&2 "error: partition ${partid} not found"
exit 3
fi
binpath="part${partid}-${partname}.bin"
devpath="/dev/mmcblk0p${partid}"
if ! test -e "${devpath}"; then
echo >&2 "error: device ${devpath} does not exist"
exit 4
elif ! test -b "${devpath}"; then
echo >&2 "error: ${devpath} is not a block device"
exit 5
elif ! test -r "${devpath}"; then
echo >&2 "error: ${devpath} not readable"
exit 6
fi
if test -e "${binpath}"; then
echo >&2 "error: ${binpath} already exists"
exit 7
fi
dd if="${devpath}" of="${binpath}"
# vim: noet:ts=8:sw=8
#!/bin/sh
# check-devmode-sig.sh
# usage: check-devmode-sig.sh
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
KEYFILE='/usr/palm/services/com.palm.service.devmode/pub.pem'
DEVSHFILE='/media/cryptofs/apps/usr/palm/services/com.palmdts.devmode.service/start-devmode.sh'
DEVSIGFILE='/media/cryptofs/apps/usr/palm/services/com.palmdts.devmode.service/start-devmode.sig'
if [ -e "${DEVSHFILE}" ]; then
if [ ! -f "${KEYFILE}" ]; then
echo "error: missing key file"
exit 1
fi
if [ ! -f "${DEVSIGFILE}" ]; then
echo "error: missing signature file"
exit 1
fi
if [ "$(openssl dgst -sha512 -verify "${KEYFILE}" -signature "${DEVSIGFILE}" "${DEVSHFILE}" 2>/dev/null)" != 'Verified OK' ]; then
echo "error: invalid signature"
exit 1
fi
echo "valid signature"
exit 0
else
echo "start-devmode.sh doesn't exist"
exit 0
fi
# vim: noet:ts=8:sw=8
#!/bin/sh
# install-cryptofs.sh
# usage: install-cryptofs.sh <ipk>
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
# check for a single argument
[ "${#}" -ne 1 ] && { echo >&2 "usage: ${0} <ipk>"; exit 1; }
# make sure arg is a file
[ -f "${1}" ] || { echo >&2 "error: not a file"; exit 1; }
ipk="$(realpath "${1}")"
payload="$(printf '{"subscribe":true,"target":{"deviceId":"INTERNAL_STORAGE","driveId":"","share":true},"id":"whatever","ipkUrl":"%s"}' "${ipk}")"
# exit after 30 seconds. hit ctrl+c to exit earlier
luna-send -w 30000 -i 'luna://com.webos.appInstallService/installLocal' "${payload}"
# vim: noet:ts=8:sw=8
#!/bin/sh
# install-dev.sh
# usage: install-dev.sh <ipk>
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
# check for a single argument
[ "${#}" -ne 1 ] && { echo >&2 "usage: ${0} <ipk>"; exit 1; }
# make sure arg is a file
[ -f "${1}" ] || { echo >&2 "error: not a file"; exit 1; }
# get absolute path
ipk="$(realpath "${1}")"
payload="$(printf '{"subscribe":true,"id":"com.ares.defaultName","ipkUrl":"%s"}' "${ipk}")"
# exit after 30 seconds. hit ctrl+c to exit earlier
luna-send-pub -w 30000 -i 'luna://com.webos.appInstallService/dev/install' "${payload}"
# vim: noet:ts=8:sw=8
#!/bin/sh
# launch.sh
# usage: launch.sh <app id>
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
# check for a single argument
[ "${#}" -ne 1 -o -z "${1}" ] && { echo >&2 "usage: ${0} <app id>"; exit 1; }
id="${1}"
payload="$(printf '{"id":"%s"}' "${id}")"
# wait up to 10 seconds. hit ctrl+c to exit earlier
luna-send-pub -w 10000 -n 1 -f 'luna://com.webos.applicationManager/launch' "${payload}"
#!/bin/sh
# remove-dev.sh
# usage: remove-dev.sh <appid>
# by throwaway96
# https://gist.github.com/throwaway96/1558bc833029224005b794009a2aa8b1
# Copyright 2024. Distributable under the terms of the AGPL v3 or later.
# SPDX-License-Identifier: AGPL-3.0-or-later
# check for a single argument
[ "${#}" -ne 1 -o -z "${1}" ] && { echo >&2 "usage: ${0} <appid>"; exit 1; }
payload="$(printf '{"subscribe":true,"id":"%s"}' "${1}")"
# exit after 10 seconds. hit ctrl+c to exit earlier
luna-send-pub -w 10000 -i 'luna://com.webos.appInstallService/dev/remove' "${payload}"
# vim: noet:ts=8:sw=8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment