39 lines
2.1 KiB
Text
39 lines
2.1 KiB
Text
|
#!/bin/bash
|
||
|
#option $1 is vm_list file name
|
||
|
#option $2 id DB location
|
||
|
#option $3 is DB user
|
||
|
#option $4 is DB name
|
||
|
|
||
|
host='localhost'
|
||
|
|
||
|
user_arr=( $(cat $1 | awk '{print $1}' ))
|
||
|
vmid_arr=( $(cat $1 | awk '{print $2}' ))
|
||
|
port_arr=( $(cat $1 | awk '{print $3}' ))
|
||
|
place_arr=( $(cat $1 | awk '{print $4}' ))
|
||
|
|
||
|
for ((i=0; i<${#user_arr[@]}; i++)) do
|
||
|
#create user
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_entity (name, type) VALUES ('${user_arr[i]}','USER');"
|
||
|
en_id=$(psql -h $2 -U $3 -d $4 -tAc "SELECT entity_id FROM guacamole_entity WHERE name = '${user_arr[i]}';")
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_user(entity_id, password_hash, password_date) VALUES ('$en_id', '\x74657374', now());"
|
||
|
|
||
|
#create connection
|
||
|
cn=${user_arr[i]}${vmid_arr[i]}
|
||
|
echo $cn
|
||
|
if [ 0 -eq $(psql -h $2 -U $3 -d $4 -tAc "SELECT connection_id FROM guacamole_connection WHERE connection_name = '$cn';" | wc -l) ]; then
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_connection (connection_name, protocol) VALUES ('$cn', 'vnc');"
|
||
|
cn_id=$(psql -h $2 -U $3 -d $4 -tAc "SELECT MAX(connection_id) FROM guacamole_connection WHERE connection_name = '$cn' AND parent_id IS NULL;")
|
||
|
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_connection_parameter VALUES ('$cn_id','hostname','$host');"
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_connection_parameter VALUES ('$cn_id','port','${port_arr[i]}');"
|
||
|
|
||
|
#connection permission
|
||
|
psql -h $2 -U $3 -d $4 -tAc "INSERT INTO guacamole_connection_permission(entity_id, connection_id, permission) VALUES ('$en_id', '$cn_id', 'READ');"
|
||
|
|
||
|
else
|
||
|
cn_id=$(psql -h $2 -U $3 -d $4 -tAc "SELECT MAX(connection_id) FROM guacamole_connection WHERE connection_name = '$cn' AND parent_id IS NULL;")
|
||
|
psql -h $2 -U $3 -d $4 -tAc "UPDATE guacamole_connection_parameter SET parameter_value='$host' where connection_id='$cn_id' and parameter_name='hostname';"
|
||
|
psql -h $2 -U $3 -d $4 -tAc "UPDATE guacamole_connection_parameter SET parameter_value='${port_arr[i]}' where connection_id='$cn_id' and parameter_name='port';"
|
||
|
fi
|
||
|
|
||
|
done
|