Skip to content

Instantly share code, notes, and snippets.

@guileen
Last active July 25, 2016 21:44
Show Gist options
  • Save guileen/10399658 to your computer and use it in GitHub Desktop.
Save guileen/10399658 to your computer and use it in GitHub Desktop.
git shell commands
#!/bin/sh
# If the user is not root
if [ "$USERNAME" != "root" ]
then
# Dislpay a notice and stop
echo "Sorry, only root can use this command."
exit 1
fi
# Read in the SSH key
echo "Input the key to be added:"
read key
# Place the key in a temporary file (it's hard to get ssh-keygen
# to read from stdin; <<< works for bash, but is non-posix)
keyfile=$(tempfile) &&\
echo "$key" > $keyfile
# Generate a fingerprint
fingerprint=$(ssh-keygen -lf $keyfile)
# Check for errors
if [ $(echo "$fingerprint" | egrep -c '(R|D)SA') -eq 0 ]
then
# Display the fingerprint error and clean up
echo "Error: $fingerprint"
rm $keyfile
exit 1
fi
# Add the key to the authorised keys file and clean up
mkdir -p .ssh &&\
echo -n "no-agent-forwarding,no-port-forwarding,no-X11-forwarding " >> .ssh/authorized_keys &&\
cat $keyfile >> .ssh/authorized_keys
rm $keyfile
# Display the fingerprint for reference
echo "Success! Added a key with the following fingerprint:"
echo $fingerprint
#!/bin/sh
GIT_HOSTNAME=$(hostname)
# If the user is not root
# if [ "$USERNAME" != "root" ]
# then
# # Dislpay a notice and stop
# echo "Sorry, only root can use this command."
# exit 1
# fi
# If no project name is given
if [ $# -eq 0 ]
then
# Display usage and stop
echo "Usage: create <project.git>"
echo "Usage: create <group/project.git>"
exit 1
fi
# Set the project name, adding .git if necessary
project=$(echo "$*" | sed 's/\.git$\|$/.git/i')
# Create and initialise the project
mkdir -p "$project" && \
cd "$project" && \
git --bare init && \
echo 'run "git clone git@$GIT_HOSTNAME:$project"'
Copy link

ghost commented Apr 10, 2014

sinatra-prawncreate <project.git>"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment