Qemu script deletion & container script update
- container script checks for sudo & adds optionally adds entry to users' ssh config - initialize script checks for sudo priveliges like the container script - Removal of qemu scripts
This commit is contained in:
parent
2a49f4a4df
commit
8ae037cd30
13 changed files with 56 additions and 128 deletions
|
|
@ -4,6 +4,12 @@
|
|||
PACKAGES="ca-certificates vim git dbus "
|
||||
REPO=https://github.com/SonnyBA/dotfiles.git
|
||||
|
||||
if [ $EUID != 0 ]; then
|
||||
echo "This script needs sudo priveleges (for systemd-nspawn)"
|
||||
echo "Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
run() {
|
||||
systemd-nspawn -D $CONTAINER_PATH $@
|
||||
}
|
||||
|
|
@ -12,23 +18,24 @@ 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
|
||||
|
||||
touch $CONTAINER_PATH/root/.bash_profile
|
||||
cat <<- 'EOF' > $CONTAINER_PATH/root/.bash_profile
|
||||
# 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
|
||||
# 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
|
||||
}
|
||||
|
||||
|
|
@ -41,30 +48,30 @@ read -e -p "Enter the path of the container (including container root): " CONTA
|
|||
read -p "Enter debian release channel: " CHANNEL
|
||||
read -e -p "Enter (private) ssh key for git (absolute path): " KEY
|
||||
read -p "Start a ssh server? [y/n]: " SSH_SERVER
|
||||
read -p "Hostname? : " HOSTNAME
|
||||
read -p "Add dotfiles? [y/n]: " DOTFILES
|
||||
read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA
|
||||
read -p "Append container to ssh user config? [y/n]: " USER_CONFIG
|
||||
|
||||
if [ "$SSH_SERVER" == "y" ];then
|
||||
read -p "Enter ssh listening port: " PORT
|
||||
PACKAGES+=" ssh "
|
||||
fi
|
||||
|
||||
echo "Current packages: $PACKAGES"
|
||||
read -p "Enter additional packages (space separated) to install or leave blank: " EXTRA
|
||||
|
||||
PACKAGES+=$EXTRA
|
||||
|
||||
# Seperate packages with a comma for debootstrap's include flag
|
||||
PACKAGES=$(echo $PACKAGES | sed 's/\ /,/g;s/,$//')
|
||||
|
||||
read -p "Add dotfiles? [y/n]: " DOTFILES
|
||||
|
||||
echo "Creating container.."
|
||||
debootstrap --include=$PACKAGES $CHANNEL $CONTAINER_PATH
|
||||
mkdir $CONTAINER_PATH/root/.bin/
|
||||
|
||||
echo "Copying key.."
|
||||
mkdir $CONTAINER_PATH/root/.bin/
|
||||
mkdir $CONTAINER_PATH/root/.ssh
|
||||
cp $KEY $KEY.pub $CONTAINER_PATH/root/.ssh/
|
||||
|
||||
if [ -n "$HOSTNAME" ] ;then
|
||||
echo $HOSTNAME > $CONTAINER_PATH/etc/hostname
|
||||
fi
|
||||
|
||||
if [ "$SSH_SERVER" == "y" ] ;then
|
||||
add_ssh
|
||||
fi
|
||||
|
|
@ -73,5 +80,22 @@ if [ "$DOTFILES" == "y" ] ;then
|
|||
dotfiles
|
||||
fi
|
||||
|
||||
if [ "$USER_CONFIG" == "y" ]; then
|
||||
cat <<- EOF >> /home/$SUDO_USER/.ssh/config
|
||||
|
||||
Host $HOSTNAME
|
||||
User root
|
||||
Hostname 127.0.0.1
|
||||
Port $PORT
|
||||
EOF
|
||||
# Remove leading whitespace
|
||||
sed -i 's/^ *//g' /home/$SUDO_USER/.ssh/config
|
||||
fi
|
||||
|
||||
echo "Enter root pass"
|
||||
run passwd
|
||||
|
||||
CONTAINER_NAME=$(basename $CONTAINER_PATH)
|
||||
|
||||
echo "Container finished setting up, use ssh $HOSTNAME after starting the machine" \
|
||||
"with machinectl start $CONTAINER_NAME"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue