Commit 868afefa authored by Marco Marinello's avatar Marco Marinello

Variabilize clonezilla home

Signed-off-by: Marco Marinello's avatarMarco Marinello <mmarinello@sezf.it>
parent 1e1763b0
#!/bin/bash
mkdir -p /srv/clonezilla/.ssh
rm -rf /srv/clonezilla/.ssh/*
cp /usr/share/fuss-fucc/clonezilla_live.pub /srv/clonezilla/.ssh/authorized_keys
ssh-keyscan -H proxy > /srv/clonezilla/.ssh/known_hosts 2>/dev/null
CLONEZILLA_HOME=$(getent passwd clonezilla|cut -d : -f 6)
mkdir -p ${CLONEZILLA_HOME}/.ssh
rm -rf ${CLONEZILLA_HOME}/.ssh/*
cp /usr/share/fuss-fucc/clonezilla_live.pub ${CLONEZILLA_HOME}/.ssh/authorized_keys
ssh-keyscan -H proxy > ${CLONEZILLA_HOME}/.ssh/known_hosts 2>/dev/null
# Check if the SSH key already exists, if so check if is in authorized-keys
if [ -e /srv/clonezilla/.ssh/id_rsa.pub ] ; then
if ! grep $(cat /srv/clonezilla/.ssh/id_rsa.pub|cut -d ' ' -f 2) /root/.ssh/authorized_keys 2>&1 > /dev/null ; then
echo 'command="if [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^scp[[:space:]]-f ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^add_client_principal ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ rm[[:space:]]/root/ ]]; then $SSH_ORIGINAL_COMMAND; else echo \"Access Denied $SSH_ORIGINAL_COMMAND\"; fi"' $(cat /srv/clonezilla/.ssh/id_rsa.pub) >> /root/.ssh/authorized_keys
if [ -e ${CLONEZILLA_HOME}/.ssh/id_rsa.pub ] ; then
if ! grep $(cat ${CLONEZILLA_HOME}/.ssh/id_rsa.pub|cut -d ' ' -f 2) /root/.ssh/authorized_keys 2>&1 > /dev/null ; then
echo 'command="if [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^scp[[:space:]]-f ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^add_client_principal ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ rm[[:space:]]/root/ ]]; then $SSH_ORIGINAL_COMMAND; else echo \"Access Denied $SSH_ORIGINAL_COMMAND\"; fi"' $(cat ${CLONEZILLA_HOME}/.ssh/id_rsa.pub) >> /root/.ssh/authorized_keys
fi
else
# else, generate a new keypair and send it to root's authorized keys
ssh-keygen -t rsa -N "" -f /srv/clonezilla/.ssh/id_rsa -C "root@fuss-fucc"
ssh-keygen -t rsa -N "" -f ${CLONEZILLA_HOME}/.ssh/id_rsa -C "root@fuss-fucc"
touch /root/.ssh/authorized_keys
mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.old
grep -v "root@fuss-fucc" /root/.ssh/authorized_keys.old > /root/.ssh/authorized_keys
echo 'command="if [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^scp[[:space:]]-f ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^add_client_principal ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ rm[[:space:]]/root/ ]]; then $SSH_ORIGINAL_COMMAND; else echo \"Access Denied $SSH_ORIGINAL_COMMAND\"; fi"' $(cat /srv/clonezilla/.ssh/id_rsa.pub) >> /root/.ssh/authorized_keys
echo 'command="if [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^scp[[:space:]]-f ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ ^add_client_principal ]] || [[ \"$SSH_ORIGINAL_COMMAND\" =~ rm[[:space:]]/root/ ]]; then $SSH_ORIGINAL_COMMAND; else echo \"Access Denied $SSH_ORIGINAL_COMMAND\"; fi"' $(cat ${CLONEZILLA_HOME}/.ssh/id_rsa.pub) >> /root/.ssh/authorized_keys
fi
chown -R clonezilla. /srv/clonezilla/.ssh
chmod 400 /srv/clonezilla/.ssh/id_rsa*
chown -R clonezilla. /srv/clonezilla/clientScripts
chmod -R 770 /srv/clonezilla/clientScripts
chown clonezilla. /srv/clonezilla/computerList.txt
chown -R clonezilla. ${CLONEZILLA_HOME}/.ssh
chmod 400 ${CLONEZILLA_HOME}/.ssh/id_rsa*
chown -R clonezilla. ${CLONEZILLA_HOME}/clientScripts
chmod -R 770 ${CLONEZILLA_HOME}/clientScripts
chown clonezilla. ${CLONEZILLA_HOME}/computerList.txt
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment