1
|
#!/bin/bash
|
2
|
# Copyright (c) 2019 Marco Marinello <mmarinello@fuss.bz.it>
|
3
|
|
4
|
case $1 in
|
5
|
rootpw)
|
6
|
read -s -p "Clients password: " pw1
|
7
|
echo
|
8
|
read -s -p "Confirm clients password: " pw2
|
9
|
echo
|
10
|
|
11
|
if ! [ "$pw1" = "$pw2" ] ; then
|
12
|
echo "Password mismatch! Please retry"
|
13
|
else
|
14
|
perl -e "print crypt(\"$pw1\", \"salt\")" > $(cat /etc/fuss-fucc/sftpdir)/clientScripts/new_root_pw
|
15
|
fi
|
16
|
|
17
|
unset pw1
|
18
|
unset pw2
|
19
|
|
20
|
;;
|
21
|
octolist)
|
22
|
IMAGE="$2"
|
23
|
JOIN="join"
|
24
|
DB="/var/lib/octofuss/octofuss.db"
|
25
|
OUTFILE="$(cat /etc/fuss-fucc/sftpdir)/computerList.txt.octo-new"
|
26
|
|
27
|
rm -f ${OUTFILE}
|
28
|
touch ${OUTFILE}
|
29
|
|
30
|
PCS=$(sqlite3 $DB <<EOF
|
31
|
select distinct hostname from client_component;
|
32
|
.quit
|
33
|
EOF
|
34
|
)
|
35
|
|
36
|
for fqdn in $PCS; do
|
37
|
client=$(echo $fqdn | cut -d '.' -f 1)
|
38
|
# Check if the host has already been mapped
|
39
|
if ! grep $client ${OUTFILE} 2>&1 > /dev/null; then
|
40
|
# Find that MAC
|
41
|
MAC=$(sqlite3 $DB <<EOF
|
42
|
select value from client_component where hostname = "$fqdn" and component like "mac%";
|
43
|
.quit
|
44
|
EOF
|
45
|
)
|
46
|
MAC=$(echo $MAC|cut -d ' ' -f 1)
|
47
|
if [ -z "$MAC" ] ; then
|
48
|
echo "No mac for ${fqdn}"
|
49
|
else
|
50
|
if ! grep $MAC ${OUTFILE} 2>&1 > /dev/null ; then
|
51
|
THIS="$IMAGE"
|
52
|
echo $client $MAC $THIS $JOIN $(grep $client /etc/clusters | head -1 | cut -d ' ' -f 1) >> ${OUTFILE}
|
53
|
else
|
54
|
echo "$MAC has more than one fqdn (${fqdn})"
|
55
|
fi
|
56
|
fi
|
57
|
fi
|
58
|
done
|
59
|
|
60
|
;;
|
61
|
*)
|
62
|
echo "Usage: $0 [SUBCOMMAND]"
|
63
|
echo
|
64
|
echo -e "\trootpw\t\tGenerate and save the root\n\t\t\tpassword for the installed clients"
|
65
|
echo -e "\toctolist [image]\tGenerate the computerList.txt from\n\t\t\tthe OctoFuss database"
|
66
|
|
67
|
;;
|
68
|
esac
|