-
Notifications
You must be signed in to change notification settings - Fork 0
/
copy_to_sd_card.sh
executable file
·146 lines (97 loc) · 3.42 KB
/
copy_to_sd_card.sh
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
#!/bin/bash
set -e
if [ -z ${setup_env+x} ]; then
echo -e "$c_info Sourcing setup_env.sh.. $c_default"
source ./setup_env.sh
fi
# make sure to be in the same directory as this script #########################
script_dir_abs=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd "${script_dir_abs}"
# Functions definitions ########################################################
abort() {
echo -e "$c_error Error in `basename "$0"`$c_default"
exit 1
}
trap 'abort' 0
echo -e "$c_good *** START `basename "$0"` *** $c_default"
#Copy files to sd card
sdcard_abs="$1"
if [ ! -b "${sdcard_abs}" ]; then
while [ ! -b "${sdcard_abs}" ]; do
echo "Error: could not find \"${sdcard_abs}\""
echo "You can plug the SD card or quit the script with CTRL + C"
read -p "Press [Enter] key to restart..."
done
fi
if [ "$(echo "${sdcard_abs}" | grep -P "/dev/sd\w$")" ]; then
sdcard_fat32_partition_number="1"
sdcard_dev_ext3_id="2"
sdcard_preloader_partition_number="3"
elif [ "$(echo "${sdcard_abs}" | grep -P "/dev/mmcblk\w$")" ]; then
sdcard_fat32_partition_number="p1"
sdcard_dev_ext3_id="p2"
sdcard_preloader_partition_number="p3"
else
echo -e "$c_errorYou entered a partition. Please enter only the name of the sdcard..$c_default"
exit 1
fi
media_fat="/media/sdcard_fat32"
media_ext4="/media/sdcard_ext4"
set +e
sudo umount ${sdcard_abs}${sdcard_dev_ext3_id}
sudo umount ${sdcard_abs}${sdcard_fat32_partition_number}
set -e
sudo mkdir -p "$media_ext4"
sudo mount -t ext4 "${sdcard_abs}$sdcard_dev_ext3_id" "$media_ext4"
#Copy files in rootfs
sudo mkdir -p "$media_ext4/root/Desktop"
sudo rm -rf "$media_ext4/root/Desktop/*"
pushd $applications_dir_r
#shopt -s extglob
#shopt -u extglob
for d in * ; do
if [ -d $d ]; then
ommit="make_*.sh *.pdf *.o ./old *~ .* *.o"
echo -e "$c_info Copying $d to \"$media_ext4/root/Desktop/$d\" ommiting $ommit . $c_default"
#sudo cp -rv "!(*.sh)" "./$d" "$media_ext4/root/Desktop/"
sudo rsync -rv --exclude 'make_*.sh' "./$d" "$media_ext4/root/Desktop/"
#Exclude make.sh in the copy
#cp -r !(make.sh) ./directory
fi
done
echo -e "$c_info -------------------------------- $c_default"
for d in *.sh ; do
echo -e "$c_info Copying script $d to "$media_ext4/root/Desktop/" $c_default"
sudo cp "$d" "$media_ext4/root/Desktop/"
done
popd
pushd $preset_dir_r
if [ -f "etc_network_interfaces" ]; then
sudo cp "etc_network_interfaces" "$media_ext4/etc/network/interfaces"
fi
if [ -f "rc.local" ]; then
sudo cp "rc.local" "$media_ext4/etc/rc.local"
fi
sudo cp -r ./pkg "$media_ext4/root/Desktop/"
popd
sudo sync
sudo umount "${sdcard_abs}$sdcard_dev_ext3_id"
sudo rm -rf "$media_ext4"
sudo mkdir -p "$media_fat"
sudo mount -t vfat "${sdcard_abs}${sdcard_fat32_partition_number}" "$media_fat"
sudo rm -rf "$media_fat"/*
sudo cp "$build_dir_r/uImage" "$media_fat"
sudo cp "$build_dir_r/devicetree.dtb" "$media_fat"
sudo cp "$build_dir_r/BOOT.bin" "$media_fat/"
sudo cp "$build_dir_r/uEnv.txt" "$media_fat/"
sudo cp "$build_dir_r/7z020.bit" "$media_fat"
ls -l "$media_fat/"
sudo sync
sudo umount "$media_fat"
sudo rm -rf "$media_fat"
set +e
sudo umount ${sdcard_abs}${sdcard_dev_ext3_id}
sudo umount ${sdcard_abs}${sdcard_fat32_partition_number}
set -e
trap : 0
echo -e "$c_good *** DONE `basename "$0"` *** $c_default"