Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. #!/system/bin/sh
  2. # MAD Team App2SD (Cyanogen 7)
  3. # by subpsyke
  4.  
  5. swapfile="/system/etc/init.d/06swap"
  6. LOG="/dev/null"
  7.  
  8. checkapp2sd() {
  9. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  10.  
  11. if [ -f /system/sd/.app2sd_enabled ]; then
  12. result="app2sd"
  13. else
  14. result="normal"
  15. fi
  16. }
  17.  
  18. checkspace() {
  19. sdused=`du -c /system/sd/ | tail -n1 | awk ' { print $1 } '`
  20. sdfree=`df /system/sd/ | tail -n1 | awk ' { print $4 } '`
  21. phoneused=`du -c /data | tail -n1 | awk ' { print $1 } '`
  22. phonefree=`df /data | tail -n1 | awk ' { print $4 } '`
  23. }
  24.  
  25. convert_app2sd() {
  26. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  27. sleep 5
  28. rm -r /data
  29. sync
  30. sleep 5
  31. cp -a /system/sd/data /
  32. sync
  33. sleep 5
  34. umount /dev/block/mmcblk0p2
  35. mke2fs -t ext4 -O ^huge_file /dev/block/stl14
  36. sleep 5
  37. mke2fs -t ext4 -O ^huge_file /dev/block/mmcblk0p2
  38. sleep 5
  39. }
  40.  
  41. convert_normal() {
  42. umount /dev/block/mmcblk0p2
  43. mke2fs -O journal_dev /dev/block/stl14
  44. sleep 5
  45. mke2fs -t ext4 -O ^huge_file -J device=/dev/block/stl14 /dev/block/mmcblk0p2
  46. sleep 5
  47. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  48. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  49. sleep 5
  50. cp -a /data /system/sd/
  51. sync
  52. sleep 5
  53. rm -r /data
  54. sync
  55. sleep 5
  56. touch /system/sd/.app2sd_enabled
  57. }
  58.  
  59. mount_normal() {
  60. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  61. mount -t ext4 -o nodev,nosuid /dev/block/stl14 /cache
  62. }
  63.  
  64. mount_app2sd() {
  65. umount -a
  66. mount -t ext4 -o nodev,nosuid /dev/block/stl14 /cache
  67. if mount | grep /dev/block/stl14 | grep cache; then
  68. umount /dev/block/stl14
  69. mke2fs -O journal_dev /dev/block/stl14
  70. tune2fs -J device=/dev/block/stl14 /dev/block/mmcblk0p2
  71. fi
  72. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  73. mkdir /system/sd/data
  74. mount -o bind /system/sd/data /data
  75. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /cache
  76. }
  77.  
  78. doboot() {
  79. # Run checks
  80. checkapp2sd
  81.  
  82. # Toggle App2SD
  83. if [ -f /system/sd/.toggleapp2sd ]; then
  84. rm /system/sd/.toggleapp2sd
  85. stop
  86. convert_$result
  87. if [ "$result" = "normal" ]; then
  88. result="app2sd"
  89. else
  90. result="normal"
  91. fi
  92. sleep 5
  93. stop
  94. sync
  95. umount -a
  96. sync
  97. stop
  98. sleep 5
  99. reboot
  100. fi
  101.  
  102. mount_$result
  103. }
  104.  
  105. if [ "$1" = "" ]; then
  106. checkapp2sd
  107. checkspace
  108. echo ""
  109. echo "Usage: madteam_app2sd [option]"
  110. echo "Options:"
  111. echo ""
  112. echo " * toggle - disable/enable App2SD"
  113. echo " * swapon - enable swap"
  114. echo " * swapoff - disable swap"
  115. echo ""
  116. echo "MAD Team App2SD status:"
  117. echo ""
  118. if [ "$result" = "app2sd" ]; then
  119. echo "App2SD: activated"
  120. echo "SD card used: $sdused""KB"
  121. echo "SD card free: $sdfree""KB"
  122. else
  123. echo "App2SD: deactivated"
  124. echo "Phone used: $phoneused""KB"
  125. echo "Phone free: $phonefree""KB"
  126. fi
  127. echo "Swap size: " `free | grep Swap | awk ' { print ($2) } '`"KB"
  128. echo ""
  129. fi
  130.  
  131.  
  132. mkdir /system/sd 1>>$LOG 2>>$LOG
  133.  
  134. if [ "$1" = "doboot" ]; then
  135. doboot
  136. fi
  137.  
  138. if [ "$1" = "swapon" ]; then
  139. echo "#!/system/bin/sh" >$swapfile
  140. echo "swapon /dev/block/mmcblk0p3" >$swapfile
  141. chmod +x $swapfile
  142. $swapfile
  143. echo "Swap enabled! Setting will be kept on reboot."
  144. fi
  145.  
  146. if [ "$1" = "swapoff" ]; then
  147. echo "#!/system/bin/sh" >$swapfile
  148. echo "swapon /dev/block/mmcblk0p3" >$swapfile
  149. chmod -x $swapfile
  150. swapoff /dev/block/mmcblk0p3
  151. echo "Swap disabled! Setting will be kept on reboot."
  152. fi
  153.  
  154. if [ "$1" = "toggle" ]; then
  155. checkapp2sd
  156. checkspace
  157. if [ "$result" = "app2sd" ]; then
  158. echo "Current App2SD status: activated"
  159. echo ""
  160. echo "SD card used: $sdused""KB"
  161. echo "Phone free: $phonefree""KB"
  162. echo ""
  163. if [ $(($sdused)) -gt $(($phonefree)) ]; then
  164. echo "Not enough space in phone memory to complete operation!"
  165. echo "Please free " $(($sdused-$phonefree)) "KB from SD card's App2SD partition to continue."
  166. echo "Aborting!"
  167. else
  168. echo "Please reboot your phone to deactivate App2SD."
  169. echo "Note: your phone will reboot twice. This is normal."
  170. touch /system/sd/.toggleapp2sd
  171. fi
  172. fi
  173. if [ "$result" = "normal" ]; then
  174. echo "Current App2SD status: deactivated"
  175. echo ""
  176. echo "Phone used: $phoneused""KB"
  177. echo "SD card free: $sdfree""KB"
  178. echo ""
  179. if [ $(($phoneused)) -gt $(($sdfree)) ]; then
  180. echo "Not enough space on SD card partition to complete operation!"
  181. echo "Please free " $(($phoneused-$sdfree)) "KB from Phone to continue."
  182. echo "Aborting!"
  183. else
  184. echo "Please reboot your phone to activate App2SD."
  185. echo "Note: your phone will reboot twice. This is normal."
  186. touch /system/sd/.toggleapp2sd
  187. fi
  188. fi
  189. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement