#!/system/bin/sh
#
#
#=============================
#=============================
# NOS ENTROPY BY EXIT_ONLY ===
#=============================
#=============================
#
#
# This script is based on Seeder Entropy. Huge thanks | Ryuinferno @ XDA 2013 | for making seeder possible.
#
# WARNING: DO NOT USE CROSSBREEDER OR SEEDER IN CONJUNCTION WITH NOS ENTROPY. BOOTLOOP, SOFT BRICK, OR HARD BRICK MAY HAPPEN. USE THIS SCRIPT AT YOUR OWN RISK!

clear
   echo ""
   echo ""
   echo ""
   echo ""
   echo ""
   echo "======================================"
   echo "= NOS Entropy Generator by Exit_Only ="
   echo "======================================"
   echo ""
   echo "Mounting /system as r/w"
mount -o rw,remount /system
   echo ""
   echo "Checking to see if you are rooted..."
id=`id`; id=`echo ${id#*=}`; id=`echo ${id%%\(*}`; id=`echo ${id%% *}`
if [ "$id" != "0" ] && [ "$id" != "root" ]; then
sleep 1
   echo ""
   echo "Why are you NOT running as root???"
   echo ""
   echo "Maybe you are not even rooted??? Do you even know what root is???
sleep 1
   echo ""
   echo "Please type 'su' first before typing 'nos_entropy'..."
   echo ""
   echo "Or if you are not rooted Google "How to root 'YOUR DEVICE NAME' and press enter!!!"
exit 0
else
   echo ""
   echo "You are rooted...way to go!!!"
sleep 1
fi
pgrep rngd > /dev/null
test=$?
if [ $test -ne 1 ]; then
nos_switcher="On"
else
nos_switcher="Off"
fi
if [ -e /system/etc/nos_scripts/prof_mod ]; then
nos_prof="Moderate"
elif [ -e /system/etc/nos_scripts/prof_light ]; then
nos_prof="Light"
else
nos_prof="Aggressive"
fi
if [ -e /system/etc/init.d/S10_nos_injection_entropy ]; then
nos_bootup="Yes"
else
nos_bootup="No"
fi
sleep 1
   echo ""
   echo "NOS Entropy generator: $nos_switcher"
   echo ""
   echo "NOS Entropy generator profile: $nos_prof"
   echo ""
   echo "Run at boot?: $nos_bootup"
   echo ""
   echo "======================================"
   echo "=         NOS Entropy Menu:          ="
   echo "======================================"
   echo "1.] NOS entropy generator on/off"
   echo "2.] Run at boot on/off (Needs init.d)"
   echo "3.] Monitor available Entropy levels"
   echo "4.] Exit out"
   echo ""
   echo -n "Please select an option [1-4]: "
read option 
if [ $option -eq 1 ]; then
if [ $test -ne 1 ]; then
   echo ""
   echo "Switching NOS Entropy generator off..."
sleep 1
pkill rngd
rm /data/rngd.pid
   echo ""
   echo "All Done!"
   echo ""
   echo "Press enter to continue..."
read enterKey
nos_entropy
else
   echo ""
   echo "Switching NOS Entropy generator on..."
if pgrep qrngd > /dev/null; then
sleep 1
   echo ""
   echo "qrngd already running! NOS Entropy will not start..."
   echo ""
   echo "Press enter to continue..."
read enterKey
nos_entropy
else
if [ -e /system/bin/qrngd -o -e /system/xbin/qrngd ]; then
sleep 1
   echo ""
   echo "qrngd found in /system! NOS Entropy will not be started!"
   echo ""
   echo "Press enter to continue..."
read enterKey
nos_entropy
else
sleep 1
   echo "==========================="
   echo "= Please select a profile ="
   echo "==========================="
   echo "1.] Do you want light?"
   echo "2.] Do you want moderate?"
   echo "3.] Do you want aggressive?"
option_prof=0
while [ $option_prof -lt 1 ] || [ $option_prof -gt 3 ]
do
   echo ""
   echo -n "Please select: "
read option_prof
if [ $option_prof -eq 1 ]; then
   echo ""
   echo "Light profile has been selected..."
rm /system/etc/nos_scripts/prof_*
if [ -e /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log ]; then
rm /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log
fi
cp /system/etc/nos_scripts/nos_entropy_light /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
echo "light" > /system/etc/nos_scripts/prof_light
rngd -s 512 -t 1 -W 50 
echo -17 > /proc/$(pgrep rngd)/oom_adj
renice 9 `pidof rngd`
    echo ""
    echo "All Done!"
sleep 1
    echo ""
    echo "Your phone will reboot shortly!!!"
sleep 1
reboot
busybox reboot
read enterKey
nos_entropy
elif [ $option_prof -eq 2 ]; then
    echo ""
    echo "Moderate profile has been selected..."
rm /system/etc/nos_scripts/prof_*
if [ -e /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log ]; then
rm /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log
fi
cp /system/etc/nos_scripts/nos_entropy_mod /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
echo "moderate" > /system/etc/nos_scripts/prof_mod
rngd -s 768 -t 0.5 -W 75
echo -17 > /proc/$(pgrep rngd)/oom_adj
renice 9 `pidof rngd`
    echo ""
    echo "All Done!"
sleep 1
    echo ""
    echo "Your phone will reboot shortly!!!"
sleep 1
reboot
busybox reboot
read enterKey
nos_entropy
elif [ $option_prof -eq 3 ]; then
    echo ""
    echo "Aggressive profile has been selected..."
sleep 1
rm /system/etc/nos_scripts/prof_*
if [ -e /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log ]; then
rm /data/nos_injection/4cylturbo/engine/S10_nos_injection_entropy.log
fi
cp /system/etc/nos_scripts/nos_entropy_agg /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
echo "aggressive" > /system/etc/nos_scripts/prof_agg
rngd -s 1024 -t 0.25 -W 90
echo -17 > /proc/$(pgrep rngd)/oom_adj
renice 9 `pidof rngd`
    echo ""
    echo "All Done!"
sleep 1
    echo ""
    echo "Your phone will reboot shortly!!!"
sleep 1
reboot 
busybox reboot
read enterKey
nos_entropy 
else
    echo ""
    echo "Invalid option, please try again..."
sleep 1
fi
done
fi
fi
fi
elif [ $option -eq 2 ]; then
if [ -e /system/etc/init.d/S10_nos_injection_entropy ]; then
   echo ""
   echo "Disabling init.d script..."
sleep 1
rm /system/etc/init.d/S10_nos_injection_entropy
   echo ""
   echo "All Done!"
sleep 1
   echo ""
   echo "Press enter to continue..."
sleep 1
read enterKey
nos_entropy
else
   echo ""
   echo "Enabling init.d script..."
sleep 1
if [ -e /system/etc/nos_scripts/prof_light ]; then
cp /system/etc/nos_scripts/nos_entropy_light /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
elif [ -e /system/etc/nos_scripts/prof_mod ]; then
cp /system/etc/nos_scripts/nos_entropy_mod /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
else
cp /system/etc/nos_scripts/nos_entropy_agg /system/etc/init.d/S10_nos_injection_entropy
chmod 777 /system/etc/init.d/S10_nos_injection_entropy
chown 0.0 /system/etc/init.d/S10_nos_injection_entropy
fi
   echo ""
   echo "All Done!"
sleep 1
   echo ""
   echo "Press enter to continue..."
sleep 1
read enterKey
nos_entropy
fi
elif [ $option -eq 3 ]; then
   echo ""
   echo "To stop monitoring, press Volume Down key and c (from keyboard) together..."
sleep 2
clear
entro
elif [ $option -eq 4 ]; then
mount -o ro,remount /system
sleep 1
   echo ""
   echo "======================================"
   echo "=  NOS Entropy Generator Script done ="
   echo "======================================"
sleep 2
   echo ""
   echo "======================================"
   echo "=       Exit_Only @ XDA 2013         ="
   echo "======================================"
sleep 2
exit 0
else
   echo ""
   echo "Invalid option, please try again..."
sleep 1
nos_entropy
fi