-
Notifications
You must be signed in to change notification settings - Fork 0
/
burn.sh
executable file
·132 lines (111 loc) · 3.41 KB
/
burn.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
#!/bin/bash
function usage() {
cat <<EOF
USAGE: ${BASH_SOURCE[0]} [options] DESTINATION_UBOOT DESTINATION_ROOTFS
OPTIONS:
-h, --help Display this help message
EOF
}
function main() {
if [ "$(id -u)" != 0 ]; then
echo "Please run this script as root or with sudo" >&2
return 1
fi
POSITIONAL_ARGS=0
NEXT_POSITIONA_ARG=(DESTINATION_UBOOT DESTINATION_ROOTFS)
DESTINATION_UBOOT=
DESTINATION_ROOTFS=
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
usage
return 0
;;
-*)
echo "ERROR: Unrecognized option '$1'" >&2
usage
return 1
;;
*)
if [ "$POSITIONAL_ARGS" -ge 2 ] ; then
echo "ERROR: too many positional arguments!" >&2
usage
return 1
fi
declare "${NEXT_POSITIONA_ARG[$POSITIONAL_ARGS]}"="$1"
POSITIONAL_ARGS=$((POSITIONAL_ARGS+1))
esac
shift
done
if [ -z "$DESTINATION_UBOOT" ] || [ -z "$DESTINATION_ROOTFS" ]; then
echo "ERROR: required argument missing" >&2
usage
return 1
fi
if ! [ -d "$DESTINATION_UBOOT" ] || [ "$DESTINATION_UBOOT" = / ]; then
echo "Invalid argument DESTINATION_UBOOT: '$DESTINATION_UBOOT'" >&2
usage
return 1
fi
if ! [ -d "$DESTINATION_ROOTFS" ] || [ "$DESTINATION_ROOTFS" = / ]; then
echo "Invalid argument DESTINATION_ROOTFS: '$DESTINATION_ROOTFS'" >&2
usage
return 1
fi
DESTINATION_UBOOT="$(realpath "$DESTINATION_UBOOT")"
DESTINATION_ROOTFS="$(realpath "$DESTINATION_ROOTFS")"
echo ""
echo "About to write to the following directories,"
echo "please type 'y' to confirm."
echo "Anything else will exit."
echo ""
echo "boot: '$DESTINATION_UBOOT'"
echo "rootfs: '$DESTINATION_ROOTFS'"
echo ""
read -r -p "Are you sure? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
# Continue
;;
*)
echo "I'll take that as a no. Exiting."
return 1
;;
esac
SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
cd "$SCRIPT_DIR"
echo " +-- Setting target directories as instructed..."
# Substitute destination directories
MAKEFILE="zcu102_hwvirt_pikeos.int/Makefile"
tmpfile=$(mktemp)
cp "$MAKEFILE" "$tmpfile"
sed -i 's#/media/ubuntu/ROOT1#'"\"$DESTINATION_ROOTFS\""'#g' "$tmpfile"
sed -i 's#/media/ubuntu/ROOT#'"\"$DESTINATION_UBOOT\""'#g' "$tmpfile"
sed -i 's/umount/#umount/g' "$tmpfile"
# TODO: rename to image.ub
cp "$tmpfile" "$MAKEFILE.tmp"
rm -f "$tmpfile"
echo " +-- Restarting the license server"
systemctl stop lmxserv51
rm -f /usr/lmx-5.1/lmx-serv.pid
systemctl start lmxserv51
echo " +-- Cleaning target directories..."
rm -rf "${DESTINATION_UBOOT:?}"/*
rm -rf "${DESTINATION_ROOTFS:?}"/*
echo " +-- Burning on target directories..."
cd zcu102_hwvirt_pikeos.int
# source ELINOS.sh
source PikeOS.sh
make -f Makefile.tmp install
rm -f Makefile.tmp
cd ..
mv "$DESTINATION_UBOOT"/hwvirt-linux-zynq-zcu102-hwvirt-uboot_dtb "$DESTINATION_UBOOT/image.ub"
cp uboot/* "$DESTINATION_UBOOT"
umount "$DESTINATION_UBOOT"
umount "$DESTINATION_ROOTFS"
echo ' +-- Success!'
}
(
set -e
main "$@"
)