#!/sbin/sh

set -e

# $SYSTEM set by the caller
# $PRODUCT set by the caller
# $SYSTEM_EXT set by the caller

cd "$(dirname $0)"

export PATH="${PATH}:${SYSTEM}/bin:${SYSTEM}/xbin"

# install setup script
echo "Installing setup script"
cp cm-data/system-setup-runonce.sh /sdcard/system-setup-runonce.sh
chown root:root /sdcard/system-setup-runonce.sh
chmod 750 /sdcard/system-setup-runonce.sh

# install iptables script
echo "Installing iptables script"
cp cm-data/oem-iptables-init.sh ${SYSTEM}/bin/oem-iptables-init.sh
chown root:root ${SYSTEM}/bin/oem-iptables-init.sh
chmod 750 ${SYSTEM}/bin/oem-iptables-init.sh

# install restore script
echo "Installing restore script"
cp cm-data/99-perso.sh.addon ${SYSTEM}/addon.d/99-perso.sh
chown root:root ${SYSTEM}/addon.d/99-perso.sh
chmod 755 ${SYSTEM}/addon.d/99-perso.sh

# call restore script post to remove bloat
export SYSTEM
export PRODUCT
export SYSTEM_EXT
${SYSTEM}/addon.d/99-perso.sh post-restore

echo "Done"
echo "Do not forget to WIPE Cache/Dalvik"

