#!/bin/bash LIST_FILE="/data/gitea-init/repos.list" ENV_FILE="/data/gitea-init/install.env" trap 'echo -e "\033[31mcreate-all.sh: Something went wrong\033[0m"; exit 1' ERR set -e echo "Checking for a repos.list file..." if [ ! -f "$LIST_FILE" ]; then echo "File $LIST_FILE not found" exit 1 fi echo "Including a file with environment variables..." if [ -f $ENV_FILE ]; then source $ENV_FILE else echo "File install.env not found" exit 1 fi echo "Checking the presence of a variable GITEA_WRITE_USER_REPO..." if [ -z "$GITEA_WRITE_USER_REPO" ]; then echo "The GITEA_WRITE_USER_REPO variable is not set" exit 1 fi echo "Reading a CSV file and creating repositories..." OLDIFS=$IFS IFS=' | ' while read -r NAME_REPO DESCRIPTION_REPO; do if [ "$NAME_REPO" != "NAME_REPO" ]; then # Skip title RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "https://$GITEA_API_HOST/api/v1/user/repos" \ -H "Content-Type: application/json" \ -H "Authorization: token $GITEA_WRITE_USER_REPO" \ -d '{ "name": "'"$NAME_REPO"'", "private": true, "description": "'"$DESCRIPTION_REPO"'" }') if [ "$RESPONSE" -eq 201 ]; then echo "The $NAME_REPO repository has been created successfully" else echo "Error creating repository $NAME_REPO. HTTP status: $RESPONSE" fi fi done < "$LIST_FILE" IFS=$OLDIFS trap - ERR echo "Create all complete"