#!/bin/sh
# This file is from getwdbootmsg repo

usr_reboot_file="/var/local/telem/user-reboot"
msg=""
brargs=""
while : ; do
	case "$1" in
	-m) { msg="$2"; shift; } ;;
	-d) { brargs="$brargs $1 $2"; shift; } ;;
	-f|-n) brargs="$brargs $1" ;;
	--)
		shift
		break
		;;
	-*)
		busybox reboot -h
		exit 0
		;;
	*)
		break
		;;
	esac
	shift
done

# Get parent process tree
parentp="$(pstree -p -s -A $PPID | grep -o -- "^.*($PPID)")"

cat > "$usr_reboot_file" << EOL
rmsg='$msg'
rparent='$parentp'
rargs='$brargs'
EOL

busybox reboot $brargs
