2015-12-02 20:33:32 +01:00
|
|
|
#!/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
|
|
|
|
#
|
2015-12-18 12:22:42 +03:00
|
|
|
# Functions:
|
|
|
|
# install_distribution_specific
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
install_distribution_specific (){
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
# Install board common applications
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------------
|
2016-04-05 16:04:48 +03:00
|
|
|
display_alert "Applying distribution specific tweaks for" "$RELEASE" "info"
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2015-12-26 10:25:00 +01:00
|
|
|
# Common
|
|
|
|
|
|
|
|
# set up apt
|
2016-03-17 20:16:26 +01:00
|
|
|
cat <<END > $CACHEDIR/sdcard/etc/apt/apt.conf.d/71-no-recommends
|
2015-12-26 10:25:00 +01:00
|
|
|
APT::Install-Recommends "0";
|
|
|
|
APT::Install-Suggests "0";
|
|
|
|
END
|
|
|
|
|
|
|
|
# configure the system for unattended upgrades
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/scripts/50unattended-upgrades $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
cp $SRC/lib/scripts/02periodic $CACHEDIR/sdcard/etc/apt/apt.conf.d/02periodic
|
2015-12-26 10:25:00 +01:00
|
|
|
|
2016-03-06 14:13:34 +03:00
|
|
|
# setting window title for remote sessions
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/profile.d
|
|
|
|
install -m 755 $SRC/lib/scripts/ssh-title.sh $CACHEDIR/sdcard/etc/profile.d/ssh-title.sh
|
2016-03-06 14:13:34 +03:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
case $RELEASE in
|
|
|
|
|
|
|
|
# Debian Wheezy
|
|
|
|
wheezy)
|
|
|
|
# add serial console
|
2016-03-17 20:16:26 +01:00
|
|
|
echo T0:2345:respawn:/sbin/getty -L $SERIALCON 115200 vt100 >> $CACHEDIR/sdcard/etc/inittab
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# don't clear screen on boot console
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e 's/getty 38400 tty1/getty --noclear 38400 tty1/g' -i $CACHEDIR/sdcard/etc/inittab
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# disable some getties
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e 's/5:23:respawn/#5:23:respawn/g' -i $CACHEDIR/sdcard/etc/inittab
|
|
|
|
sed -e 's/6:23:respawn/#6:23:respawn/g' -i $CACHEDIR/sdcard/etc/inittab
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# auto upgrading
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e "s/ORIGIN/Debian/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
sed -e "s/n=CODENAME/a=old-stable/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# install ramlog
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/bin/ramlog_2.0.0_all.deb $CACHEDIR/sdcard/tmp
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg -i /tmp/ramlog_2.0.0_all.deb >/dev/null 2>&1"
|
2015-12-02 20:33:32 +01:00
|
|
|
# enabled back at first run. To remove errors
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "service ramlog disable >/dev/null 2>&1"
|
|
|
|
rm $CACHEDIR/sdcard/tmp/ramlog_2.0.0_all.deb
|
|
|
|
sed -e 's/TMPFS_RAMFS_SIZE=/TMPFS_RAMFS_SIZE=512m/g' -i $CACHEDIR/sdcard/etc/default/ramlog
|
|
|
|
sed -e 's/$remote_fs $time/$remote_fs $time ramlog/g' -i $CACHEDIR/sdcard/etc/init.d/rsyslog
|
|
|
|
sed -e 's/umountnfs $time/umountnfs $time ramlog/g' -i $CACHEDIR/sdcard/etc/init.d/rsyslog
|
2015-12-02 20:33:32 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
# Debian Jessie
|
|
|
|
jessie)
|
|
|
|
# enable root login for latest ssh on jessie
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' $CACHEDIR/sdcard/etc/ssh/sshd_config
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# auto upgrading
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e "s/ORIGIN/Debian/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
sed -e "s/CODENAME/$RELEASE/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# mount 256Mb tmpfs to /tmp
|
2016-03-17 20:16:26 +01:00
|
|
|
echo "tmpfs /tmp tmpfs nodev,nosuid,size=256M 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
|
|
|
|
|
|
|
# fix selinux error
|
|
|
|
mkdir $CACHEDIR/sdcard/selinux
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# add serial console
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/config/ttyS0.conf $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
|
|
|
sed -e "s/ttyS0/$SERIALCON/g" -i $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "systemctl --no-reload enable serial-getty@$SERIALCON.service >/dev/null 2>&1"
|
|
|
|
mkdir -p "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d"
|
2016-05-01 15:01:42 +03:00
|
|
|
printf "[Service]\nExecStart=\nExecStart=-/sbin/agetty -L 115200 %%I $TERM" > "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d/10-rate.conf"
|
2015-12-19 13:01:14 +03:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# don't clear screen tty1
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p "$CACHEDIR/sdcard/etc/systemd/system/getty@tty1.service.d/"
|
2016-05-01 14:24:40 +03:00
|
|
|
printf "[Service]\nTTYVTDisallocate=no" > "$CACHEDIR/sdcard/etc/systemd/system/getty@tty1.service.d/10-noclear.conf"
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2015-12-18 21:52:33 +01:00
|
|
|
# seting timeout
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/systemd/system/systemd-modules-load.service.d/
|
2016-05-01 14:24:40 +03:00
|
|
|
printf "[Service]\nTimeoutStopSec=10" > $CACHEDIR/sdcard/etc/systemd/system/systemd-modules-load.service.d/10-timeout.conf
|
2016-01-31 15:05:17 +03:00
|
|
|
|
|
|
|
# handle PMU power button
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/udev/rules.d/
|
|
|
|
cp $SRC/lib/config/71-axp-power-button.rules $CACHEDIR/sdcard/etc/udev/rules.d/
|
2015-12-02 20:33:32 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
# Ubuntu Trusty
|
|
|
|
trusty)
|
|
|
|
# add serial console
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/config/ttyS0.conf $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
|
|
|
sed -e "s/ttyS0/$SERIALCON/g" -i $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
# don't clear screen tty1
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e s,"exec /sbin/getty","exec /sbin/getty --noclear",g -i $CACHEDIR/sdcard/etc/init/tty1.conf
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# disable some getties
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -f $CACHEDIR/sdcard/etc/init/tty5.conf
|
|
|
|
rm -f $CACHEDIR/sdcard/etc/init/tty6.conf
|
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# enable root login for latest ssh on trusty
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' $CACHEDIR/sdcard/etc/ssh/sshd_config
|
|
|
|
|
|
|
|
# fix selinux error
|
|
|
|
mkdir $CACHEDIR/sdcard/selinux
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
# that my custom motd works well
|
2016-04-29 12:54:41 +03:00
|
|
|
if [[ -d $CACHEDIR/sdcard/etc/update-motd.d ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
mv $CACHEDIR/sdcard/etc/update-motd.d $CACHEDIR/sdcard/etc/update-motd.d-backup
|
2015-12-02 20:33:32 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# auto upgrading
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e "s/ORIGIN/Ubuntu/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
sed -e "s/CODENAME/$RELEASE/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
# remove what's anyway not working
|
2016-04-29 12:54:41 +03:00
|
|
|
#chroot $CACHEDIR/sdcard /bin/bash -c "apt-get remove --auto-remove ureadahead"
|
2016-03-17 20:16:26 +01:00
|
|
|
rm $CACHEDIR/sdcard/etc/init/ureadahead*
|
|
|
|
rm $CACHEDIR/sdcard/etc/init/plymouth*
|
2015-12-02 20:33:32 +01:00
|
|
|
;;
|
|
|
|
|
2016-03-08 21:22:35 +03:00
|
|
|
xenial)
|
|
|
|
# enable root login for latest ssh on jessie
|
2016-04-05 16:04:48 +03:00
|
|
|
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' $CACHEDIR/sdcard/etc/ssh/sshd_config
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# auto upgrading (disabled while testing)
|
2016-03-17 20:16:26 +01:00
|
|
|
#sed -e "s/ORIGIN/Debian/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
|
|
|
#sed -e "s/CODENAME/$RELEASE/g" -i $CACHEDIR/sdcard/etc/apt/apt.conf.d/50unattended-upgrades
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# fix selinux error
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir $CACHEDIR/sdcard/selinux
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# add serial console (needs testing whether it's still needed)
|
2016-03-17 20:16:26 +01:00
|
|
|
#cp $SRC/lib/config/ttyS0.conf $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
|
|
|
#sed -e "s/ttyS0/$SERIALCON/g" -i $CACHEDIR/sdcard/etc/init/$SERIALCON.conf
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "systemctl --no-reload enable serial-getty@$SERIALCON.service >/dev/null 2>&1"
|
|
|
|
#mkdir -p "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d"
|
|
|
|
#echo "[Service]" > "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d/10-rate.conf"
|
|
|
|
#echo "ExecStart=" >> "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d/10-rate.conf"
|
|
|
|
#echo "ExecStart=-/sbin/agetty -L 115200 %I $TERM" >> "$CACHEDIR/sdcard/etc/systemd/system/serial-getty@$SERIALCON.service.d/10-rate.conf"
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# don't clear screen tty1
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p "$CACHEDIR/sdcard/etc/systemd/system/getty@tty1.service.d/"
|
2016-05-01 14:24:40 +03:00
|
|
|
printf "[Service]\nTTYVTDisallocate=no" > "$CACHEDIR/sdcard/etc/systemd/system/getty@tty1.service.d/10-noclear.conf"
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# seting timeout
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/systemd/system/systemd-modules-load.service.d/
|
2016-05-01 14:24:40 +03:00
|
|
|
printf "[Service]\nTimeoutStopSec=10" > $CACHEDIR/sdcard/etc/systemd/system/systemd-modules-load.service.d/10-timeout.conf
|
2016-03-08 21:22:35 +03:00
|
|
|
|
|
|
|
# handle PMU power button
|
2016-03-17 20:16:26 +01:00
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/udev/rules.d/
|
|
|
|
cp $SRC/lib/config/71-axp-power-button.rules $CACHEDIR/sdcard/etc/udev/rules.d/
|
2016-03-11 21:52:54 +03:00
|
|
|
|
|
|
|
# disable ureadahead
|
|
|
|
# needs kernel tracing options that AFAIK are present only in mainline TODO: fix later
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "systemctl --no-reload mask ureadahead.service >/dev/null 2>&1"
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "systemctl --no-reload mask setserial.service etc-setserial.service >/dev/null 2>&1"
|
2016-03-14 21:54:03 +03:00
|
|
|
|
2016-05-01 14:24:40 +03:00
|
|
|
# disable stopping network interfaces
|
|
|
|
# fixes shutdown with root on NFS
|
|
|
|
mkdir -p $CACHEDIR/sdcard/etc/systemd/system/networking.service.d/
|
|
|
|
printf "[Service]\nExecStop=\n" > $CACHEDIR/sdcard/etc/systemd/system/networking.service.d/10-nostop.conf
|
2016-03-08 21:22:35 +03:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
exit_with_error "Unknown OS release selected"
|
|
|
|
;;
|
2015-12-02 20:33:32 +01:00
|
|
|
esac
|
|
|
|
|
2015-12-19 13:01:14 +03:00
|
|
|
# copy hostapd configurations
|
2016-04-16 20:50:12 +02:00
|
|
|
install -m 755 $SRC/lib/config/hostapd/hostapd.conf $CACHEDIR/sdcard/etc/hostapd.conf
|
|
|
|
install -m 755 $SRC/lib/config/hostapd/hostapd.realtek.conf $CACHEDIR/sdcard/etc/hostapd.conf-rt
|
2015-12-19 13:01:14 +03:00
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
# console fix due to Debian bug
|
|
|
|
sed -e 's/CHARMAP=".*"/CHARMAP="'$CONSOLE_CHAR'"/g' -i $CACHEDIR/sdcard/etc/default/console-setup
|
2015-12-19 13:01:14 +03:00
|
|
|
|
|
|
|
# root-fs modifications
|
2016-03-17 20:16:26 +01:00
|
|
|
rm -f $CACHEDIR/sdcard/etc/motd
|
|
|
|
touch $CACHEDIR/sdcard/etc/motd
|
2015-12-19 13:01:14 +03:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# change time zone data
|
2016-03-17 20:16:26 +01:00
|
|
|
echo $TZDATA > $CACHEDIR/sdcard/etc/timezone
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg-reconfigure -f noninteractive tzdata >/dev/null 2>&1"
|
2015-12-02 20:33:32 +01:00
|
|
|
|
2016-03-17 20:16:26 +01:00
|
|
|
# set root password
|
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "(echo $ROOTPWD;echo $ROOTPWD;) | passwd root >/dev/null 2>&1"
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
# create proper fstab
|
2016-04-29 12:54:41 +03:00
|
|
|
if [[ $BOOTSIZE -eq 0 ]]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
local device="/dev/mmcblk0p1 / ext4 defaults,noatime,nodiratime,data=writeback,commit=600,errors=remount-ro"
|
|
|
|
else
|
2016-03-17 20:16:26 +01:00
|
|
|
local device="/dev/mmcblk0p2 / ext4 defaults,noatime,nodiratime,data=writeback,commit=600,errors=remount-ro"
|
2015-12-02 20:33:32 +01:00
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
echo "$device 0 0" >> $CACHEDIR/sdcard/etc/fstab
|
2015-12-02 20:33:32 +01:00
|
|
|
|
|
|
|
# flash media tunning
|
2016-04-29 12:54:41 +03:00
|
|
|
if [[ -f $CACHEDIR/sdcard/etc/default/tmpfs ]]; then
|
2016-03-17 20:16:26 +01:00
|
|
|
sed -e 's/#RAMTMP=no/RAMTMP=yes/g' -i $CACHEDIR/sdcard/etc/default/tmpfs
|
|
|
|
sed -e 's/#RUN_SIZE=10%/RUN_SIZE=128M/g' -i $CACHEDIR/sdcard/etc/default/tmpfs
|
|
|
|
sed -e 's/#LOCK_SIZE=/LOCK_SIZE=/g' -i $CACHEDIR/sdcard/etc/default/tmpfs
|
|
|
|
sed -e 's/#SHM_SIZE=/SHM_SIZE=128M/g' -i $CACHEDIR/sdcard/etc/default/tmpfs
|
|
|
|
sed -e 's/#TMP_SIZE=/TMP_SIZE=1G/g' -i $CACHEDIR/sdcard/etc/default/tmpfs
|
2015-12-02 20:33:32 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# add custom bashrc loading
|
2016-03-17 20:16:26 +01:00
|
|
|
cat <<END >> $CACHEDIR/sdcard/etc/bash.bashrc
|
2016-04-29 12:54:41 +03:00
|
|
|
if [[ -f /etc/bash.bashrc.custom ]]; then
|
2015-12-02 20:33:32 +01:00
|
|
|
. /etc/bash.bashrc.custom
|
|
|
|
fi
|
|
|
|
END
|
|
|
|
|
2016-01-21 21:49:11 +03:00
|
|
|
# display welcome message at first root login
|
2016-03-17 20:16:26 +01:00
|
|
|
touch $CACHEDIR/sdcard/root/.not_logged_in_yet
|
2016-01-21 21:49:11 +03:00
|
|
|
|
2016-03-13 13:10:45 +03:00
|
|
|
# force change root password at first login
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "chage -d 0 root"
|
2016-03-13 13:10:45 +03:00
|
|
|
|
2015-12-02 20:33:32 +01:00
|
|
|
# remove hostapd because it's replaced with ours
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "apt-get -y -qq remove hostapd >/dev/null 2>&1"
|
2016-02-26 12:30:06 +03:00
|
|
|
|
|
|
|
# install sunxi-tools
|
2016-03-17 20:16:26 +01:00
|
|
|
cp $SRC/lib/bin/sunxi-tools_1.3-1_armhf.deb $CACHEDIR/sdcard/tmp/
|
2016-02-26 12:30:06 +03:00
|
|
|
# libusb dependency should already be satisfied by usbutils
|
2016-03-17 20:16:26 +01:00
|
|
|
chroot $CACHEDIR/sdcard /bin/bash -c "dpkg -i /tmp/sunxi-tools_1.3-1_armhf.deb >/dev/null 2>&1"
|
2016-01-22 16:10:59 +07:00
|
|
|
}
|