Project

General

Profile

Download (2.5 KB) Statistics
| Branch: | Tag: | Revision:

fuss-fucc / debian / postinst @ master

1
#!/bin/bash
2

    
3
CLONEZILLA_HOME=$(getent passwd clonezilla|cut -d : -f 6)
4

    
5
#
6
# First of all, place the SSH configuration for clonezilla and root@proxy
7
#
8

    
9
mkdir -p ${CLONEZILLA_HOME}/.ssh
10
#rm -rf ${CLONEZILLA_HOME}/.ssh/*
11
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

    
14
# Check if the SSH key already exists, if so check if is in authorized-keys
15
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
	fi
19
else
20
	# else, generate a new keypair and send it to root's authorized keys
21
	ssh-keygen -t rsa -N "" -f ${CLONEZILLA_HOME}/.ssh/id_rsa -C "root@fuss-fucc"
22
	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
	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
fi
27

    
28
chown -R clonezilla. ${CLONEZILLA_HOME}/.ssh
29
chmod 400 ${CLONEZILLA_HOME}/.ssh/id_rsa*
30

    
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
cp /usr/share/fuss-fucc/clonezilla/script ${SFTPDIR}
54

    
55
chown -R clonezilla. ${SFTPDIR}/clientScripts
56
chmod -R 770 ${SFTPDIR}/clientScripts
57
chown clonezilla. ${SFTPDIR}/computerList.txt
58
chown clonezilla. ${SFTPDIR}/script
59
chmod 770 ${SFTPDIR}/script
60

    
61
mkdir -p /etc/fuss-fucc
62
echo $SFTPDIR > /etc/fuss-fucc/sftpdir
(7-7/11)