forked from armbian/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeboarddeb.sh
336 lines (294 loc) · 12.8 KB
/
makeboarddeb.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
#!/bin/bash
#
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of tool chain https://github.com/igorpecovnik/lib
#
#
# Create board support packages
#
# Functions:
# create_board_package
create_board_package()
{
display_alert "Creating board support package" "$BOARD $BRANCH" "info"
local destination=$DEST/debs/$RELEASE/${CHOSEN_ROOTFS}_${REVISION}_${ARCH}
rm -rf $destination
mkdir -p $destination/DEBIAN
# Replaces: base-files is needed to replace /etc/update-motd.d/ files on Xenial
# Replaces: unattended-upgrades may be needed to replace /etc/apt/apt.conf.d/50unattended-upgrades
# (distributions provide good defaults, so this is not needed currently)
# Depends: linux-base is needed for "linux-version" command in initrd cleanup script
cat <<-EOF > $destination/DEBIAN/control
Package: linux-${RELEASE}-root-${DEB_BRANCH}${BOARD}
Version: $REVISION
Architecture: $ARCH
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
Installed-Size: 1
Section: kernel
Priority: optional
Depends: bash, linux-base, u-boot-tools, initramfs-tools
Provides: armbian-bsp
Conflicts: armbian-bsp
Replaces: base-files, mpv
Recommends: bsdutils, parted, python3-apt, util-linux, toilet, wireless-tools
Description: Armbian tweaks for $RELEASE on $BOARD ($BRANCH branch)
EOF
# set up pre install script
cat <<-EOF > $destination/DEBIAN/preinst
#!/bin/sh
[ "\$1" = "upgrade" ] && touch /var/run/.reboot_required
[ -d "/boot/bin.old" ] && rm -rf /boot/bin.old
[ -d "/boot/bin" ] && mv -f /boot/bin /boot/bin.old
if [ -L "/etc/network/interfaces" ]; then
cp /etc/network/interfaces /etc/network/interfaces.tmp
rm /etc/network/interfaces
mv /etc/network/interfaces.tmp /etc/network/interfaces
fi
# make a backup since we are unconditionally overwriting this on update
cp /etc/default/cpufrequtils /etc/default/cpufrequtils.dpkg-old
dpkg-divert --package linux-${RELEASE}-root-${DEB_BRANCH}${BOARD} --add --rename \
--divert /etc/mpv/mpv-dist.conf /etc/mpv/mpv.conf
exit 0
EOF
chmod 755 $destination/DEBIAN/preinst
# postrm script
cat <<-EOF > $destination/DEBIAN/postrm
#!/bin/sh
[ remove = "\$1" ] || [ abort-install = "\$1" ] && dpkg-divert --package linux-${RELEASE}-root-${DEB_BRANCH}${BOARD} --remove --rename \
--divert /etc/mpv/mpv-dist.conf /etc/mpv/mpv.conf
systemctl disable log2ram.service armhwinfo.service >/dev/null 2>&1
exit 0
EOF
chmod 755 $destination/DEBIAN/postrm
# set up post install script
cat <<-EOF > $destination/DEBIAN/postinst
#!/bin/sh
[ ! -f "/etc/network/interfaces" ] && cp /etc/network/interfaces.default /etc/network/interfaces
ln -sf /var/run/motd /etc/motd
rm -f /etc/update-motd.d/00-header /etc/update-motd.d/10-help-text
if [ -f "/boot/bin/$BOARD.bin" ] && [ ! -f "/boot/script.bin" ]; then ln -sf bin/$BOARD.bin /boot/script.bin >/dev/null 2>&1 || cp /boot/bin/$BOARD.bin /boot/script.bin; fi
rm -f /usr/local/bin/h3disp /usr/local/bin/h3consumption
[ ! -f /etc/default/armbian-motd ] && cp /usr/lib/armbian/armbian-motd.default /etc/default/armbian-motd
if [ ! -f "/etc/default/log2ram" ]; then
cp /etc/default/log2ram.dpkg-dist /etc/default/log2ram
fi
if [ -f "/etc/systemd/system/log2ram.service" ]; then
mv /etc/systemd/system/log2ram.service /etc/systemd/system/log2ram-service.dpkg-old
fi
if [ -f "/lib/systemd/system/pinebook-enable-sound.service" ]; then
systemctl enable pinebook-enable-sound.service
fi
exit 0
EOF
chmod 755 $destination/DEBIAN/postinst
# won't recreate files if they were removed by user
# TODO: Add proper handling for updated conffiles
#cat <<-EOF > $destination/DEBIAN/conffiles
#EOF
# trigger uInitrd creation after installation, to apply
# /etc/initramfs/post-update.d/99-uboot
cat <<-EOF > $destination/DEBIAN/triggers
activate update-initramfs
EOF
# create directory structure
mkdir -p $destination/etc/{init.d,default,update-motd.d,profile.d,network,cron.d,cron.daily}
mkdir -p $destination/usr/{bin,sbin} $destination/usr/lib/armbian/ $destination/usr/share/armbian/ $destination/usr/share/log2ram/
mkdir -p $destination/etc/initramfs/post-update.d/
mkdir -p $destination/etc/kernel/preinst.d/
mkdir -p $destination/etc/apt/apt.conf.d/ $destination/etc/apt/preferences.d/
mkdir -p $destination/etc/X11/xorg.conf.d/
mkdir -p $destination/lib/systemd/system/
install -m 755 $SRC/lib/scripts/armhwinfo $destination/etc/init.d/
# configure MIN / MAX speed for cpufrequtils
cat <<-EOF > $destination/etc/default/cpufrequtils
ENABLE=true
MIN_SPEED=$CPUMIN
MAX_SPEED=$CPUMAX
GOVERNOR=$GOVERNOR
EOF
# armhwinfo, firstrun, armbianmonitor, etc. config file
cat <<-EOF > $destination/etc/armbian-release
# PLEASE DO NOT EDIT THIS FILE
BOARD=$BOARD
BOARD_NAME="$BOARD_NAME"
VERSION=$REVISION
LINUXFAMILY=$LINUXFAMILY
BRANCH=$BRANCH
ARCH=$ARCHITECTURE
IMAGE_TYPE=$IMAGE_TYPE
BOARD_TYPE=$BOARD_TYPE
EOF
# add USB OTG port mode switcher (obsolete - will be handled with DT overlays)
# install -m 755 $SRC/lib/scripts/sunxi-musb $destination/usr/bin
# armbianmonitor (currently only to toggle boot verbosity and log upload)
install -m 755 $SRC/lib/scripts/armbianmonitor/armbianmonitor $destination/usr/bin
# updating uInitrd image in update-initramfs trigger
cat <<-EOF > $destination/etc/initramfs/post-update.d/99-uboot
#!/bin/sh
echo "update-initramfs: Converting to u-boot format" >&2
tempname="/boot/uInitrd-\$1"
mkimage -A $INITRD_ARCH -O linux -T ramdisk -C gzip -n uInitrd -d \$2 \$tempname > /dev/null
ln -sf \$(basename \$tempname) /boot/uInitrd > /dev/null 2>&1 || mv \$tempname /boot/uInitrd
exit 0
EOF
chmod +x $destination/etc/initramfs/post-update.d/99-uboot
# removing old initrd.img on upgrade
cat <<-EOF > $destination/etc/kernel/preinst.d/initramfs-cleanup
#!/bin/sh
version="\$1"
[ -x /usr/sbin/update-initramfs ] || exit 0
# passing the kernel version is required
if [ -z "\${version}" ]; then
echo >&2 "W: initramfs-tools: \${DPKG_MAINTSCRIPT_PACKAGE:-kernel package} did not pass a version number"
exit 0
fi
# avoid running multiple times
if [ -n "\$DEB_MAINT_PARAMS" ]; then
eval set -- "\$DEB_MAINT_PARAMS"
if [ -z "\$1" ] || [ "\$1" != "upgrade" ]; then
exit 0
fi
fi
STATEDIR=/var/lib/initramfs-tools
version_list="\$(ls -1 "\${STATEDIR}" | linux-version sort --reverse)"
for v in \$version_list; do
if ! linux-version compare \$v eq \$version; then
# try to delete delete old initrd images via update-initramfs
INITRAMFS_TOOLS_KERNEL_HOOK=y update-initramfs -d -k \$v 2>/dev/null
# delete unused state files
find \$STATEDIR -type f ! -name "\$version" -printf "Removing obsolete file %f\n" -delete
# delete unused initrd images
find /boot -name "initrd.img*" -o -name "uInitrd-*" ! -name "*\$version" -printf "Removing obsolete file %f\n" -delete
fi
done
EOF
chmod +x $destination/etc/kernel/preinst.d/initramfs-cleanup
# network interfaces configuration
cp $SRC/lib/config/network/interfaces.* $destination/etc/network/
[[ $RELEASE = xenial ]] && sed -i 's/#no-auto-down/no-auto-down/g' $destination/etc/network/interfaces.default
# apt configuration
cat <<-EOF > $destination/etc/apt/apt.conf.d/71-no-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
# xorg configuration
cat <<-EOF > $destination/etc/X11/xorg.conf.d/01-armbian-defaults.conf
Section "Monitor"
Identifier "Monitor0"
Option "DPMS" "false"
EndSection
Section "ServerFlags"
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
EndSection
EOF
# configure the system for unattended upgrades
cp $SRC/lib/scripts/02periodic $destination/etc/apt/apt.conf.d/02periodic
# pin priority for armbian repo
# reference: man apt_preferences
# this allows providing own versions of hostapd, libdri2 and sunxi-tools
cat <<-EOF > $destination/etc/apt/preferences.d/50-armbian.pref
Package: *
Pin: origin "apt.armbian.com"
Pin-Priority: 500
EOF
# script to install to SATA
cp -R $SRC/lib/scripts/nand-sata-install/usr $destination/
chmod +x $destination/usr/lib/nand-sata-install/nand-sata-install.sh
ln -s ../lib/nand-sata-install/nand-sata-install.sh $destination/usr/sbin/nand-sata-install
# configuration script
# TODO: better git update logic
if [[ -d $SRC/sources/Debian-micro-home-server ]]; then
git --work-tree=$SRC/sources/Debian-micro-home-server --git-dir=$SRC/sources/Debian-micro-home-server/.git pull
else
git clone https://github.com/igorpecovnik/Debian-micro-home-server $SRC/sources/Debian-micro-home-server
fi
install -m 755 $SRC/sources/Debian-micro-home-server/scripts/tv_grab_file $destination/usr/bin/tv_grab_file
install -m 755 $SRC/sources/Debian-micro-home-server/debian-config $destination/usr/bin/armbian-config
install -m 755 $SRC/sources/Debian-micro-home-server/softy $destination/usr/bin/softy
# install custom motd with reboot and upgrade checking
install -m 755 $SRC/lib/scripts/update-motd.d/* $destination/etc/update-motd.d/
cp $SRC/lib/scripts/check_first_login_reboot.sh $destination/etc/profile.d
cp $SRC/lib/scripts/check_first_login.sh $destination/etc/profile.d
install -m 755 $SRC/lib/scripts/apt-updates $destination/usr/lib/armbian/apt-updates
cat <<-EOF > $destination/usr/lib/armbian/armbian-motd.default
# add space-separated list of MOTD script names (without number) to exclude them from MOTD
# Example:
# MOTD_DISABLE="header tips updates"
MOTD_DISABLE=""
EOF
cat <<-EOF > $destination/etc/cron.d/armbian-updates
@reboot root /usr/lib/armbian/apt-updates
@daily root /usr/lib/armbian/apt-updates
EOF
# setting window title for remote sessions
install -m 755 $SRC/lib/scripts/ssh-title.sh $destination/etc/profile.d/ssh-title.sh
# install copy of boot script & environment file
local bootscript_src=${BOOTSCRIPT%%:*}
local bootscript_dst=${BOOTSCRIPT##*:}
cp $SRC/lib/config/bootscripts/$bootscript_src $destination/usr/share/armbian/$bootscript_dst
[[ -n $BOOTENV_FILE && -f $SRC/lib/config/bootenv/$BOOTENV_FILE ]] && \
cp $SRC/lib/config/bootenv/$BOOTENV_FILE $destination/usr/share/armbian/armbianEnv.txt
# h3disp for sun8i/3.4.x
if [[ $LINUXFAMILY == sun8i && $BRANCH == default ]]; then
install -m 755 $SRC/lib/scripts/h3disp $destination/usr/bin
install -m 755 $SRC/lib/scripts/h3consumption $destination/usr/bin
fi
# add configuration for setting uboot environment from userspace with: fw_setenv fw_printenv
if [[ -n $UBOOT_FW_ENV ]]; then
UBOOT_FW_ENV=($(tr ',' ' ' <<< "$UBOOT_FW_ENV"))
echo "# Device to access offset env size" > $destination/etc/fw_env.config
echo "/dev/mmcblk0 ${UBOOT_FW_ENV[0]} ${UBOOT_FW_ENV[1]}" >> $destination/etc/fw_env.config
fi
# log2ram - systemd compatible ramlog alternative
cp $SRC/lib/scripts/log2ram/LICENSE.log2ram $destination/usr/share/log2ram/LICENSE
cp $SRC/lib/scripts/log2ram/log2ram.service $destination/lib/systemd/system/log2ram.service
install -m 755 $SRC/lib/scripts/log2ram/log2ram $destination/usr/sbin/log2ram
install -m 755 $SRC/lib/scripts/log2ram/log2ram.hourly $destination/etc/cron.daily/log2ram
cp $SRC/lib/scripts/log2ram/log2ram.default $destination/etc/default/log2ram.dpkg-dist
if [[ $LINUXFAMILY == sun*i* ]]; then
install -m 755 $SRC/lib/scripts/armbian-add-overlay $destination/usr/sbin
if [[ $BRANCH == default ]]; then
arm-linux-gnueabihf-gcc $SRC/lib/scripts/sunxi-temp/sunxi_tp_temp.c -o $destination/usr/bin/sunxi_tp_temp
# convert and add fex files
mkdir -p $destination/boot/bin
for i in $(ls -w1 $SRC/lib/config/fex/*.fex | xargs -n1 basename); do
fex2bin $SRC/lib/config/fex/${i%*.fex}.fex $destination/boot/bin/${i%*.fex}.bin
done
fi
fi
if [[ ( $LINUXFAMILY == sun*i || $LINUXFAMILY == pine64 ) && $BRANCH == default ]]; then
# add mpv config for vdpau_sunxi
mkdir -p $destination/etc/mpv/
cp $SRC/lib/config/mpv_sunxi.conf $destination/etc/mpv/mpv.conf
echo "export VDPAU_OSD=1" > $destination/etc/profile.d/90-vdpau.sh
chmod 755 $destination/etc/profile.d/90-vdpau.sh
fi
if [[ ( $LINUXFAMILY == sun50i* || $LINUXFAMILY == sun8i ) && $BRANCH == dev ]]; then
# add mpv config for x11 output - slow, but it works compared to no config at all
mkdir -p $destination/etc/mpv/
cat <<-EOF > $destination/etc/mpv/mpv.conf
# HW acceleration is not supported on this platform yet
vo=x11
EOF
fi
#TODO: move to sources.conf
if [[ $BOARD == pinebook-a64 ]]; then
cp $SRC/lib/scripts/pinebook-enable-sound.service $destination/lib/systemd/system/
fi
# add some summary to the image
fingerprint_image "$destination/etc/armbian.txt"
# create board DEB file
display_alert "Building package" "$CHOSEN_ROOTFS" "info"
cd $DEST/debs/$RELEASE/
dpkg -b ${CHOSEN_ROOTFS}_${REVISION}_${ARCH} >/dev/null
# cleanup
rm -rf ${CHOSEN_ROOTFS}_${REVISION}_${ARCH}
}