1 |
f15b8a56
|
Marco Marinello
|
#!/bin/bash
|
2 |
|
|
|
3 |
868afefa
|
Marco Marinello
|
CLONEZILLA_HOME=$(getent passwd clonezilla|cut -d : -f 6)
|
4 |
|
|
|
5 |
f0eeafca
|
Marco Marinello
|
#
|
6 |
|
|
# First of all, place the SSH configuration for clonezilla and root@proxy
|
7 |
|
|
#
|
8 |
|
|
|
9 |
868afefa
|
Marco Marinello
|
mkdir -p ${CLONEZILLA_HOME}/.ssh
|
10 |
f0eeafca
|
Marco Marinello
|
#rm -rf ${CLONEZILLA_HOME}/.ssh/*
|
11 |
868afefa
|
Marco Marinello
|
cp /usr/share/fuss-fucc/clonezilla_live.pub ${CLONEZILLA_HOME}/.ssh/authorized_keys
|
12 |
|
|
ssh-keyscan -H proxy > ${CLONEZILLA_HOME}/.ssh/known_hosts 2>/dev/null
|
13 |
f15b8a56
|
Marco Marinello
|
|
14 |
|
|
# Check if the SSH key already exists, if so check if is in authorized-keys
|
15 |
868afefa
|
Marco Marinello
|
if [ -e ${CLONEZILLA_HOME}/.ssh/id_rsa.pub ] ; then
|
16 |
|
|
if ! grep $(cat ${CLONEZILLA_HOME}/.ssh/id_rsa.pub|cut -d ' ' -f 2) /root/.ssh/authorized_keys 2>&1 > /dev/null ; then
|
17 |
|
|
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
|
18 |
f15b8a56
|
Marco Marinello
|
fi
|
19 |
|
|
else
|
20 |
|
|
# else, generate a new keypair and send it to root's authorized keys
|
21 |
868afefa
|
Marco Marinello
|
ssh-keygen -t rsa -N "" -f ${CLONEZILLA_HOME}/.ssh/id_rsa -C "root@fuss-fucc"
|
22 |
f15b8a56
|
Marco Marinello
|
touch /root/.ssh/authorized_keys
|
23 |
|
|
mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.old
|
24 |
|
|
grep -v "root@fuss-fucc" /root/.ssh/authorized_keys.old > /root/.ssh/authorized_keys
|
25 |
868afefa
|
Marco Marinello
|
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
|
26 |
f15b8a56
|
Marco Marinello
|
fi
|
27 |
|
|
|
28 |
868afefa
|
Marco Marinello
|
chown -R clonezilla. ${CLONEZILLA_HOME}/.ssh
|
29 |
|
|
chmod 400 ${CLONEZILLA_HOME}/.ssh/id_rsa*
|
30 |
f0eeafca
|
Marco Marinello
|
|
31 |
|
|
|
32 |
|
|
#
|
33 |
|
|
# Then get the SFTP directoty and copy the files
|
34 |
|
|
#
|
35 |
|
|
#DEBHELPER#
|
36 |
|
|
|
37 |
|
|
# Source debconf
|
38 |
|
|
. /usr/share/debconf/confmodule
|
39 |
|
|
|
40 |
|
|
# Get the directory
|
41 |
|
|
db_get fuss-fucc/sftp_directory
|
42 |
|
|
SFTPDIR="$RET"
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
# Fix the directory in pxelinux
|
46 |
|
|
sed -i "s+/srv/clonezilla+$SFTPDIR+g" /srv/tftp/pxelinux.cfg/default
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
# Copy required files
|
50 |
|
|
mkdir -p $SFTPDIR
|
51 |
|
|
cp -R /usr/share/fuss-fucc/clonezilla/clientScripts ${SFTPDIR}
|
52 |
|
|
test -e ${SFTPDIR}/computerList.txt || cp /usr/share/fuss-fucc/clonezilla/computerList.txt ${SFTPDIR}
|
53 |
dcf3e1a7
|
Paolo Dongilli
|
cp /usr/share/fuss-fucc/clonezilla/script ${SFTPDIR}
|
54 |
f0eeafca
|
Marco Marinello
|
|
55 |
|
|
chown -R clonezilla. ${SFTPDIR}/clientScripts
|
56 |
|
|
chmod -R 770 ${SFTPDIR}/clientScripts
|
57 |
|
|
chown clonezilla. ${SFTPDIR}/computerList.txt
|
58 |
dcf3e1a7
|
Paolo Dongilli
|
chown clonezilla. ${SFTPDIR}/script
|
59 |
|
|
chmod 770 ${SFTPDIR}/script
|
60 |
bb456d9f
|
Marco Marinello
|
|
61 |
|
|
mkdir -p /etc/fuss-fucc
|
62 |
|
|
echo $SFTPDIR > /etc/fuss-fucc/sftpdir
|