forked from mindboards/ev3dev-rootfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrootfs-create
executable file
·148 lines (115 loc) · 5.65 KB
/
rootfs-create
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
#!/bin/sh
# ------------------------------------------------------------------------------
# rootfs-create - download and configure a minimal rootfs for ev3dev
#
# Must be run as root (use sudo of course!)
# ------------------------------------------------------------------------------
die() { echo -n >&2 "\n$0: $@\n"; exit 1; }
# ------------------------------------------------------------------------------
# Make sure we're running as root
[ "$(whoami)" != "root" ] && die "Sorry, you are not root!"
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
TARGET_ROOTFS_DIR="ev3-rootfs"
# ------------------------------------------------------------------------------
# Make sure we want to overwrite the file if it already exists!
echo "-------------------------------------------------------------------------------"
echo " WARNING - If you type \"Yes\" to the prompt, this script"
echo " may OVERWRITE the ev3dev-rootfs directory!"
echo
echo " This script can be run multiple times, for example you may do the download"
echo " and initial unpacking the first time the script is run, then stop and save"
echo " that result so that you never have to download again."
echo
echo " The next time you run the script, you can bypass the download and do the"
echo " initial configuration and cleanup step, then save the result again."
echo
echo " You will always be asked for confirmation before a potentially destructive"
echo " step in the process!"
echo "-------------------------------------------------------------------------------"
echo -n " Type \"Yes\" to continue ... "
read YesNo
[ ! "${YesNo}" = "Yes" ] && die " .. aborting, you typed \"${YesNo}\""
# ------------------------------------------------------------------------------
# If we find a pre-existing directory, then ask if we want to recreate a blank one
if [ -d ${TARGET_ROOTFS_DIR} ]; then
echo "-------------------------------------------------------------------------------"
echo " Found an existing ${TARGET_ROOTFS_DIR}"
echo
echo -n " Type \"Yes\" to erase the contents, anything else to skip this step ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
echo -n " Erasing the exiting ${TARGET_ROOTFS_DIR} - should only take a few seconds ... "
rm -rf ${TARGET_ROOTFS_DIR} > /dev/null 2>&1
echo "done."
fi
fi
# ------------------------------------------------------------------------------
# Download the bare ev3-rootfs directory if we don't already have it
# cd ../ev3dev-rootfs
if [ ! -d ${TARGET_ROOTFS_DIR} ]; then
echo "-------------------------------------------------------------------------------"
echo " Downloading a complete grip rootfs from emDebian - this might take a while"
echo " so you might want to tail the multistrap.log file from another shell to keep"
echo " track of progress ... "
echo
echo -n " Type \"Yes\" to continue, anything else to skip this step ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
# multistrap -f multistrap.conf > multistrap.log 2>&1
multistrap -f multistrap.conf
fi
else
echo "-------------------------------------------------------------------------------"
echo " Checked for existing ev3-rootfs - already exists!"
fi
# ------------------------------------------------------------------------------
# Configuring the rootfs packages
if [ -d ${TARGET_ROOTFS_DIR} ]; then
echo "-------------------------------------------------------------------------------"
echo " This step will configure the rootfs - it will take a while and overwrite"
echo " any customizations you have done!"
echo
echo -n " Type \"Yes\" to continue, anything else to skip this step ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
if [ ! -e ${TARGET_ROOTFS_DIR}/usr/bin/qemu-arm-static ]; then
echo -n " Copying qemu-arm-static to ev3-rootfs/usr/bin ... "
cp /usr/bin/qemu-arm-static ${TARGET_ROOTFS_DIR}/usr/bin
echo "done."
fi
echo -n " Running the dash.preinst file in ev3-rootfs ... "
chroot ${TARGET_ROOTFS_DIR} var/lib/dpkg/info/dash.preinst install > /dev/null
echo "done."
echo " Configuring packages in ev3-rootfs - this will take a while!"
chroot ${TARGET_ROOTFS_DIR} dpkg --configure -a
echo "done."
# mount proc -t proc /proc
# dpkg --configure -a
fi
fi
# ------------------------------------------------------------------------------
# Clean out the apt archives in /var/
if [ -d ${TARGET_ROOTFS_DIR} ]; then
echo "-------------------------------------------------------------------------------"
echo " This step will clean up the rootfs by removing all the extra cruft"
echo " from /var"
echo
echo -n " Type \"Yes\" to continue, anything else to skip this step ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
echo
chroot ${TARGET_ROOTFS_DIR} apt-get clean
chroot ${TARGET_ROOTFS_DIR} apt-get purge
echo
echo -n " Deleting cached entries from /var/lib/apt/lists ... "
rm `find ${TARGET_ROOTFS_DIR}/var/lib/apt/lists -maxdepth 1 -type f -not -name "lock"` > /dev/null 2>&1
echo "done."
echo -n " Deleting package lists... "
rm ${TARGET_ROOTFS_DIR}/var/cache/apt/*.bin > /dev/null 2>&1
echo "done."
fi
fi
echo "-------------------------------------------------------------------------------"
# ------------------------------------------------------------------------------