SHOW:
|
|
- or go back to the newest paste.
1 | #!/bin/sh | |
2 | ||
3 | - | #Made by sixwheeledbeast, Estel, Malkavian, peterleinchen and vi_ |
3 | + | ############################ |
4 | ##Depends on rootsh don't want this | |
5 | - | ## Go root if not (Depends rootsh) |
5 | + | ## Go root if not |
6 | #if [ `id -u` != 0 ] ; then | |
7 | # exec | sudo gainroot <<EOF | |
8 | #exec sh $0 $* | |
9 | #EOF | |
10 | # exit $? | |
11 | #fi | |
12 | ######################### | |
13 | ||
14 | # Setup swap names for script | |
15 | ||
16 | ## Swap 0 - Backup internal swap location | |
17 | swap0=/dev/mmcblk0p3 | |
18 | echo $swap0 | |
19 | ||
20 | ## Swap 1 - First Main Swap Location | |
21 | swap1=/dev/mmcblk1p2 | |
22 | echo $swap1 | |
23 | ||
24 | ## Swap 2 - Second Main Swap Location | |
25 | swap2=/dev/mmcblk1p3 | |
26 | echo $swap2 | |
27 | ||
28 | ##Swap | |
29 | xswapon="/bin/busybox swapon" | |
30 | xswapoff="/bin/busybox swapoff" | |
31 | ||
32 | # Setup notification banner | |
33 | banner(){ | |
34 | o=org | |
35 | f=freedesktop | |
36 | n=Notifications | |
37 | run-standalone.sh dbus-send --type=method_call \ | |
38 | --dest=$o.$f.$n /$o/$f/$n $o.$f.$n.SystemNoteInfoprint string:"$1" | |
39 | } | |
40 | ||
41 | # Get and Print Current Swap Pre | |
42 | swap=`cat /proc/swaps | awk '/dev/ {print $1}'` | |
43 | echo $swap | |
44 | banner "$swap" | |
45 | ||
46 | sleep 4 | |
47 | ||
48 | #Logic | |
49 | if [ "$swap" = "$swap1" ] ; | |
50 | then | |
51 | $xswapon $swap2 | |
52 | $xswapoff $swap1 | |
53 | elif [ "$swap" = "$swap2" ] ; | |
54 | then | |
55 | $xswapon $swap1 | |
56 | $xswapoff $swap2 | |
57 | elif [ "$swap" = "$swap0" ] ; | |
58 | then | |
59 | $xswapon $swap1 | |
60 | $xswapoff $swap0 | |
61 | sleep 5 | |
62 | # Get and Print Current Swap Post | |
63 | swappost=`cat /proc/swaps | awk '/dev/ {print $1}'` | |
64 | banner "$swappost" | |
65 | else | |
66 | banner "Swap Switch Failed" && exit 1 | |
67 | fi | |
68 | #End of Logic | |
69 | ||
70 | sleep 2 | |
71 | #Get current swap from /proc/swaps | |
72 | disk=$(cat /proc/swaps | awk '/dev/ {print $1}' | cut -d "/" -f 3) | |
73 | #Get blocks used since boot from /proc/diskstats | |
74 | ublocks=$(awk '{if ($3=="'"$disk"'") print $10}' /proc/diskstats) | |
75 | echo $ublocks ublocks | |
76 | #Multiply blocks by 512 to get used bytes | |
77 | ubytes=$(($ublocks*512)) | |
78 | #Calculate used bytes into Kb, Mb and Gb | |
79 | echo $ubytes ubytes | |
80 | ukbytes=$(($ubytes/1024)) | |
81 | umbytes=$(($ubytes/1024/1024)) | |
82 | ugbytes=$(($ubytes/1024/1024/1024)) | |
83 | echo $ukbytes ukbytes, $umbytes umbytes, $ugbytes ugbytes | |
84 | echo "$umbytes" > /tmp/flopswaplast && exit 1 |