#!/bin/bash ###################### # Debootstrap # ###################### set -e show_usage() { cat < $TARGET_DIR/etc/apt/sources.list deb http://ftp.fr.debian.org/debian $DEBIAN_RELEASE main contrib non-free deb http://security.debian.org/ $DEBIAN_RELEASE/updates main contrib non-free EOT cat < $TARGET_DIR/etc/apt/apt.conf.d/71-no-recommends APT::Install-Suggests "0"; EOT if [ ${APTCACHER} ] ; then cat < $TARGET_DIR/etc/apt/apt.conf.d/01proxy Acquire::http::Proxy "http://localhost:3142"; EOT fi chroot_deb $TARGET_DIR 'apt-get update' # Add usefull packages chroot_deb $TARGET_DIR "apt-get install -y --force-yes openssh-server ntp parted locales vim bash-completion rng-tools $PACKAGES" echo 'HRNGDEVICE=/dev/urandom' >> $TARGET_DIR/etc/default/rng-tools echo '. /etc/bash_completion' >> $TARGET_DIR/root/.bashrc # Use dhcp on boot cat < $TARGET_DIR/etc/network/interfaces auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp allow-hotplug usb0 iface usb0 inet dhcp EOT # Debootstrap optimisations from igorpecovnik # change default I/O scheduler, noop for flash media, deadline for SSD, cfq for mechanical drive cat <> $TARGET_DIR/etc/sysfs.conf block/mmcblk0/queue/scheduler = noop #block/sda/queue/scheduler = cfq EOT # flash media tunning if [ -f "$TARGET_DIR/etc/default/tmpfs" ]; then sed -e 's/#RAMTMP=no/RAMTMP=yes/g' -i $TARGET_DIR/etc/default/tmpfs sed -e 's/#RUN_SIZE=10%/RUN_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs sed -e 's/#LOCK_SIZE=/LOCK_SIZE=/g' -i $TARGET_DIR/etc/default/tmpfs sed -e 's/#SHM_SIZE=/SHM_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs sed -e 's/#TMP_SIZE=/TMP_SIZE=1G/g' -i $TARGET_DIR/etc/default/tmpfs fi # Generate locales sed -i "s/^# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen sed -i "s/^# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen chroot_deb $TARGET_DIR "locale-gen en_US.UTF-8" # Update timezone echo 'Europe/Paris' > $TARGET_DIR/etc/timezone chroot_deb $TARGET_DIR "dpkg-reconfigure -f noninteractive tzdata" if [ "$DEBIAN_RELEASE" = "jessie" ] ; then # Add fstab for root chroot_deb $TARGET_DIR "echo '/dev/mmcblk0 / ext4 defaults 0 1' >> /etc/fstab" # Configure tty install -m 755 -o root -g root ${REP}/config/ttyS0.conf $TARGET_DIR/etc/init/ttyS0.conf chroot_deb $TARGET_DIR 'cp /lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service' chroot_deb $TARGET_DIR 'sed -e s/"--keep-baud 115200,38400,9600"/"-L 115200"/g -i /etc/systemd/system/getty.target.wants/serial-getty@ttyS0.service' # specifics packets add and remove chroot_deb $TARGET_DIR "debconf-apt-progress -- apt-get -y install libnl-3-dev busybox-syslogd software-properties-common python-software-properties" chroot_deb $TARGET_DIR "apt-get -y remove rsyslog" # don't clear screen tty1 #chroot_deb $TARGET_DIR 'sed -e s,"TTYVTDisallocate=yes","TTYVTDisallocate=no",g -i /etc/systemd/system/getty.target.wants/getty@tty1.service' # enable root login for latest ssh on jessie chroot_deb $TARGET_DIR "sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config" else # Configure tty echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $TARGET_DIR/etc/inittab fi # Good right on some directories chroot_deb $TARGET_DIR 'chmod 1777 /tmp/' chroot_deb $TARGET_DIR 'chgrp mail /var/mail/' chroot_deb $TARGET_DIR 'chmod g+w /var/mail/' chroot_deb $TARGET_DIR 'chmod g+s /var/mail/' # Set hostname echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname # Add firstrun and secondrun init script install -m 755 -o root -g root ${REP}/script/secondrun $TARGET_DIR/etc/init.d/ install -m 755 -o root -g root ${REP}/script/firstrun $TARGET_DIR/etc/init.d/ chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null" if [ $INSTALL_KERNEL ] ; then cp ${INSTALL_KERNEL}/*.deb $TARGET_DIR/tmp/ chroot_deb $TARGET_DIR 'dpkg -i /tmp/*.deb' rm $TARGET_DIR/tmp/* cp ${INSTALL_KERNEL}/boot.scr $TARGET_DIR/boot/ chroot_deb $TARGET_DIR "ln -s /boot/dtb/$DTB /boot/board.dtb" fi if [ $INSTALL_YUNOHOST ] ; then chroot_deb $TARGET_DIR "apt-get install -y --force-yes git" chroot_deb $TARGET_DIR "git clone https://github.com/YunoHost/install_script /tmp/install_script" chroot_deb $TARGET_DIR "cd /tmp/install_script && ./autoinstall_yunohostv2 testing || exit 0" fi # Add 'olinux' for root password and force to change it at first login chroot_deb $TARGET_DIR '(echo olinux;echo olinux;) | passwd root' chroot_deb $TARGET_DIR 'chage -d 0 root' # Remove useless files chroot_deb $TARGET_DIR 'apt-get clean' rm $TARGET_DIR/etc/resolv.conf if [ ${CROSS} ] ; then rm $TARGET_DIR/usr/bin/qemu-arm-static fi if [ ${APTCACHER} ] ; then rm $TARGET_DIR/etc/apt/apt.conf.d/01proxy fi # Umount proc, sys, and dev umount -l $TARGET_DIR/dev/pts umount -l $TARGET_DIR/dev umount -l $TARGET_DIR/proc umount -l $TARGET_DIR/sys