#!/system/bin/sh

set -eu
DATA=/data/adb/tvsmbmanager
umask 077

mkdir -p "$DATA"
if [ ! -f "$DATA/license.bin" ] || [ "$(wc -c < "$DATA/license.bin" 2>/dev/null)" != "32" ]; then
  dd if=/dev/urandom of="$DATA/license.bin" bs=32 count=1 2>/dev/null
fi
if [ ! -f "$DATA/install.id" ] || [ "$(wc -c < "$DATA/install.id" 2>/dev/null)" != "16" ]; then
  dd if=/dev/urandom of="$DATA/install.id" bs=16 count=1 2>/dev/null
fi
printf 1 > "$DATA/contract.version"
chown 0:0 "$DATA/license.bin" "$DATA/install.id" "$DATA/contract.version"
chmod 600 "$DATA/license.bin" "$DATA/install.id" "$DATA/contract.version"
test "$(stat -c '%u:%g:%a:%s' "$DATA/license.bin")" = "0:0:600:32"
test "$(stat -c '%u:%g:%a:%s' "$DATA/install.id")" = "0:0:600:16"
test "$(stat -c '%u:%g:%a:%s' "$DATA/contract.version")" = "0:0:600:1"
echo TVSMB_PAIRING_V1_OK
