Newer
Older
#!/bin/bash
# My GiLab Backup (mygb) is a script for backup my GitLab's groups and projects
# Copyright (C) 2021 Christophe Chaudier
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
mygb.sh <command> [options]
Command :
init : create the configuration file
export : export from GitLab
import : import to GitLab
Options :
-h : print help
-c path/to/conf : read one config file
-p path/to/projet : export the projet
-g path/to/group : export the group and is subgroups and projects
-a : export all my group and subgroup
'
# Vars
config_file='.mygb_config'
export_all=false
_exit() {
cr=${1}
echo "End with code ${cr}"
exit ${cr}
}
if [[ -e ${config_file} ]]; then
# shellcheck disable=SC1090
source ${config_file}
else
_create_config
fi
}
_create_config() {
echo "There is no file!"
echo "What is the GitLab URL :"
read -r gitlab_url
echo "What is the GitLab API token :"
read -rs gitlab_api_token
echo "gitlab_url=\"${gitlab_url}\"" >${config_file}
echo "gitlab_api_token=\"${gitlab_api_token}\"" >>${config_file}
echo "The file ${config_file} was created with this content."
echo "Please add the line below on your .gitignore"
echo "${config_file}"
}
echo "Flag is ${flag}"
# shellcheck disable=SC2034
case "${flag}" in
c) config_file=${OPTARG} ;;
p) project=${OPTARG} ;;
g) groups=${OPTARG} ;;
a) export_all=true ;;
h | *) _help ;;
esac
done
case "${action}" in
init) _load_config ;;
export) _export ;;
import) _import ;;
*) _help ;;
esac