-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_rsync
executable file
·67 lines (57 loc) · 1.75 KB
/
install_rsync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Embedded rsync installation
#
# Version 0.2
# OLOC - 26/07/2013
Name=rsync
LogDir=/var/log
LogFile=${LogDir}/$(basename $0).$(date +%Y%m%d.%H%M%S).log
RunDir=/run
TmpDir=/tmp/${Name}
HomeDir=/home/${Name}
SshDir=${HomeDir}/.ssh
###################
# Functions
_echo() {
echo "$(date +%Y%m%d-%H%M%S) - $1" | tee -a ${LogFile}
}
_log() {
echo "$(date +%Y%m%d-%H%M%S) * $1" >> ${LogFile}
}
_log "${Name} - start."
_echo "Account creation in progress..."
useradd -m -s /bin/false ${Name}
_echo "Directories creation in progress..."
mkdir -p ${LogDir}/${Name}
chown ${Name}:${Name} ${LogDir}/${Name}
mkdir -p ${RunDir}/${Name}
chown ${Name}:${Name} ${RunDir}/${Name}
mkdir -p ${SshDir}
chown ${Name}:${Name} ${SshDir}
chmod 600 ${SshDir}
_echo "Script retrieve in progress..."
CurDir=$(pwd)
cd ${HomeDir}
wget -c http://olivierlocard.com/share/scripts/backup
chmod 750 ${HomeDir}/backup
chown ${Name}:${Name} ${HomeDir}/backup
_echo "Remote configuration in progress..."
echo -n "Remote Server:"
read RmtServer
echo -n "Remote User:"
read RmtUser
CfgFile=${HomeDir}/backup.conf
Key=${Name}-key
_echo "Configuration file creation in progress..."
echo "User=${RmtUser}" >> ${CfgFile}
echo "Server=${RmtServer}" >> ${CfgFile}
echo "Key=${SshDir}/${Key}" >> ${CfgFile}
_echo "SSH Key generation in progress..."
ssh-keygen -t rsa -b 2048 -f ${SshDir}/${Key} -C ${Name}@$(cat /etc/hostname)
chmod 600 ${SshDir}/${Key}*
chown ${Name}:${Name} ${SshDir}/${Key}*
_echo "Sending ${Key}.pub to ${RmtUser}@${RmtServer}..."
scp ${SshDir}/${Key}.pub ${RmtUser}@${RmtServer}:.ssh
_echo "Remote integration..."
ssh ${RmtUser}@${RmtServer} "cat ./.ssh/${Key}.pub >> ./.ssh/authorized_keys && chmod 600 ./.ssh/authorized_keys && rm ./.ssh/${Key}.pub"
cd ${CurDir}
_log "${Name} - End."