62 lines
1.5 KiB
Bash
Executable file
62 lines
1.5 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
|
|
|
|
dotfiles $CONTAINER_PATH
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
function dotfiles {
|
|
echo -n "Add dotfiles? [y/n]: "
|
|
read DOTFILES
|
|
|
|
if [ "$DOTFILES" == "y" ] ;then
|
|
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
|
|
elif [ -z "$SSH_SERVER" ] ;then
|
|
echo "Not cloning anything"
|
|
fi
|
|
}
|
|
|
|
create_container
|