forked from Oline/cubieboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_debootstrap.sh
executable file
·259 lines (203 loc) · 6.47 KB
/
make_debootstrap.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#! /usr/bin/env sh
# Copyright (c) 2013-2014, Sylvain Leroy <[email protected]>
# 2014, Jean-Marc Lacroix <[email protected]>
# 2014, Philippe Thierry <[email protected]>
# This file is part of CBoard.
# CBoard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# CBoard is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with CBoard. If not, see <http://www.gnu.org/licenses/>.
#set -x
set -e
#############
# VARIABLES #
#############
# Including users defined variables
. ./makefile.vars
############
# FUNCTION #
############
do_debootstrap()
{
set -x
sudo /usr/sbin/debootstrap --foreign --arch "$DEB_ARCH" "$DEB_SUITE" . "$DEBOOTSTRAP_MIRROR"
# --variant=minbase
# that command is usefull to run target host binaries (ARM) on the build host (x86)
sudo cp /usr/bin/qemu-arm-static usr/bin
# if you use grsecurity on build host, you should uncomment that line
#sudo /sbin/paxctl -cm usr/bin/qemu-arm-static
#sudo /sbin/paxctl -cpexrms usr/bin/qemu-arm-static
# debootstrap second stage and packages configuration
sudo LC_ALL=C LANGUAGE=C LANG=C chroot . /debootstrap/debootstrap --second-stage
sudo LC_ALL=C LANGUAGE=C LANG=C chroot . dpkg --configure -a
set +x
}
##########
configure_system()
{
# set root password
echo "Please enter the root password: "
if [ -z "$ROOT_PASSWORD" ]; then
# hiding the root password when typed could be a good idea... (stty)
read ROOT_PASSWORD
fi
sudo bash -c "echo -e root:$ROOT_PASSWORD | chroot . chpasswd"
# this set -x does not appear before previous sudo, not to show the root password on the output.
set -x
# set hostname
echo "Please enter the hostname of the host: "
if [ -z "$HOSTNAME" ]; then
read HOSTNAME
fi
sudo bash -c "echo $HOSTNAME > etc/hostname"
# check if a serial console already exist in the inittab file
# we remove the error check to let grep output an error if the file does not have the line we look for
set +e
grep 'T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100' etc/inittab
RET_VALUE=$?
set -e
if [ 0 -ne "$RET_VALUE" ]; then
# add serial console to connect to the system
sudo bash -c 'echo "T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100" >> etc/inittab'
fi
# disable some local consoles
# sed -i 's/^\([3-6]:.* tty[3-6]\)/#\1/' /etc/inittab
# copy basic templates of configuration files
sudo cp ../fstab.base etc/fstab
sudo cp ../interfaces.base etc/network/interfaces
set +x
}
##########
update_system_and_custom_packages()
{
set -x
# tmp stuff
sudo cp /etc/resolv.conf etc
# updating root_fs
sudo bash -c "echo deb http://http.debian.net/debian/ $DEB_SUITE main contrib non-free > etc/apt/sources.list"
sudo bash -c "echo deb http://security.debian.org/ $DEB_SUITE/updates main contrib non-free >> etc/apt/sources.list"
sudo mkdir -p etc/apt/apt.conf.d
# Configure http proxy for APT
if [ -n "$HTTP_PROXY" ]
then
sudo bash -c "echo \"Acquire::http::Proxy \"$HTTP_PROXY\";\" > etc/apt/apt.conf.d/99proxy"
fi
# Update to be able to install lastest packages
sudo chroot . apt-get update
# Install brcmfmac firmware for Cubietruck (wifi/BT)
if [ x"$CUBIEBOARD_NAME" = "xCubietruck" ]; then
sudo chroot . apt-get install --yes firmware-brcm80211
if [ ! -d lib/firmware/brcm ]; then
echo "*** Failed to install firmware" 1>&2
exit 1
else
sudo cp ../resources/brcmfmac43362-sdio.txt lib/firmware/brcm/
fi
fi
# install additionnals packages
### Here $PACKAGES MUST be without double quotes or apt-get won't understand the list of packages
sudo chroot . apt-get install --yes $PACKAGES
# removing tmp stuff
sudo chroot . apt-get clean
sudo chroot . apt-get autoclean
sudo rm etc/resolv.conf
if [ -e etc/apt/apt.conf.d/99proxy ]
then
sudo rm etc/apt/apt.conf.d/99proxy
fi
set +x
}
##########
install_kernel()
{
set -x
# copy linux image to the root_fs
sudo cp ../$LINUX_DIR/arch/arm/boot/uImage boot
sudo cp ../$LINUX_DIR/arch/arm/boot/dts/${DTB} boot
sudo make -C ../$LINUX_DIR INSTALL_MOD_PATH=`pwd` ARCH=arm CROSS_COMPILE="$GCC_PREFIX" modules_install
# add some kernel boot args
mkimage -C none -A arm -T script -d ../boot.cmd ../boot.scr
sudo mv ../boot.scr boot/
sudo chown root:root boot/boot.scr
set +x
}
##########
board_script()
{
set -x
# grab template fex file for cubieboard
# case "$CUBIEBOARD_NAME" in
# Cubieboard)
# cp ../sunxi-boards/sys_config/a10/cubieboard.fex ../script.fex
# ;;
# Cubieboard2)
# cp ../sunxi-boards/sys_config/a20/cubieboard2.fex ../script.fex
# ;;
# *)
# echo "Unknown Cubieboard version. Leaving..."
# exit 1
# ;;
# esac
# Set Ethernet MAC addr
# echo "" >> ../script.fex
# echo "[dynamic]" >> ../script.fex
# echo "MAC = \"$MACADDR\"" >> ../script.fex
# Change the LEDs behavior
#grep leds_trigger ../script.fex
# created the binary version of the fex file
# ../sunxi-tools/fex2bin ../script.fex ../script.bin
# sudo chown root:root ../script.bin
# sudo mv ../script.bin boot/
# rm ../script.fex
# Adding fex manipulation binary to change Ethernet MAC addr at boot time using u-boot
# sudo cp ../sunxi-tools/fexc root/
# sudo chown root:root root/fexc
set +x
}
########
# MAIN #
########
# create the chroot if it doesn't exist
mkdir -p $CHROOT_DIR
cd $CHROOT_DIR
case "$1" in
all)
do_debootstrap
configure_system
update_system_and_custom_packages
install_kernel
board_script
;;
debootstrap)
do_debootstrap
;;
config)
configure_system
;;
custom)
update_system_and_custom_packages
;;
kernel)
install_kernel
;;
board_script)
board_script
;;
*)
echo "Usage: make_debootstrap.sh {all|debootstrap|config|custom|kernel|board_script}"
exit 1
esac
exit 0
##########
# Local Variables:
# mode:sh
# tab-width: 4
# indent-tabs-mode: nil
# End:
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=4:softtabstop=4