#!/bin/bash # Debian containers only function create_container { echo -n "Enter the path of the container (including container root): " read -e CONTAINER_PATH echo -n "Enter debian release channel: " read CHANNEL echo -n "Enter (private) ssh key for git (absolute path): " read -e KEY echo -n "Start a ssh server? [y/n]: " read SSH_SERVER if [ "$SSH_SERVER" == "y" ];then echo -n "Enter ssh listening port: " read PORT fi echo -n "Add dotfiles? [y/n]: " read DOTFILES echo "Creating container.." debootstrap $CHANNEL $CONTAINER_PATH mkdir $CONTAINER_PATH/root/.bin/ echo "Copying key.." mkdir $CONTAINER_PATH/root/.ssh cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/ if [ "$SSH_SERVER" == "y" ] ;then systemd-nspawn -D $CONTAINER_PATH apt-get -y install ssh add_ssh $CONTAINER_PATH $PORT elif [ -z "$SSH_SERVER" ] ;then echo "Not creating a ssh server" fi echo "Installing vim & git" systemd-nspawn -D $CONTAINER_PATH apt-get -y install vim git echo "Starting container first time, enter root pass" systemd-nspawn -D $CONTAINER_PATH passwd if [ "$DOTFILES" == "y" ] ;then dotfiles $CONTAINER_PATH fi } function add_ssh { CONTAINER_PATH=$1 PORT=$2 echo "Editing ssh config" sed -i 's/^#Port .*/Port '"$PORT"'/' $CONTAINER_PATH/etc/ssh/sshd_config sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $CONTAINER_PATH/etc/ssh/sshd_config # Restart ssh in order to load changes systemd-nspawn -D $CONTAINER_PATH systemctl restart ssh } function dotfiles { CONTAINER_PATH=$1 systemd-nspawn -D $1 git clone https://www.github.com/SonnyBA/dotfiles.git $1/root/dotfiles systemd-nspawn -D $1 $1/root/dotfiles/initialize_script } create_container