Skip to content
Snippets Groups Projects
Commit 22cee675 authored by dylan.peiry's avatar dylan.peiry
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
*
!*.*
!Makefile
*.o
*
!*.*
!Makefile
*.o
*
!*.*
!Makefile
*.o
*
!*.*
!Makefile
*.o
*
!*.*
!Makefile
*.o
*
!*.*
!Makefile
*.o
#!/bin/bash
# Script to automatically create and init a repo on the specified gitlab instance
# Written by Dylan PEIRY (dylan.peiry@etu.hesge.ch
# Syntax : ./gitcreate.sh {username_aai} {public:true_or_false} {method:https_or_ssh}
ACCESS_TOKEN="6HdtsLxS63D22EVPuzBX"
# methods of access
HTTPS="https://gitedu.hesge.ch"
SSH="ssh://git@ssh.hesge.ch:10572"
# Check the the access token is set
if [[ -z $ACCESS_TOKEN ]]; then
echo 'Please set your access token in the script.'
exit
fi
# Check the the visibility arg is specified
if [[ $# -lt 3 ]]; then
echo 'The AAI username must be specified (firstname.lastname).'
echo 'The visibility level must be specified (true=public,false=private).'
echo 'The access method must be specified (https,ssh)'
exit
fi
# The name of the repository will be the name of the current directory
NAME=$(basename $PWD)
USERNAME=$1
VISIBILITY=$2
ACCESS_METHOD=$3
echo $ACCESS_METHOD
# Define the remote origin (url on which we will link the local repository)
REMOTE_ORIGIN=""
if [[ $ACCESS_METHOD == "ssh" ]]; then
REMOTE_ORIGIN="$SSH/$USERNAME/$NAME.git"
fi
if [[ $ACCESS_METHOD == "https" ]]; then
REMOTE_ORIGIN="$HTTPS/$USERNAME/$NAME.git"
fi
echo $REMOTE_ORIGIN
# Call the api to create the repository with the specified name
RESPONSE=$(curl -X POST 'https://gitedu.hesge.ch/api/v4/projects?private_token='$ACCESS_TOKEN'' \
-d '{"name":"'$NAME'","path":"'$NAME'"}' \
-H "Content-Type: application/json" \
-silent)
# Look through the response to see if the name was taken by another repository
if [[ $RESPONSE == *"taken"* ]]; then
echo 'A repository with the name ['$NAME'] already exists.'
exit
fi
# Create a .gitignore specific to a c program
touch .gitignore
echo "*" >> .gitignore
echo "!*.*" >> .gitignore
echo "!Makefile" >> .gitignore
echo "*.o" >> .gitignore
# Initialize a local repository and push the files
git init
git remote add origin $REMOTE_ORIGIN
git add .
git commit -m "initial commit"
git push -u origin master
echo 'The repository was successfully created and the files were successfully pushed to it.'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment