dotfiles/scripts/create_container
2017-06-17 18:35:23 +02:00

48 lines
1.2 KiB
Bash
Executable file

#!/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 "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/
echo -n "Start a ssh server? [y/n]: "
read SSH_SERVER
if [ "$SSH_SERVER" == "y" ] ;then
systemd-nspawn -D $CONTAINER_PATH apt-get install ssh
add_ssh $CONTAINER_PATH
elif [ -z "$SSH_SERVER" ] ;then
echo "Not creating a ssh server"
fi
echo "Installing vim & git"
systemd-nspawn -D $CONTAINER_PATH apt-get install vim git
echo "Starting container first time, enter root pass"
systemd-nspawn -D $CONTAINER_PATH passwd
}
function add_ssh {
echo -n "Enter ssh listening port: "
read PORT
echo "Editing ssh config"
# edit ssh config
sed -i 's/^#Port .*/Port '"$PORT"'/' $1/etc/ssh/sshd_config
sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $1/etc/ssh/sshd_config
}
create_container