#!/bin/bash set -e mirror=http://ftp.md.debian.org/debian/ zone=Europe/Moscow # guest = release as arg echo function template_ready { echo -n clean-up host keys ... rm -f lala/etc/ssh/ssh_host_* && echo done #dpkg-reconfigure openssh-server echo -n generating edwards host key ... ssh-keygen -f lala/etc/ssh/ssh_host_ed25519_key -t ed25519 -N '' -C "$guest" && echo done echo -n indexing ... chroot lala/ bash -c "updatedb" && echo done echo -n clean-up shell history ... chroot lala/ bash -c "history -c" rm -f lala/root/.bash_history && echo done echo -n un-mounting ... umount -R lala/ && echo done rmdir lala/ } function setup_network { echo -n setting up host name ... echo $guest > lala/etc/hostname && echo done echo -n setting up static names ... cat > lala/etc/hosts < lala/etc/network/interfaces <> lala/etc/resolv.conf && echo dns $entry done; unset entry } function setup_repo { echo -n setting up debian mirror ... # syntax differs a little bit for buster, on the security repo if [[ $guest = buster ]]; then cat > lala/etc/apt/sources.list < lala/etc/apt/sources.list < prep.log && echo done echo -n fixup locale - prep.log ... chroot lala/ bash -c "apt-get -qy install locales" >> prep.log echo -n setting up en_US.UTF-8 locale ... chroot lala/ bash -c "dpkg-reconfigure locales" echo -n checking locale ... chroot lala/ bash -c "perl -e exit" && echo done echo -n installing additional packages - prep.log ... chroot lala/ bash -c "apt-get -qy install \ ifupdown \ net-tools \ man-db \ manpages \ openssh-server \ openssh-client \ mlocate \ netcat-openbsd \ nmap \ wget \ elvis-tiny \ bash-completion" >> prep.log && echo done echo -n default shell ... chroot lala/ bash -c "useradd -D -s /bin/bash" && echo done echo -n setting up shell env ... [[ -f lala/etc/bash.bashrc.dist ]] && echo already && return cp -pi lala/etc/bash.bashrc lala/etc/bash.bashrc.dist cat >> lala/etc/bash.bashrc < lala/etc/timezone && echo done # TODO w/o password echo -n unlocking root user ... chroot lala/ bash -c "passwd -d root" && echo done echo -n setting up default init ... chroot lala/ systemctl bash -c "set-default multi-user" && echo done } [[ -z $1 ]] && echo ${0##*/} GUEST-NAME && exit 1 guest=$1 [[ ! -f network.conf ]] && define ip gw dns in network.conf && exit 1 source network.conf [[ -z $ip ]] && echo \$ip not defined && exit 1 [[ -z $gw]] && echo \$gw not defined && exit 1 [[ -z $dns]] && echo \$dns not defined && exit 1 [[ ! -d lala/ ]] && echo expecting lala/ folder && exit 1 [[ -z `mount | grep $guest | grep lala` ]] && echo expecting mounted lala/ folder && exit 1 setup_network setup_repo echo setup_env echo template_ready echo echo all done echo