#!/system/bin/sh
	
HNV=/data/adb/modules/HideNavBar
chmod +x "$HNV"/tools/*
RES="$HNV"/Mods/Qtmp/res/values/dimens.xml
FOL="$HNV"/service.sh
cp -rf "$HNV"/tools/service.sh "$HNV"
cp -rf "$HNV"/Mods/QS/* "$HNV"/Mods/Qtmp/
rm -rf "$HNV"/Mods/Q/*
mkdir -p "$HNV"/Mods/Q/NavigationBarModeGestural/
mkdir -p "$HNV"/opt/

# Grep prop
grep_prop() {
  local REGEX="s/^$1=//p"
  shift
  local FILES=$@
  [ -z "$FILES" ] && FILES='/system/build.prop'
  sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
}


API=$(grep_prop ro.build.version.sdk)
echo $API

echo "Fullscreen/Immersive module setup"

echo "Enter Gesture Sensitivity"
if [ "$API" -ge 31 ] ; then
 echo "(Min 3000, Default 9000, Module default 4000)"
else
 echo "(Min 10.0, default 32.0, Module default 18.0)"
fi
read -r GS
if [ "$GS" = "" ]; then
    # $var is empty
echo " "
else
 if [ "$API" -ge 31 ] ; then
 sed -i s/9000/"$GS"/g "$FOL"
 else
 sed -i s/0.2/"$GS"/g "$RES"
 fi
fi

echo "What Navbar height?"
if [ "$API" -ge 31 ] ; then
 echo "(0 Module default, 4000 Android default)"
else
 echo "(0.0 Module default, 18.0 Android default)"
fi
read -r BH
if [ "$BH" = "" ]; then
    # $var is empty
echo " "
else
 if [ "$API" -ge 31 ] ; then
 sed -i s/03/"$BH"/g "$FOL"
 else
 sed -i s/0.3/"$BH"/g "$RES"
 fi
fi

echo "What Keyboard bar height?"
 if [ "$API" -ge 31 ] ; then
 echo "(0 Fullscreen, 9500 immersive)"
 echo "(4000 Immersive+Small keyboard bar)"
 else
 echo "(0.0 Fullscreen, 48.0 immersive)"
 echo "(18.0 Immersive+Small keyboard bar)"
 fi
read -r FH
if [ "$FH" = "" ]; then
    # $var is empty
echo " "
else
 if [ "$API" -ge 31 ] ; then
 sed -i s/01/"$FH"/g "$FOL"
 else
 sed -i s/0.1/"$FH"/g "$RES"
 fi
fi

if [ "$FH" = 0.0 ] ; then
 : 
else
echo "Hide pill? (yes or no, in lowercase)"
read -r HB
 if [ "$HB" = yes ] ; then
  if [ "$API" -ge 31 ] ; then
  :
  else
  cp -rf "$HNV"/Mods/HP/. "$HNV"/opt
  fi
 else
  if [ "$API" -ge 31 ] ; then
  cat "$HNV"/service.sh | head -16 > "$HNV"/services.sh && mv "$HNV"/services.sh "$HNV"/service.sh
  else
  rm -rf "$HNV"/opt/pillhide.apk
  fi
 fi
fi


if [ "$API" -ge 31 ] ; then
 :
else
 if [ "$FH" = 0.0 ] ; then
  :
 else
 echo "Hide keyboard buttons? (yes or no, in lowercase)"
 read -r HKB
  if [ "$HKB" = yes ] ; then
  cp -rf "$HNV"/Mods/HKB/. "$HNV"/opt/
  else
  rm -rf "$HNV"/opt/HKN.apk
  fi
 fi
fi

echo "Disable the back gesture? (yes or no, in lowercase)"
read -r DB
 if [ "$DB" = yes ] ; then
 :
 else
 settings delete secure back_gesture_inset_scale_left
 settings delete secure back_gesture_inset_scale_right
 fi

if [ "$DB" = yes ] ; then
echo "Left only (type l) Both sides (type b)"
read -r SD
  if [ "$SD" = l ] ; then
  settings put secure back_gesture_inset_scale_left -1
  else
  settings put secure back_gesture_inset_scale_left -1
  settings put secure back_gesture_inset_scale_right -1
  fi
else
 :
fi

if [ "$API" -le 30 ] ; then
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-sw900dp/
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-sw600dp/
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-440dpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-xhdpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-xxhdpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/dimens.xml "$HNV"/Mods/Qtmp/res/values-xxxhdpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/* "$HNV"/Mods/MIUI/res/values-xxhdpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/* "$HNV"/Mods/MIUI/res/values-440dpi/
cp -rf "$HNV"/Mods/Qtmp/res/values/* "$HNV"/Mods/MIUI/res/values/


mkdir "$HNV"/ti
cp -rf "$HNV"/tools "$HNV"/Mods "$HNV"/module.prop "$HNV"/tools/customize.sh "$HNV"/tools/META-INF/ "$HNV"/service.sh "$HNV"/ti
cd "$HNV"/ti
rm -rf "$HNV"/ti/test.zip
"$HNV"/tools/zip -r test.zip .

magisk --install-module "$HNV"/ti/test.zip

else
 :
fi

echo "reboot for changes to apply"


