Created
February 27, 2014 22:10
-
-
Save dsebastien/9260683 to your computer and use it in GitHub Desktop.
git-shell-commands - create
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Adapted from: http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell | |
# comment out or adapt if you want to allow non-root users to create new repositories | |
# If the user is not root | |
if [ "$USERNAME" != "root" ] | |
then | |
# Display 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>" | |
exit 1 | |
fi | |
# Set the project name, adding .git if necessary | |
extension=".git" | |
project=$(echo "$*") | |
if [ "${project/$extension}" = "$project" ]; | |
then | |
project=$project$extension | |
fi | |
# Create and initialize the project | |
mkdir "$project" && \ | |
cd "$project" && \ | |
git --bare init | |
echo "$project repository created. Check with 'list'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment