2024-08-09 02:45:42 +05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-22 21:03:07 +05:00
|
|
|
LIST_FILE="/data/gitea-init/repos.list"
|
|
|
|
ENV_FILE="/data/gitea-init/install.env"
|
2024-08-09 02:45:42 +05:00
|
|
|
|
2024-08-22 21:03:07 +05:00
|
|
|
trap 'echo -e "\033[31mcreate-all.sh: Something went wrong\033[0m"; exit 1' ERR
|
|
|
|
set -e
|
|
|
|
|
|
|
|
echo "Checking for a repos.list file..."
|
2024-08-09 02:45:42 +05:00
|
|
|
if [ ! -f "$LIST_FILE" ]; then
|
|
|
|
echo "File $LIST_FILE not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 21:03:07 +05:00
|
|
|
echo "Including a file with environment variables..."
|
2024-08-09 02:45:42 +05:00
|
|
|
if [ -f $ENV_FILE ]; then
|
|
|
|
source $ENV_FILE
|
|
|
|
else
|
2024-08-22 21:03:07 +05:00
|
|
|
echo "File install.env not found"
|
2024-08-09 02:45:42 +05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 21:03:07 +05:00
|
|
|
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"
|
2024-08-09 02:45:42 +05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 21:03:07 +05:00
|
|
|
echo "Reading a CSV file and creating repositories..."
|
2024-08-09 02:45:42 +05:00
|
|
|
OLDIFS=$IFS
|
|
|
|
IFS=' | '
|
|
|
|
while read -r NAME_REPO DESCRIPTION_REPO; do
|
|
|
|
if [ "$NAME_REPO" != "NAME_REPO" ]; then # Skip title
|
2024-08-22 21:03:07 +05:00
|
|
|
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST "https://$GITEA_API_HOST/api/v1/user/repos" \
|
2024-08-09 02:45:42 +05:00
|
|
|
-H "Content-Type: application/json" \
|
2024-08-22 21:03:07 +05:00
|
|
|
-H "Authorization: token $GITEA_WRITE_USER_REPO" \
|
2024-08-09 02:45:42 +05:00
|
|
|
-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"
|
2024-08-22 21:03:07 +05:00
|
|
|
IFS=$OLDIFS
|
|
|
|
|
|
|
|
trap - ERR
|
|
|
|
echo "Create all complete"
|