From 2cbd0fc146a4658bf0a430a9fe0f2d257b0a0423 Mon Sep 17 00:00:00 2001 From: sose Date: Fri, 11 Sep 2020 16:04:08 -0700 Subject: [PATCH] refactored keyfile location --- connection.sh | 35 +++++++++-------------------------- setup.sh | 24 +++++++++++++++++------- util.sh | 13 +++++++++++++ 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/connection.sh b/connection.sh index 00186c6..b4c0aae 100755 --- a/connection.sh +++ b/connection.sh @@ -1,39 +1,22 @@ #!/bin/sh connection_test() { - ssh_command="$1" + key_file="$1" + tilde_username="$2" + tilde_name="$3" + + ssh_command="ssh -i $key_file $tilde_username@$tilde_name" + + echo "Running \`$ssh_command\`..." while ! $ssh_command 'exit' do echo "There seems to be a problem connecting to the tilde" echo "Use this shell to try and fix any problems, then try connecting again by exiting the shell" - bash + echo "Use \`exit 1\` to abort the install" + bash || fail done echo "Connection success!" } -check_key_file() { - ssh_command="" - chmod 700 /tilde/key/* - - tilde_username="$1" - tilde_name="$2" - key_file="$(find /tilde/key | tail -n1)" - - if [ -f "$key_file" ] - then - while [ -z "$(cat $key_file | head -n1 | grep -- '-----BEGIN .* PRIVATE KEY-----')" ] - do - echo "$key_file does not look like a private key file, try again" - key_file="$(find /tilde/key | tail -n1)" - bash - done - ssh_command="ssh -i $key_file $tilde_username@$tilde_name" - echo "Key file located!" - fi - - echo "Testing ssh connection to $tilde_name as user $tilde_username..." - connection_test "$ssh_command" -} - configure_network() { echo "Press ENTER to configure network" read dummy_var diff --git a/setup.sh b/setup.sh index f006ae2..c5c1479 100755 --- a/setup.sh +++ b/setup.sh @@ -1,8 +1,9 @@ #!/bin/sh -tilde_name="" -tilde_username="" key_file="" +tilde_username="" +tilde_name="" + startx_command="startlxqt" . ./util.sh @@ -13,7 +14,7 @@ choice="" clear echo "=== Welcome to Tildelinux! ===" -configure_network || fail +configure_network clear echo "What tilde would you like to connect to? (use the domain name as you would for ssh)" @@ -27,12 +28,21 @@ echo "By whatever means, place your private key in the /tilde/key directory" echo "Here is a shell, once the key is in the proper location, simply type \"exit\" to close the shell and continue" bash -echo "Looking for keyfile..." -check_key_file "$tilde_username" "$tilde_name" || fail -# the key_file variable has now been set by check_key_file +echo "Looking for key file..." +key_file="$(find_key_file '/tilde/key')" +while [ -z "$key_file" ] +do + echo "Could not find a valid key file in /tilde/key" + echo "Use this shell to try and fix any problems, then check again by exiting this shell" + echo "Use \`exit 1\` to abort the install" + bash || fail + key_file="$(find_key_file '/tilde/key')" +done +echo "Key file located at $key_file, testing connection..." +connection_test "$key_file" "$tilde_username" "$tilde_name" echo "Configuring user..." -configure_user "$key_file" "$tilde_username" "$tilde_name" "$startx_command" || fail +configure_user "$key_file" "$tilde_username" "$tilde_name" "$startx_command" echo "User configured!" echo "All done! Enjoy using Tildelinux!" diff --git a/util.sh b/util.sh index 77f4a92..cb2612e 100755 --- a/util.sh +++ b/util.sh @@ -11,6 +11,19 @@ is_substring() { } fail() { + # TODO: make this exit cleanly, and from any subshell echo "Something went wrong, exiting..." exit } + +find_key_file() { + search_dir="$1" + for file in "$search_dir" + do + if cat $file | head -n1 | grep -q -- '-----BEGIN .* PRIVATE KEY-----') + then + echo "$file" + fi + + done +}