This repository has been archived by the owner on Mar 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash
89 lines (88 loc) · 2.49 KB
/
flash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/system/bin/sh
#Setting path variables
DEVDIR=/dev/block/platform/msm_sdcc.1/by-name #block devices derectory
BAKDIR=/sdcard/Partition_backup #backups directory
VERS=1.1.02
info () {
echo "Partition images flashing utility by Alexander Agura
Version: $VERS
This utility flashes chosen image file to a chosen partition. Partition will be backed up before flashing.
Usage: `basename $0` [PARTITION] [FILE] [-n|--nobak]
-n,--nobak Skip backup creating
Usage#2: `basename $0` [option]
Options:
--lsbak List backups
--rmbak Clean up backup folder
--lsdev List available partitions
--restore|-r Restore backup
--help|-h Show this help and exit"
}
#Checking parameters
case $1 in
--rmbak)
rm -rf $BAKDIR/*
echo "All backups are removed!"
;;
--lsbak)
ls $BAKDIR || { echo "No backups directory."; exit 3;}
;;
--lsdev)
ls $DEVDIR || su root ls $DEVDIR || { echo "Block devices directory not found!"; echo "Is \'$DEVDIR\' your block devices directory?";exit 3;}
# 'su root *' is tested only with SuperSU 'su' binary. Don't know if it works with other root implementations.
;;
--restore|-r)
if [[ "$#" > "3" || "$#" = 1 ]]
then
echo "Usage: `basename $0` --restore|-r [PARTITION] <BAKNAME>"
echo "BAKNAME is not necessary, you will be promted to choose it"
echo "Enter `basename $0` --lsbak to view backups list"; exit 1
else
BAK=$3
if [ $BAK -z ]
then
test -d $BAKDIR || { echo "No backups directory!"; exit 3;}
ls $BAKDIR/$2* &> /dev/null || { echo "No backups of $2"; exit 3;}
echo "Select the backup from the list:"
echo
PS3="Select: "
cd $BAKDIR
select BAK in $(ls $2*)
do break; done
unset PS3
cd $OLDPWD
fi
echo "Restoring $2 from $BAKDIR/$BAK"
dd if=$BAKDIR/$BAK of=$DEVDIR/$2 && echo "$2 is restored"|| exit 2
fi
;;
--help|-h)
info
;;
*)
if [[ -z "$2" || "$#" > "3" || -n "$3" && "$3" != "-n" && "$3" != "--nobak" ]]
then
info
exit 1
else
if [[ "$3" = "-n" || "$3" = "--nobak" ]]
then
echo "Flashing $2 to $1 without backup!
Processing..."
dd if=$2 of=$DEVDIR/$1 || exit 2
echo "Done!"
else
#Backing up partition
echo "Backing up $1 before flashing..."
mkdir -p $BAKDIR
BAK="$1-`busybox date -Iseconds`.img"
dd if=$DEVDIR/$1 of=$BAKDIR/$BAK || exit 2
echo "$1 saved as $BAKDIR/$BAK.img"
unset BAK
echo "Enter 'flash --lsbak' to list all backups or 'flash --rmbak' to clean up backup folder"
#Flashing
echo "Flashing $2 to $1 partition..."
dd if=$2 of=$DEVDIR/$1 || exit 2
echo "Done!"
fi
fi
esac