Working version
This commit is contained in:
parent
2b9452cfa1
commit
ba6d92c8c2
1 changed files with 58 additions and 57 deletions
|
|
@ -1,68 +1,69 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Debian containers only
|
# 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
|
|
||||||
|
|
||||||
if [ "$DOTFILES" == "y" ] ;then
|
|
||||||
dotfiles $CONTAINER_PATH
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Starting container first time, enter root pass"
|
|
||||||
systemd-nspawn -D $CONTAINER_PATH passwd
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_ssh {
|
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/^#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
|
systemd-nspawn -D $CONTAINER_PATH systemctl restart ssh
|
||||||
}
|
}
|
||||||
|
|
||||||
function dotfiles {
|
function install_packages {
|
||||||
CONTAINER_PATH=$1
|
echo $PACKAGES
|
||||||
systemd-nspawn -D $1 git clone https://www.github.com/SonnyBA/dotfiles.git $1/root/dotfiles
|
systemd-nspawn -D $CONTAINER_PATH apt-get -y install $PACKAGES
|
||||||
systemd-nspawn -D $1 $1/root/dotfiles/initialize_script
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create_container
|
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): "
|
||||||
|
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 "Enter additional packages (space separated) to install or leave blank: "
|
||||||
|
read EXTRA
|
||||||
|
|
||||||
|
PACKAGES+=$EXTRA
|
||||||
|
|
||||||
|
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
|
||||||
|
PACKAGES+=" ssh"
|
||||||
|
echo $PACKAGES
|
||||||
|
install_packages $CONTAINER_PATH $PACKAGES
|
||||||
|
add_ssh $CONTAINER_PATH $PORT
|
||||||
|
else
|
||||||
|
install_packages $CONTAINER_PATH $PACKAGES
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$DOTFILES" == "y" ] ;then
|
||||||
|
dotfiles $CONTAINER_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Starting container first time, enter root pass"
|
||||||
|
systemd-nspawn -D $CONTAINER_PATH passwd
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue