Spaces:
Sleeping
Sleeping
oxmraz-mldo24
commited on
Commit
·
52d92f0
1
Parent(s):
a8cfc9f
Create setupaccess.yml
Browse files- .github/workflows/setupaccess.yml +25 -0
- setupaccess.exp +7 -2
- setupaccess.sh +21 -3
.github/workflows/setupaccess.yml
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Setup Access
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
workflow_dispatch: # Manual trigger
|
| 5 |
+
|
| 6 |
+
jobs:
|
| 7 |
+
deploy:
|
| 8 |
+
runs-on: ubuntu-latest
|
| 9 |
+
|
| 10 |
+
steps:
|
| 11 |
+
- name: Checkout Repository
|
| 12 |
+
uses: actions/checkout@v3
|
| 13 |
+
|
| 14 |
+
- name: Install expect
|
| 15 |
+
run: sudo apt-get install expect
|
| 16 |
+
|
| 17 |
+
- name: Add permission for script to run
|
| 18 |
+
run: chmod +x setupaccess.sh
|
| 19 |
+
|
| 20 |
+
- name: Run Bash Scripts
|
| 21 |
+
env:
|
| 22 |
+
PASSPHRASE_GROUP17: ${{ secrets.PASSPHRASE_GROUP17 }}
|
| 23 |
+
GROUP17_PUBLICKKEY: ${{ secrets.GROUP17_PUBLICKKEY }}
|
| 24 |
+
GROUP17_PRIVATEKEY: ${{ secrets.GROUP17_PRIVATEKEY }}
|
| 25 |
+
run: expect setupaccess.exp "$PASSPHRASE_GROUP17" # this one has code triggering setupaccess.sh, so command ultimately runs multiple scripts :)
|
setupaccess.exp
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
#!/usr/bin/expect -f
|
|
|
|
| 2 |
spawn ./setupaccess.sh
|
| 3 |
-
set timeout
|
|
|
|
|
|
|
| 4 |
expect "Enter passphrase for key 'group17':\r"
|
| 5 |
send "$PASSPHRASE_GROUP17\r"
|
| 6 |
expect "Enter passphrase for key 'group17':\r"
|
| 7 |
send "$PASSPHRASE_GROUP17\r"
|
| 8 |
-
expect
|
|
|
|
|
|
|
|
|
| 1 |
#!/usr/bin/expect -f
|
| 2 |
+
set PASSPHRASE_GROUP17 [lindex $argv 0]
|
| 3 |
spawn ./setupaccess.sh
|
| 4 |
+
set timeout 5
|
| 5 |
+
expect "The authenticity of host"
|
| 6 |
+
send "yes\r"
|
| 7 |
expect "Enter passphrase for key 'group17':\r"
|
| 8 |
send "$PASSPHRASE_GROUP17\r"
|
| 9 |
expect "Enter passphrase for key 'group17':\r"
|
| 10 |
send "$PASSPHRASE_GROUP17\r"
|
| 11 |
+
expect "Enter passphrase for key 'group17':\r"
|
| 12 |
+
send "$PASSPHRASE_GROUP17\r"
|
| 13 |
+
expect eof
|
setupaccess.sh
CHANGED
|
@@ -17,11 +17,29 @@ echo "setupaccess.sh: remove known host keys for the server to avoid the REMOTE
|
|
| 17 |
cat group17.pub > authorized_keys
|
| 18 |
echo "setupaccess.sh: make an authorized_keys file with group17.pub as an authorized key"
|
| 19 |
|
| 20 |
-
|
| 21 |
-
echo "setupaccess.sh:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
rm authorized_keys
|
| 24 |
echo "setupaccess.sh: remove authorized_keys file from host"
|
| 25 |
|
| 26 |
ssh -p 22017 -i group17 -o StrictHostKeyChecking=no [email protected]
|
| 27 |
-
echo "setupaccess.sh: try to ssh in"
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
cat group17.pub > authorized_keys
|
| 18 |
echo "setupaccess.sh: make an authorized_keys file with group17.pub as an authorized key"
|
| 19 |
|
| 20 |
+
rm group17.pub
|
| 21 |
+
echo "setupaccess.sh: remove group17.pub file from host"
|
| 22 |
+
|
| 23 |
+
scpOutput=$(scp -o StrictHostKeyChecking=no -i group17 -P 22017 authorized_keys [email protected]:/home/student-admin/.ssh 2>&1)
|
| 24 |
+
echo "setupaccess.sh: try to copy authorized_keys file to server"
|
| 25 |
+
|
| 26 |
+
if [[ "$scpOutput" = *"[email protected]: Permission denied (publickey)."* ]];
|
| 27 |
+
then touch student-admin_key
|
| 28 |
+
echo "$STUDENT_ADMIN_KEY" > student-admin_key
|
| 29 |
+
echo "setupaccess.sh: make student-admin_key file"
|
| 30 |
+
scp -o StrictHostKeyChecking=no -i student-admin_key -P 22017 authorized_keys [email protected]:/home/student-admin/.ssh
|
| 31 |
+
echo "setupaccess.sh: copied authorized_keys file to server with student-admin_key"
|
| 32 |
+
rm student-admin_key
|
| 33 |
+
echo "setupaccess.sh: remove student-admin_key from host"
|
| 34 |
+
else
|
| 35 |
+
echo "setupaccess.sh: copied authorized_keys file to server with our private key"
|
| 36 |
+
fi
|
| 37 |
|
| 38 |
rm authorized_keys
|
| 39 |
echo "setupaccess.sh: remove authorized_keys file from host"
|
| 40 |
|
| 41 |
ssh -p 22017 -i group17 -o StrictHostKeyChecking=no [email protected]
|
| 42 |
+
echo "setupaccess.sh: try to ssh in"
|
| 43 |
+
|
| 44 |
+
rm group17
|
| 45 |
+
echo "setupaccess.sh: remove group17 file from host"
|