pub / stagit-scripts

Building src.jayvii.de with stagit
git clone https://src.jayvii.de/pub/stagit-scripts.git
Home | Log | Files | Exports | Refs | README | RSS

git_create_repo.sh (1918B)


      1 #!/usr/bin/env sh
      2 # SPDX-License-Identifier: AGPL-3.0-or-later
      3 # SPDX-FileCopyrightText: 2021-2024 JayVii <jayvii[AT]posteo[DOT]de>
      4 
      5 # $1 - HTML Root
      6 # $2 - prv/pub
      7 # $3 - repo name
      8 # $4 - description
      9 # $5 - long description
     10 # $6 - owner/maintainer
     11 
     12 # Error out if not all options are given
     13 if [ -z "$6" ]; then
     14     echo "Usage:
     15 git_create_repo.sh \\
     16     \"/var/www/git.example.git\" \\
     17     \"pub\" \\
     18     \"stagit-scripts\" \\
     19     \"An example repository.\" \\
     20     \"A long description for this respoitory.\" \\
     21     \"JayVii\"
     22     "
     23     exit 1;
     24 fi
     25 
     26 # If Git Repositories / folders already exist, exit immediately
     27 if [ -d "${1}/${2}/${3}.git" ]; then
     28     echo "${2}/${3} already exists!"
     29     exit 1;
     30 fi
     31 
     32 # Retrieve URL if set
     33 if [ -f "${1}/url" ]; then
     34     URL=`cat ${1}/url`
     35 else
     36     URL=""
     37 fi
     38 
     39 # Create Folders
     40 mkdir -p "${1}/${2}/${3}/"
     41 mkdir -p "${1}/${2}/${3}/exports/"
     42 mkdir -p "${1}/${2}/${3}.git/"
     43 
     44 # Ensure that export-directory is browsable
     45 echo "Options +Indexes" > "${1}/${2}/${3}/exports/.htaccess"
     46 
     47 # Git-Repository
     48 cd "${1}/${2}/${3}.git" || exit 1;
     49 
     50 # create bare branch
     51 git init --bare || exit 1;
     52 
     53 # Set default branch to "main"
     54 echo "ref: refs/heads/main" > HEAD
     55 
     56 # Add short description
     57 echo "$4" > description
     58 
     59 # Add long description
     60 echo "$5" > description_full
     61 
     62 # Add owner
     63 echo "$6" > owner
     64 
     65 # Add Clone URL, if "url" file exists in root directory
     66 if [ -f "${1}/url" ]; then
     67     URL=`cat ${1}/url`
     68     echo "${URL}/${2}/${3}.git" > "${1}/${2}/${3}.git/url"
     69 fi
     70 
     71 # Add Hooks
     72 PUH_FILE="${1}/${2}/${3}.git/hooks/post-update"
     73 touch "$PUH_FILE"
     74 chmod +x "$PUH_FILE"
     75 echo "#!/usr/bin/env sh
     76 ~/bin/git_post_push.sh \"${1}\" \"${2}\" \"${3}\" \"\$@\"" >> "$PUH_FILE"
     77 
     78 # make branch cloneable via http(s)
     79 git update-server-info
     80 
     81 # enforce file permissions
     82 chmod 770 -R "${1}/${2}/${3}"
     83 chmod 770 -R "${1}/${2}/${3}.git"
     84 
     85 # User output
     86 echo "The repository is available via git clone ${URL}/${2}/${3}.git"