blob: 859334add3b7983eccd6354773179bd5642aed24 (
plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
#!/bin/bash
#***********************************************#
# Gui tool to create backups of FOSSEE laptop #
# to external storage media. #
# #
#***********************************************#
# functions()
# ###########
# ------------------------------------------------------------#
# selection_menu () #
# shows the menu with two options. #
# Parameter: $1(title) $2(option1) $3(option2) #
# change the value of $result to 1 or 2 according to option #
# selected. #
# ------------------------------------------------------------#
selection_menu() {
choice="$(zenity --width=600 --height=200 --list --radiolist --title="$1" --text "<b>Choose :</b> " --hide-header --column "selection" --column "options" FALSE "$2" FALSE "$3")"
case "${choice}" in
$2 )
result="1" # if option1 is selected.
;;
$3 )
result="2" # if option2 is selected.
;;
esac
}
# ------------------------------------------------------------#
# sudoAccess () #
# get the sudo password from user via zenity window and #
# stores in a global variable ($password). #
# #
# ------------------------------------------------------------#
sudoAccess() {
# Remove any previous sudo passwords
sudo -K
# In case of wrong password, else condition will fail(return 1)
# and executes from beginning
while true
do
# Get password from user
password=$(zenity --title "Enter your password to continue" --password)
# zenity dialog button 'Cancel' returns 1, and 'Yes' returns 0.
# Check for zenity 'Cancel' option
if [ $? -eq 1 ]
then
exit 0
else
# sending user entered password to 'echo' command to verify
# password, if wrong it will repeat from beginning
echo $password | sudo -S echo "test">/dev/null
if [ $? -eq 0 ]
then
break
fi
fi
done
}
# ------------------------------------------------------------#
# Prompt a dialog box asking user to remove all the external #
# media and after that stores the size of disk without media #
# on $sizeofDiskBeforeSDCARD #
# ------------------------------------------------------------#
removeSDCARD() {
# The dialog box below will ask user to remove drive(sdcard)
zenity --question --title "Remove media" \
--text "Please remove your drive(sdcard) if connected,
then press YES to continue"
# Checking the return value of zenity dialog, same as previous function
if [ $? -eq 1 ]
then
exit 0
else
# This will return size of disk without our media
umount /media/$USER/* # to unmount all external media.
sizeofDiskBeforeSDCARD=$(echo $password | sudo -S sfdisk -s\
| tail -1 | awk '{print $2}')
fi
}
# ------------------------------------------------------------#
# Prompt a dialog box asking user to connect the required #
# media & stores the size of disk after inserting the media #
# on $sizeofDiskAfterSDCARD. #
# ------------------------------------------------------------#
insertSDCARD() {
# The dialog box below will ask user to insert sdcard
zenity --question --title "Insert media" --text "Now please insert your drive(sdcard) back,\
then press YES to continue"
# Checking the button selected in zenity dialog
if [ $? -eq 1 ]
then
exit 0
else
# sfdisk prints the total disk space in KB
sizeofDiskAfterSDCARD=$(echo $password | sudo -S sfdisk -s\
| tail -1 | awk '{print $2}')
fi
}
# ------------------------------------------------------------#
# Prompt a dialog box showing the size of detected media in #
# GB. After calculating difference of sizeofDiskBeforeSDCARD #
# and sizeofDiskAfterSDCARD #
# ------------------------------------------------------------#
SizeofSDCARD() {
# verifying new device by finding difference in size
# before and after insertion
sizeSDCARDKbytes=$(($sizeofDiskAfterSDCARD - $sizeofDiskBeforeSDCARD))
# Converting into GB first
sizeSDCARD=$(echo "scale=2;$sizeSDCARDKbytes/1048576" | bc)
# Converting sizeSDCARD to integer, so as to use in conditional statement,
# if any card is detected it will go inside 'else' statement
if [ $(echo $sizeSDCARD |cut -f 1 -d '.') -eq 0 ]
then
zenity --info --title "Info" --text "No media found, please check and restart application"
exit 0
else
zenity --question --title "Info" --text "A device of $sizeSDCARD GB is detected, the size will be less \
than actual size of your device. Would you like to continue? \
Press 'YES' to continue or 'NO' to quit !"
# If 'NO' is selected in zenity dialog then exit
if [ $? -eq 1 ]
then
exit 0
fi
fi
}
###################################################################################
# Execution starts here.
zenity --width=600 --height=200 --info --text "You need an 8GB or above external storage device (sdcard /pendrive) to continue"
sudoAccess
removeSDCARD
insertSDCARD
SizeofSDCARD
selection_menu "Select Backup mode" "Incremental Backup" "Complete Backup"
case "${result}" in
"1" ) #Incremental
selection_menu "Incremental Backup options" "Continue with previous backup storage[if you have a previous incremental backup] " "Create a new backup by formating the storage"
case "${result}" in
"1" ) # check for mac_id matching & proceed to rsync
rootfs_path=`mount | grep ext|cut -d" " -f3` # tracking the rootfs mount path
mac_id=`cat /sys/class/net/eth0/address` # macid of the machine
if [ "$rootfs_path" == "" ] || [ "$mac_id" -ne `cat $rootfs_path/opt/.Hw_addr.txt` ];
then
zenity --width=600 --height=100 --info --text "Your storage media doesnot contain matching backup from this machine"
else
# rsync -avzr / $rootfs_path
fi
;;
"2" ) #start new rsync
cat /sys/class/net/eth0/address > /opt/.Hw_addr.txt # storing mac_id b4 copy
umount /media/$USER/*
echo $password
echo "start inc Bkup"
;;
esac
;;
"2" ) #Complete
echo "Do a complete Backup"
sudo tar -cpzf /media/student/<sdcard>/FirmwareInstall/ubuntu/ubuntu13.04.tar --one-file-system /
;;
esac
|