container script changes

This commit is contained in:
Sonny Bakker 2017-07-08 21:30:16 +02:00
parent c896a73fbc
commit 376174ecc2
2 changed files with 49 additions and 38 deletions

View file

@ -1,64 +1,75 @@
#!/bin/bash #!/bin/bash
# Debian containers only # Debian containers only
function add_ssh { PACKAGES="vim git dbus "
REPO=https://github.com/SonnyBA/dotfiles.git
run() {
systemd-nspawn -D $CONTAINER_PATH $@
}
add_ssh() {
sed -i 's/^#Port .*/Port '"$PORT"'/' $CONTAINER_PATH/etc/ssh/sshd_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 sed -i 's/^#PermitRootLogin .*/PermitRootLogin yes/' $CONTAINER_PATH/etc/ssh/sshd_config
# Restart ssh in order to load changes # Restart ssh in order to load changes
systemd-nspawn -D $CONTAINER_PATH systemctl restart ssh run systemctl restart ssh
touch $CONTAINER_PATH/root/.bash_profile
cat $CONTAINER_PATH/root/.bash_profile <<EOF
# Start ssh-agent and add keys in ~/.ssh directory
# Should only be used without a desktop manager
ENV=/tmp/.agent_env
KEYS=$(basename --suffix=.pub -a $HOME/.ssh/*.pub)
if [ -z "$SSH_AGENT_PID" ] && [ ! -e "$ENV" ] ; then
ssh-agent > $ENV
source $ENV
for key in $KEYS;
do
ssh-add ~/.ssh/$key
done
echo 'Agent started'
else
source $ENV
echo 'Agent started already, good to go'
fi
EOF
} }
function install_packages { dotfiles() {
echo $PACKAGES run git clone $REPO $CONTAINER_PATH/root/dotfiles
systemd-nspawn -D $CONTAINER_PATH apt-get -y install $PACKAGES run $CONTAINER_PATH/root/dotfiles/initialize_script
} }
function dotfiles { read -e -p "Enter the path of the container (including container root): " CONTAINER_PATH
systemd-nspawn -D $CONTAINER_PATH git clone https://www.github.com/SonnyBA/dotfiles.git $CONTAINER_PATH/root/dotfiles read -p "Enter debian release channel: " CHANNEL
systemd-nspawn -D $CONTAINER_PATH $CONTAINER_PATH/root/dotfiles/initialize_script read -e -p "Enter (private) ssh key for git (absolute path): " KEY
} read -p "Start a ssh server? [y/n]: " SSH_SERVER
PACKAGES="vim git "
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 if [ "$SSH_SERVER" == "y" ];then
echo -n "Enter ssh listening port: " read -p "Enter ssh listening port: " PORT
read PORT PACKAGES+=" ssh "
fi fi
echo "Enter additional packages (space separated) to install or leave blank: " echo "Current packages: $PACKAGES"
read EXTRA read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA
PACKAGES+=$EXTRA PACKAGES+=$EXTRA
echo -n "Add dotfiles? [y/n]: " # Seperate packages with a comma for debootstrap's include flag
read DOTFILES PACKAGES=$(echo $PACKAGES | sed 's/\ /,/g;s/,$//')
read -p "Add dotfiles? [y/n]: " DOTFILES
echo "Creating container.." echo "Creating container.."
debootstrap $CHANNEL $CONTAINER_PATH debootstrap --include=$PACKAGES $CHANNEL $CONTAINER_PATH
mkdir $CONTAINER_PATH/root/.bin/ mkdir $CONTAINER_PATH/root/.bin/
echo "Copying key.." echo "Copying key.."
mkdir $CONTAINER_PATH/root/.ssh mkdir $CONTAINER_PATH/root/.ssh
cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/ cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/
if [ "$SSH_SERVER" == "y" ] ;then if [ "$SSH_SERVER" == "y" ] ;then
PACKAGES+=" ssh"
echo $PACKAGES
install_packages $CONTAINER_PATH $PACKAGES
add_ssh $CONTAINER_PATH $PORT add_ssh $CONTAINER_PATH $PORT
else
install_packages $CONTAINER_PATH $PACKAGES
fi fi
if [ "$DOTFILES" == "y" ] ;then if [ "$DOTFILES" == "y" ] ;then
@ -66,4 +77,4 @@ if [ "$DOTFILES" == "y" ] ;then
fi fi
echo "Starting container first time, enter root pass" echo "Starting container first time, enter root pass"
systemd-nspawn -D $CONTAINER_PATH passwd run passwd

View file

@ -45,7 +45,7 @@ set backspace=2
set t_ut= set t_ut=
" Light colorscheme by default " Light colorscheme by default
colorscheme greygull colorscheme seagull
" Terminal colors " Terminal colors
set termguicolors set termguicolors