gitea-init/create-all.sh
2024-08-09 02:45:42 +05:00

47 lines
1.2 KiB
Bash

#!/bin/bash
LIST_FILE="./repos.list"
ENV_FILE="/data/secrets/dev.env"
# Checking for a CSV file
if [ ! -f "$LIST_FILE" ]; then
echo "File $LIST_FILE not found"
exit 1
fi
# Including a file with environment variables
if [ -f $ENV_FILE ]; then
source $ENV_FILE
else
echo "File dev.env not found"
exit 1
fi
# Checking the presence of a variable GITEA_W_USER_REPO
if [ -z "$GITEA_W_USER_REPO" ]; then
echo "The GITEA_W_USER_REPO variable is not set"
exit 1
fi
# 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://git.rozenlab.com/api/v1/user/repos" \
-H "Content-Type: application/json" \
-H "Authorization: token $GITEA_W_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