repomng/new-repo.sh

66 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Copyright (C) 2023 Mai-Lapyst
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [[ "$#" != "1" ]]; then
echo "Usage: new-repo.sh [repo name]"
exit 0
fi
reponame=$1
had_error=0
# first check if ANY folder is already there...
check_folder() {
local folder=$1;
local path="./$folder/$reponame"
if [[ ! -d "./$folder" ]]; then
# create folder if it dosnt already exists!
mkdir "./$folder"
fi
if [[ -d $path ]]; then
echo "Error: folder $path already exists"
had_error=1
return
fi
if [[ -f $path ]]; then
echo "Error: $path already exists and is a file (needs to be a folder!)"
had_error=1
return
fi
}
check_folder "archive"
check_folder "incomming"
check_folder "pending-remove"
check_folder "public"
if [[ "$had_error" != 0 ]]; then
exit 1
fi
# we checked everything and are clear!
mkdir -p "./archive/$reponame"
mkdir -p "./incomming/$reponame"
mkdir -p "./pending-remove/$reponame"
mkdir -p "./public/$reponame"
echo $reponame >> ./active_repos
echo "Done."