-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchlinux.sh
347 lines (241 loc) · 7.59 KB
/
archlinux.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/bin/bash
set -e
# Downloads common.sh if script was run out of the git tree eg: Following readme instructions.
common_file="https://github.com/LordRafa/ALARMOnTegraK1/releases/latest/download/common.sh"
ls common.sh &> /dev/null || curl -s -L $common_file -o common.sh
. ./common.sh
MY_CHROOT_DIR=${WORK_PATH}
target_rootfs=""
EMMC_PATH="/dev/mmcblk0p1"
SD_PATH="/dev/mmcblk1p1"
SDA_PATH="/dev/sda1"
MANUAL_PATH=${MY_CHROOT_DIR}
case $1 in
"emmc")
target_rootfs=${EMMC_PATH}
;;
"sd")
target_rootfs=${SD_PATH}
;;
"sda")
target_rootfs=${SDA_PATH}
;;
"manual")
target_rootfs=${MANUAL_PATH}
;;
*)
echo -e "Usage: archlinux.sh [emmc|sd|sda|manual]:\n"\
"\temmc -> Installs Arch Linux ARM on the EMMC.\n"\
"\tsd -> Installs Arch Linux ARM on the SD Card.\n"\
"\tsda -> Installs Arch Linux ARM on the SATA Device.\n"\
"\tmanual -> Installs Arch Linux ARM on a manually mounted device/s at ${MY_CHROOT_DIR} (note: No partitioning nor formatting will be done).\n"
exit 1
;;
esac
function format_target () {
start_progress "Formatting and mount target rootfs"
ls ${MY_CHROOT_DIR} &> /dev/null || mkdir ${MY_CHROOT_DIR} >> ${LOGFILE} 2>&1
mkfs.ext3 ${target_rootfs} >> ${LOGFILE} 2>&1
mount -t ext3 ${target_rootfs} ${MY_CHROOT_DIR} >> ${LOGFILE} 2>&1
if [[ $1 == "sda" ]]; then
mkfs.ext3 ${EMMC_PATH} >> ${LOGFILE} 2>&1
mkdir ${MY_CHROOT_DIR}/boot >> ${LOGFILE} 2>&1
mount -t ext3 ${EMMC_PATH} ${MY_CHROOT_DIR}/boot >> ${LOGFILE} 2>&1
fi
end_progress "done"
}
function install_base () {
start_progress "Downloading and extracting ArchLinuxARM rootfs"
curl -s -L --output - $rootfs_file | tar xzvvp -C ${MY_CHROOT_DIR}/ >> ${LOGFILE} 2>&1
end_progress "done"
}
#
# Note, this function removes the script after execution
#
function exec_in_chroot () {
script=$1
if [ -f ${MY_CHROOT_DIR}/${script} ] ; then
chmod a+x ${MY_CHROOT_DIR}/${script}
chroot ${MY_CHROOT_DIR} /bin/bash -c /${script} >> ${LOGFILE} 2>&1
rm ${MY_CHROOT_DIR}/${script}
fi
}
function setup_chroot () {
mount -o bind /proc ${MY_CHROOT_DIR}/proc
mount -o bind /dev ${MY_CHROOT_DIR}/dev
mount -o bind /dev/pts ${MY_CHROOT_DIR}/dev/pts
mount -o bind /sys ${MY_CHROOT_DIR}/sys
}
function unset_chroot () {
if [ "x${PROGRESS_PID}" != "x" ]
then
end_progress "done"
fi
umount ${MY_CHROOT_DIR}/proc
umount ${MY_CHROOT_DIR}/dev
umount ${MY_CHROOT_DIR}/dev/pts
umount ${MY_CHROOT_DIR}/sys
}
trap unset_chroot EXIT
function copy_chros_files () {
start_progress "Copying additional files to ArchLinuxARM rootdir"
dhcpcd
mkdir -p ${MY_CHROOT_DIR}/run/resolvconf
cp /etc/resolv.conf ${MY_CHROOT_DIR}/run/resolvconf/
ln -s -f /run/resolvconf/resolv.conf ${MY_CHROOT_DIR}/etc/resolv.conf
echo alarm > ${MY_CHROOT_DIR}/etc/hostname
echo -e "\n127.0.1.1\tlocalhost.localdomain\tlocalhost\talarm" >> ${MY_CHROOT_DIR}/etc/hosts
end_progress "done"
}
function install_dev_tools () {
start_progress "Installing development base packages"
#
# Add some development tools and put the alarm user into the
# wheel group. Furthermore, grant ALL privileges via sudo to users
# that belong to the wheel group
#
cat > ${MY_CHROOT_DIR}/install-develbase.sh << EOF
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syyu --needed --noconfirm sudo wget dialog base-devel devtools vim rsync git vboot-utils
usermod -aG wheel alarm
sed -i 's/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /etc/sudoers
EOF
exec_in_chroot install-develbase.sh
end_progress "done"
}
function install_xbase () {
start_progress "Installing X-server basics"
cat > ${MY_CHROOT_DIR}/install-xbase.sh <<EOF
pacman -Syy --needed --noconfirm \
iw networkmanager network-manager-applet \
lightdm lightdm-gtk-greeter \
chromium \
xorg-apps \
xorg_server \
xorg-twm xorg-xclock xterm xorg-xinit \
xf86-input-evdev xf86-video-fbdev
systemctl enable NetworkManager
systemctl enable lightdm
EOF
exec_in_chroot install-xbase.sh
end_progress "done"
}
function install_mate () {
start_progress "Installing Mate"
# add .xinitrc to /etc/skel that defaults to Mate session
cat > ${MY_CHROOT_DIR}/etc/skel/.xinitrc << EOF
#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
if [ -d /etc/X11/xinit/xinitrc.d ]; then
for f in /etc/X11/xinit/xinitrc.d/*; do
[ -x \"\$f\" ] && . \"\$f\"
done
unset f
fi
exec mate-session
# exec startkde
# exec startxfce4
# ...or the Window Manager of your choice
EOF
cat > ${MY_CHROOT_DIR}/install-mate.sh << EOF
pacman -Syy --needed --noconfirm mate mate-extra
# copy .xinitrc to already existing home of user 'alarm'
cp /etc/skel/.xinitrc /home/alarm/.xinitrc
cp /etc/skel/.xinitrc /home/alarm/.xprofile
sed -i 's/exec mate-session/# exec mate-session/' /home/alarm/.xprofile
chown alarm:users /home/alarm/.xinitrc
chown alarm:users /home/alarm/.xprofile
EOF
exec_in_chroot install-mate.sh
end_progress "done"
}
function install_kernel () {
start_progress "Installing kernel"
cat > ${MY_CHROOT_DIR}/install-kernel.sh << EOF
wget ${kernel_file}
wget ${headers_file}
pacman -R --noconfirm linux-armv7
yes n | pacman -U --noconfirm linux-${board}-*
rm linux-${board}-*
EOF
exec_in_chroot install-kernel.sh
end_progress "done"
}
function install_misc_utils () {
start_progress "Installing some more utilities"
cat > ${MY_CHROOT_DIR}/install-utils.sh <<EOF
pacman -Syy --needed --noconfirm sshfs screen file-roller bluez bluez-utils blueman uboot-tools
systemctl enable bluetooth.service
EOF
exec_in_chroot install-utils.sh
end_progress "done"
}
function install_uboot_conf () {
start_progress "Performing configure U-BOOT."
rootfs=$(findmnt -n -o source ${MY_CHROOT_DIR})
cat > ${MY_CHROOT_DIR}/uboot-conf.sh <<EOF
pacman -Syy --needed --noconfirm uboot-tools
echo "/dev/mmcblk0boot1 0x3fe000 0x2000" > /etc/fw_env.config
if [[ $1 != "sd" ]]; then
echo 0 > /sys/block/mmcblk0boot1/force_ro
fw_setenv bootargs console=ttyS0,115200n8 console=tty1 root=${rootfs} rw rootwait
fi
EOF
exec_in_chroot uboot-conf.sh
end_progress "done"
}
function install_misc_conf () {
start_progress "Performing some additional configuration."
cat > ${MY_CHROOT_DIR}/misc-conf.sh <<EOF
echo AutoEnable=true >> /etc/bluetooth/main.conf
EOF
exec_in_chroot misc-conf.sh
end_progress "done"
}
function install_sound () {
start_progress "Installing sound (alsa/pulseaudio)"
cat > ${MY_CHROOT_DIR}/install-sound.sh <<EOF
pacman -Syy --needed --noconfirm \
alsa-lib alsa-utils alsa-tools alsa-oss alsa-firmware alsa-plugins \
pulseaudio pulseaudio-alsa
amixer -c 0 set 'IEC958' 100% unmute
alsactl store
EOF
exec_in_chroot install-sound.sh
curl -s -L --output - $alsacfg_file | tar xJvvp -C ${MY_CHROOT_DIR}/ >> ${LOGFILE} 2>&1
end_progress "done"
}
echo "" > $LOGFILE
echo -e "Installing ArchLinuxARM ${archlinux_version}-${archlinux_arch}\n"
echo -e "Warning: This will destroy any data on ${target_rootfs}\n"
read -p "Press [Enter] to continue..."
if [[ $1 != "manual" ]]; then
format_target $1
fi
install_base
setup_chroot
copy_chros_files
install_dev_tools
install_xbase
install_mate
install_sound
install_kernel
install_misc_utils
install_uboot_conf $1
install_misc_conf
echo -e "
Installation seems to be complete.
The ArchLinuxARM login is:
Username: alarm
Password: alarm
Root access can either be gained via sudo, or the root user:
Username: root
Password: root
We're now ready to start ArchLinuxARM!
"
read -p "Press [Enter] to reboot..."
reboot