Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. #!/system/bin/sh
  2.  
  3. # MAD Team App2SD (Cyanogen 7)
  4.  
  5. # by subpsyke
  6.  
  7.  
  8.  
  9. swapfile="/system/etc/init.d/06swap"
  10.  
  11. LOG="/dev/null"
  12.  
  13.  
  14.  
  15. checkapp2sd() {
  16.  
  17. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  18.  
  19.  
  20.  
  21. if [ -f /system/sd/.app2sd_enabled ]; then
  22.  
  23. result="app2sd"
  24.  
  25. else
  26.  
  27. result="normal"
  28.  
  29. fi
  30.  
  31. }
  32.  
  33.  
  34.  
  35. checkspace() {
  36.  
  37. sdused=`du -c /system/sd/ | tail -n1 | awk ' { print $1 } '`
  38.  
  39. sdfree=`df /system/sd/ | tail -n1 | awk ' { print $4 } '`
  40.  
  41. phoneused=`du -c /data | tail -n1 | awk ' { print $1 } '`
  42.  
  43. phonefree=`df /data | tail -n1 | awk ' { print $4 } '`
  44.  
  45. }
  46.  
  47.  
  48.  
  49. convert_app2sd() {
  50.  
  51. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  52.  
  53. sleep 5
  54.  
  55. rm -r /data
  56.  
  57. sync
  58.  
  59. sleep 5
  60.  
  61. cp -a /system/sd/data /
  62.  
  63. sync
  64.  
  65. sleep 5
  66.  
  67. umount /dev/block/mmcblk0p2
  68.  
  69. mke2fs -t ext4 -O ^huge_file /dev/block/stl14
  70.  
  71. sleep 5
  72.  
  73. mke2fs -t ext4 -O ^huge_file /dev/block/mmcblk0p2
  74.  
  75. sleep 5
  76.  
  77. }
  78.  
  79.  
  80.  
  81. convert_normal() {
  82.  
  83. umount /dev/block/mmcblk0p2
  84.  
  85. mke2fs -O journal_dev /dev/block/stl14
  86.  
  87. sleep 5
  88.  
  89. mke2fs -t ext4 -O ^huge_file -J device=/dev/block/stl14 /dev/block/mmcblk0p2
  90.  
  91. sleep 5
  92.  
  93. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  94.  
  95. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  96.  
  97. sleep 5
  98.  
  99. cp -a /data /system/sd/
  100.  
  101. sync
  102.  
  103. sleep 5
  104.  
  105. rm -r /data
  106.  
  107. sync
  108.  
  109. sleep 5
  110.  
  111. touch /system/sd/.app2sd_enabled
  112.  
  113. }
  114.  
  115.  
  116.  
  117. mount_normal() {
  118.  
  119. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /data
  120.  
  121. mount -t ext4 -o nodev,nosuid /dev/block/stl14 /cache
  122.  
  123. }
  124.  
  125.  
  126.  
  127. mount_app2sd() {
  128.  
  129. umount -a
  130.  
  131. mount -t ext4 -o nodev,nosuid /dev/block/stl14 /cache
  132.  
  133. if mount | grep /dev/block/stl14 | grep cache; then
  134.  
  135. umount /dev/block/stl14
  136.  
  137. mke2fs -O journal_dev /dev/block/stl14
  138.  
  139. tune2fs -J device=/dev/block/stl14 /dev/block/mmcblk0p2
  140.  
  141. fi
  142.  
  143. mount -t ext4 -o nodev,nosuid /dev/block/mmcblk0p2 /system/sd
  144.  
  145. mkdir /system/sd/data
  146.  
  147. mount -o bind /system/sd/data /data
  148.  
  149. mount -t ext4 -o nodev,nosuid /dev/block/stl13 /cache
  150.  
  151. }
  152.  
  153.  
  154.  
  155. doboot() {
  156.  
  157. # Run checks
  158.  
  159. checkapp2sd
  160.  
  161.  
  162.  
  163. # Toggle App2SD
  164.  
  165. if [ -f /system/sd/.toggleapp2sd ]; then
  166.  
  167. rm /system/sd/.toggleapp2sd
  168.  
  169. stop
  170.  
  171. convert_$result
  172.  
  173. if [ "$result" = "normal" ]; then
  174.  
  175. result="app2sd"
  176.  
  177. else
  178.  
  179. result="normal"
  180.  
  181. fi
  182.  
  183. sleep 5
  184.  
  185. stop
  186.  
  187. sync
  188.  
  189. umount -a
  190.  
  191. sync
  192.  
  193. stop
  194.  
  195. sleep 5
  196.  
  197. reboot
  198.  
  199. fi
  200.  
  201.  
  202.  
  203. mount_$result
  204.  
  205. }
  206.  
  207.  
  208.  
  209. if [ "$1" = "" ]; then
  210.  
  211. checkapp2sd
  212.  
  213. checkspace
  214.  
  215. echo ""
  216.  
  217. echo "Usage: madteam_app2sd [option]"
  218.  
  219. echo "Options:"
  220.  
  221. echo ""
  222.  
  223. echo " * toggle - disable/enable App2SD"
  224.  
  225. echo " * swapon - enable swap"
  226.  
  227. echo " * swapoff - disable swap"
  228.  
  229. echo ""
  230.  
  231. echo "MAD Team App2SD status:"
  232.  
  233. echo ""
  234.  
  235. if [ "$result" = "app2sd" ]; then
  236.  
  237. echo "App2SD: activated"
  238.  
  239. echo "SD card used: $sdused""KB"
  240.  
  241. echo "SD card free: $sdfree""KB"
  242.  
  243. else
  244.  
  245. echo "App2SD: deactivated"
  246.  
  247. echo "Phone used: $phoneused""KB"
  248.  
  249. echo "Phone free: $phonefree""KB"
  250.  
  251. fi
  252.  
  253. echo "Swap size: " `free | grep Swap | awk ' { print ($2) } '`"KB"
  254.  
  255. echo ""
  256.  
  257. fi
  258.  
  259.  
  260.  
  261.  
  262.  
  263. mkdir /system/sd 1>>$LOG 2>>$LOG
  264.  
  265.  
  266.  
  267. if [ "$1" = "doboot" ]; then
  268.  
  269. doboot
  270.  
  271. fi
  272.  
  273.  
  274.  
  275. if [ "$1" = "swapon" ]; then
  276.  
  277. echo "#!/system/bin/sh" >$swapfile
  278.  
  279. echo "swapon /dev/block/mmcblk0p3" >$swapfile
  280.  
  281. chmod +x $swapfile
  282.  
  283. $swapfile
  284.  
  285. echo "Swap enabled! Setting will be kept on reboot."
  286.  
  287. fi
  288.  
  289.  
  290.  
  291. if [ "$1" = "swapoff" ]; then
  292.  
  293. echo "#!/system/bin/sh" >$swapfile
  294.  
  295. echo "swapon /dev/block/mmcblk0p3" >$swapfile
  296.  
  297. chmod -x $swapfile
  298.  
  299. swapoff /dev/block/mmcblk0p3
  300.  
  301. echo "Swap disabled! Setting will be kept on reboot."
  302.  
  303. fi
  304.  
  305.  
  306.  
  307. if [ "$1" = "toggle" ]; then
  308.  
  309. checkapp2sd
  310.  
  311. checkspace
  312.  
  313. if [ "$result" = "app2sd" ]; then
  314.  
  315. echo "Current App2SD status: activated"
  316.  
  317. echo ""
  318.  
  319. echo "SD card used: $sdused""KB"
  320.  
  321. echo "Phone free: $phonefree""KB"
  322.  
  323. echo ""
  324.  
  325. if [ $(($sdused)) -gt $(($phonefree)) ]; then
  326.  
  327. echo "Not enough space in phone memory to complete operation!"
  328.  
  329. echo "Please free " $(($sdused-$phonefree)) "KB from SD card's App2SD partition to continue."
  330.  
  331. echo "Aborting!"
  332.  
  333. else
  334.  
  335. echo "Please reboot your phone to deactivate App2SD."
  336.  
  337. echo "Note: your phone will reboot twice. This is normal."
  338.  
  339. touch /system/sd/.toggleapp2sd
  340.  
  341. fi
  342.  
  343. fi
  344.  
  345. if [ "$result" = "normal" ]; then
  346.  
  347. echo "Current App2SD status: deactivated"
  348.  
  349. echo ""
  350.  
  351. echo "Phone used: $phoneused""KB"
  352.  
  353. echo "SD card free: $sdfree""KB"
  354.  
  355. echo ""
  356.  
  357. if [ $(($phoneused)) -gt $(($sdfree)) ]; then
  358.  
  359. echo "Not enough space on SD card partition to complete operation!"
  360.  
  361. echo "Please free " $(($phoneused-$sdfree)) "KB from Phone to continue."
  362.  
  363. echo "Aborting!"
  364.  
  365. else
  366.  
  367. echo "Please reboot your phone to activate App2SD."
  368.  
  369. echo "Note: your phone will reboot twice. This is normal."
  370.  
  371. touch /system/sd/.toggleapp2sd
  372.  
  373. fi
  374.  
  375. fi
  376.  
  377. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement