From 8700c67a66b635efbf913ab5409178f41175095d Mon Sep 17 00:00:00 2001 From: Valentin <43043885+itsmrval@users.noreply.github.com> Date: Thu, 14 Sep 2023 23:35:34 +0200 Subject: [PATCH] fix --- update.sh | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/update.sh b/update.sh index 04da579..d053d61 100644 --- a/update.sh +++ b/update.sh @@ -2,36 +2,37 @@ . /opt/accessgate_agent/config.txt -if [ $user == "accessgatemultiuser"] +if [ "$user" = "accessgatemultiuser" ] then - tmp_file=/opt/accessgate_agent/tmp_user.txt - old_file=/opt/accessgate_agent/old_user.txt - isDifferent=false - curl -o $tmp_file -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/users - [[ -f filename ]] || touch $old_file - cmp --silent $old_file $tmp_file || isDifferent=true + tmp_file=/opt/accessgate_agent/tmp_user.txt + old_file=/opt/accessgate_agent/old_user.txt + isDifferent=false + curl -o $tmp_file -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/users + [[ -f filename ]] || touch $old_file + cmp --silent $old_file $tmp_file || isDifferent=true - for x in $(head $tmp_file) - do + if [ isDifferent = "true" ] + then + for x in $(head $old_file) + do + rm /home/$x/.ssh/authorized_keys + done + fi - userPath=$x - echo $x - if [ $x != "root" ] - then - userPath=home/$x - fi - mkdir -p $userPath/.ssh - curl -o $userPath/.ssh -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/key/$x - done + for x in $(head $tmp_file) + do + mkdir -p /home/$x/.ssh + curl -o /home/$x/.ssh/authorized_keys -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/key/$x + done + mv $tmp_file $old_file else - if [ $user != "root" ] - then - userPath=home/$x - fi - mkdir -p $userPath/.ssh - curl -o $userPath/.ssh -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/allKeys + if [ $user != "root" ] + then + userPath=home/$x + fi + mkdir -p /$user + mkdir -p /$user/.ssh/ + curl -o /$user/.ssh/authorized_keys -X GET -H 'Content-Type: application/json' -d '{"secret": "'$secret'"}' $url/endpoint/update/$server/allKeys fi - -mv $tmp_file $old_file