Commit f15b8a56 authored by Marco Marinello's avatar Marco Marinello

Porting of installFucc.sh to postinst

Signed-off-by: Marco Marinello's avatarMarco Marinello <mmarinello@sezf.it>
parent 361697fa
Pipeline #30 passed with stages
in 12 minutes and 10 seconds
#!/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
# 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
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"
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
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
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