Skip to content

accepting location as an input parameter #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Well now, you can have this, do that for you! 🎊🎊🎊
## Set up

1. Either download or clone this repo
2. Edit `boot.sh` and change the location on line #5 to the path where your github private key is located.
2. Run `boot.sh` with location of ssh private key as argument
3. Copy the path to the `boot.sh` file by
1. `cd boot-github-shell-win`
2. Copy output of `pwd`
Expand All @@ -19,4 +19,4 @@ Well now, you can have this, do that for you! 🎊🎊🎊

## Options

You may opt to print details around the execution by calling the script with the `-v` flag like so: `bash boot.sh -v`
You may opt to print details around the execution by calling the script with additional flag `-v` like so: `bash boot.sh <private-key-location> -v`
27 changes: 17 additions & 10 deletions boot.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
#!/bin/bash
# Boot up github shell access for Windows WSL/Ubuntu.

#!/bin/bash
if [ "$#" -lt 1 ]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajaygtm71 , we want to make the location parameter optional here, and not mandatory. Probably behind a flag such as -l <location> or --location <location>.

then
echo "Please insert at least one argument"
exit
fi

private_key_location=~/.ssh/github_rsa # Change this location to where your file is located.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove this yet, we can have a fallback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you want to keep both ways ie manually editing and optionally passing parameters?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. As mentioned above, the location parameter is optional.

myArray=( "$@" )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a better name.

private_key_location=${myArray[0]}
verbose=${myArray[1]}

verbose=$1
if [ ! -e $private_key_location ]; then
echo "key $private_key_location not found"
exit
fi

echo 'Starting...'

if [ "$1" = "-v" ]; then
if [ "$verbose" = "-v" ]; then
echo 'Booting up ssh-agent...'
fi

eval `ssh-agent -s`
# ssh_agent_running=$(ssh-agent -s)
ssh_agent_running=$(ssh-agent -s)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test this once? I reckon that this might not work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the variable is storing the command output.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but the ssh-agent -s command actually outputs the ssh-agent's pid and the socket location and running the command inside eval stores them as local variables. If the eval is removed, ssh-add will no longer work, as shown below:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


if [ "$1" = "-v" ]; then
if [ "$verbose" = "-v" ]; then
echo 'ssh-agent started with output:' $ssh_agent_running
echo 'Adding private key to ssh-agent...'
fi

ssh_add_result=$(ssh-add $private_key_location)

if [ "$1" = "-v" ]; then
echo 'ssh-agent started with output:' $ssh_agent_running
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status messages are a part of the 'verbosity' 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same msg is already there in previous if block. so I removed from here

echo 'Adding private key to ssh-agent...'
if [ "$verbose" = "-v" ]; then
echo 'Command result: '$ssh_add_result
fi

Expand Down