CloneNum3

Snapshot 3.1

Feb 25th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.55 KB | None | 0 0
  1. #!/system/bin/sh
  2.  
  3. # Change Log
  4. # 3.1
  5. #  Re-Added memory clear from 2.0
  6. #  Added disabling and re-enabling of multi-cpus
  7. # 3.0
  8. #  Leaving /system processes alone
  9. # 2.0 aka dynamic
  10. #  Dynamically determining which services to stop
  11. # 1.0 Initial hard-coded service list
  12.  
  13. echo $0
  14.  
  15. ##### md5sum e24d678d9c18c7811e16f4755dfd1e19  /system/sbin/busybox-armv7l
  16.  
  17. ### Make sure 'free' command is in the path, recommend /system/sbin/busybox-armv7l --install -s /system/sbin
  18. which free >/dev/null 2>&1
  19. if [[ $? -ne 0 ]]
  20. then
  21.   echo "Unable to find 'which' and/or 'free' command, install busybox-armv7l
  22. # mount -o rw,remount /system
  23. # mkdir /system/sbin
  24. # download https://busybox.net/downloads/binaries/latest/busybox-armv7l to /system/sbin
  25. # chmod 777 /system/sbin/busybox-armv7l
  26. # /system/sbin/busybox-armv7l --install -s /system/sbin
  27. # rm -f /system/sbin/ps"
  28.   exit 1
  29. fi
  30.  
  31. ### Determine list of init rc scripts to reference when looking to pair a process name with a service name
  32. init_rc_list=`ls /init*rc  | grep -v goldfish | tr '\n' ' '`
  33. service_restart_list=""
  34. abort=0
  35.  
  36. ### Determine which services and processes need to be stopped for /extdata and /data to happily umount
  37. for blocking_pid in `fuser -m /extdata /data | sort | uniq`
  38. do
  39.   ### Find the name and parent pid of the blocking pid
  40.   comm=`cat /proc/${blocking_pid}/comm`
  41.   ppid=`cat /proc/${blocking_pid}/stat | awk '{print $4}'`
  42.  
  43.   ### If the parent pid is another process, set the blocking pid to the parent, the children will stop when the parent stops
  44.   if [[ $ppid -gt 1 ]]
  45.   then
  46.     #echo -n "PARENT ppid = [${ppid}] "
  47.     blocking_pid=${ppid}
  48.     comm=`cat /proc/${blocking_pid}/comm`
  49.   fi
  50.  
  51.   ### Add service and process names to variables for us to work with later.
  52.   if [[ "${comm}" == "sh" ]]
  53.   then
  54.     echo "There is an open shell using something in /extdata and/or /data... aborting."
  55.     abort=1
  56.   elif [[ "${comm}" == "zygote" ]]
  57.   then
  58.     ### Only add zygote to the list once
  59.     if [[ "$zygote_stopped" == "" ]]
  60.     then
  61.       echo "Adding [zygote] to the list of services to stop"
  62.       service_restart_list=" zygote ${service_restart_list} "
  63.       zygote_stopped=yes
  64.     fi
  65.   elif [[ "${comm}" == "keystore" ]]
  66.   then
  67.     echo "Ignoring keystore, it will be handled by pioneer /sbin/andsnap"
  68.   elif [[ "${comm}" != "" ]]
  69.   then
  70.     echo -n "blocking_pid = [${blocking_pid}] comm = [${comm}] "
  71.     service_name=`grep "^service.*\/${comm}" ${init_rc_list} | awk '{print $2}'`
  72.     if [[ "${service_name}" != "" ]]
  73.     then
  74.       echo "${service_restart_list}" | grep -q " ${service_name} "
  75.       if [[ $? -eq 0 ]]
  76.       then
  77.         echo "Service [${service_name}] has already been dealt with"
  78.       else
  79.         echo "Adding [${service_name}] to the list of services to stop"
  80.         service_restart_list=" ${service_name} ${service_restart_list} "
  81.       fi
  82.     else
  83.       echo "No match for service, killing [${service_name}]"
  84.       killall_list=" ${killall_list} ${comm} "
  85.     fi
  86.   fi
  87. done
  88.  
  89. echo "service_restart_list = [${service_restart_list}]"
  90.  
  91. [ $abort -ne 0 ] && exit 1
  92.  
  93. echo "No changes have been made yet, Ctrl-C to abort within 10 seconds"
  94. for i in `seq 1 10`
  95. do
  96.   echo -n '.'
  97.   sleep 1
  98. done
  99. echo "Continuing on..."
  100.  
  101. echo "Stopping Services"
  102. for service in ${service_restart_list}
  103. do
  104.   echo "Stopping ${service}"
  105.   stop ${service}
  106. done
  107. echo "Done Stopping Services"
  108.  
  109. for rogue_process in ${killall_list}
  110. do
  111.   echo "Killing Rogue Process: [${rogue_process}]"
  112.   killall ${rogue_process}
  113. done
  114.  
  115. multi_cpus=`find /sys/devices/system/cpu/cpu[1-9] -name online 2>/dev/null`
  116. if [[ "${multi_cpus}" == "" ]]
  117. then
  118.   echo "Single CPU, continuing..."
  119. else
  120.   for cpu_online in ${multi_cpus}
  121.   do
  122.     echo "Disabling [${cpu_online}]"
  123.     echo 0 > ${cpu_online}
  124.   done
  125. fi
  126.  
  127. echo "Sleeping for 10 seconds to let system end processes"
  128. sleep 10
  129.  
  130. echo "Zero out the memory for a small clean snapshot"
  131. head -n2 /proc/meminfo
  132. sync && echo 3 > /proc/sys/vm/drop_caches && echo ""
  133. memfree=$(free -m | awk '/^Mem/ {print $4-32}')
  134. echo "memfree=[${memfree}]"
  135. if [ $memfree -gt 0 ]; then
  136.         dd if=/dev/zero of=/dev/null bs=${memfree}M count=1
  137. fi
  138. head -n2 /proc/meminfo
  139.  
  140. sync
  141. sleep 10
  142. sync
  143. /sbin/andsnap $*
  144.  
  145. if [[ "${multi_cpus}" == "" ]]
  146. then
  147.   echo "Single CPU, continuing..."
  148. else
  149.   for cpu_online in ${multi_cpus}
  150.   do
  151.     echo "Re-enabling [${cpu_online}]"
  152.     echo 1 > ${cpu_online}
  153.   done
  154. fi
  155.  
  156. echo "Re-Starting Services"
  157. for service in ${service_restart_list}
  158. do
  159.   echo "Starting ${service}"
  160.   start ${service}
  161. done
  162.  
  163. echo "Done!"
Advertisement
Add Comment
Please, Sign In to add comment