Skip to content

Commit

Permalink
shell format
Browse files Browse the repository at this point in the history
Change-Id: I9e2436aeaa61c594932112a6a1bc203cdc768095
  • Loading branch information
LarsMichelsen committed Nov 29, 2019
1 parent d5afba6 commit 8801ee2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions agents/windows/setup-ssh
Expand Up @@ -4,7 +4,7 @@

set -ex

if [[ -z $CHROOT_PATH ]] ; then
if [[ -z $CHROOT_PATH ]]; then
echo "CHROOT_PATH is not set"
exit 1
fi
Expand All @@ -14,25 +14,24 @@ ssh_key=id_rsa_windows_test
remote_ip=$(grep "remote_ip =" $script_dir/it/remote.py | sed "s/^.*'\(.*\)'/\1/g")
remoteuser=$(grep "remoteuser =" $script_dir/it/remote.py | sed "s/^.*'\(.*\)'/\1/g")

if [[ $SUDO_USER == jenkins ]] ; then
if [[ $SUDO_USER == jenkins ]]; then
home_dir=/var/lib/jenkins
else
home_dir=/home/$SUDO_USER
fi

if [[ ! -f "$home_dir/.ssh/$ssh_key" ]] || [[ ! -f "$home_dir/.ssh/${ssh_key}.pub" ]] ; then
if [[ ! -f "$home_dir/.ssh/$ssh_key" ]] || [[ ! -f "$home_dir/.ssh/${ssh_key}.pub" ]]; then
echo "SSH key pair '$ssh_key' not found. Please generate a new key pair with the command"
echo "ssh-keygen -t rsa -N '' -C '$SUDO_USER@$HOSTNAME (Windows test)' -f $home_dir/.ssh/$ssh_key"
echo "and append the public key to \\Users\\$remoteuser\\.ssh\\authorized_keys at host $remote_ip"
exit 1
fi

if [[ ! -d "$CHROOT_PATH/home/$SUDO_USER/.ssh" ]] ; then
if [[ ! -d "$CHROOT_PATH/home/$SUDO_USER/.ssh" ]]; then
su - $SUDO_USER -c bash -c "mkdir -p $CHROOT_PATH/home/$SUDO_USER/.ssh"
fi

for ending in "" ".pub"; do
cp "$home_dir/.ssh/${ssh_key}${ending}" "$CHROOT_PATH/home/$SUDO_USER/.ssh/id_rsa${ending}"
chown $SUDO_USER:$SUDO_USER "$CHROOT_PATH/home/$SUDO_USER/.ssh/id_rsa${ending}"
done

0 comments on commit 8801ee2

Please sign in to comment.