#!/bin/sh

PREREQ=""
prereqs()
{
	echo "$PREREQ"
}
case $1 in
# get pre-requisites
prereqs)
	prereqs
	exit 0
	;;
esac

get_json_value() {
    json=$1
    key=$2

    if [ -z "$3" ]; then
        num=1
    else
        num=$3
    fi

	# grep -o "\"${key}\":[^,}]*":
	#	- Finds lines containing the specified key and its value.
	#	- -o ensures only the matching part is returned.
	# sed -n "${num}p":
	# 	- Selects the num-th occurrence of the match.
	# awk -F: '{print $2}':
	#	- Splits the matched string by : and extracts the value part.
	# tr -d '"':
	# 	- Removes double quotes from the value.
	# sed 's/^[[:space:]]*//;s/[[:space:]]*$//':
	# 	- Trims leading and trailing spaces from the value.
    value=$(grep -o "\"${key}\":[^,}]*" "${json}" | sed -n "${num}p" | awk -F: '{print $2}' | tr -d '"' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
    echo "${value}"
}

if [ -f $rootmnt/etc/deepin-immutable-ctl/disable-system-protect.json ]; then
	status=$(get_json_value $rootmnt/etc/deepin-immutable-ctl/disable-system-protect.json enable)
	if [ "$status" = "true" ];then
		mount -o remount,rw $rootmnt/usr $rootmnt/usr
	fi
fi