Working version

This commit is contained in:
Sonny 2017-06-19 21:29:29 +02:00
parent 2b9452cfa1
commit ba6d92c8c2

View file

@ -1,6 +1,23 @@
#!/bin/bash #!/bin/bash
# Debian containers only # Debian containers only
function create_container { function add_ssh {
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 install_packages {
echo $PACKAGES
systemd-nspawn -D $CONTAINER_PATH apt-get -y install $PACKAGES
}
function dotfiles {
systemd-nspawn -D $CONTAINER_PATH git clone https://www.github.com/SonnyBA/dotfiles.git $CONTAINER_PATH/root/dotfiles
systemd-nspawn -D $CONTAINER_PATH $CONTAINER_PATH/root/dotfiles/initialize_script
}
PACKAGES="vim git "
echo -n "Enter the path of the container (including container root): " echo -n "Enter the path of the container (including container root): "
read -e CONTAINER_PATH read -e CONTAINER_PATH
@ -18,6 +35,11 @@ function create_container {
read PORT read PORT
fi fi
echo "Enter additional packages (space separated) to install or leave blank: "
read EXTRA
PACKAGES+=$EXTRA
echo -n "Add dotfiles? [y/n]: " echo -n "Add dotfiles? [y/n]: "
read DOTFILES read DOTFILES
@ -31,38 +53,17 @@ function create_container {
if [ "$SSH_SERVER" == "y" ] ;then if [ "$SSH_SERVER" == "y" ] ;then
systemd-nspawn -D $CONTAINER_PATH apt-get -y install ssh PACKAGES+=" ssh"
echo $PACKAGES
install_packages $CONTAINER_PATH $PACKAGES
add_ssh $CONTAINER_PATH $PORT add_ssh $CONTAINER_PATH $PORT
elif [ -z "$SSH_SERVER" ] ;then else
echo "Not creating a ssh server" install_packages $CONTAINER_PATH $PACKAGES
fi fi
echo "Installing vim & git"
systemd-nspawn -D $CONTAINER_PATH apt-get -y install vim git
if [ "$DOTFILES" == "y" ] ;then if [ "$DOTFILES" == "y" ] ;then
dotfiles $CONTAINER_PATH dotfiles $CONTAINER_PATH
fi fi
echo "Starting container first time, enter root pass" echo "Starting container first time, enter root pass"
systemd-nspawn -D $CONTAINER_PATH passwd systemd-nspawn -D $CONTAINER_PATH passwd
}
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