diff --git a/config/config_git.sh b/config/config_git.sh new file mode 100644 index 0000000..1af66bd --- /dev/null +++ b/config/config_git.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# shellcheck disable=SC2034 + +CONFIG_SERVER_GIT="https://gitea.server.home/" \ No newline at end of file diff --git a/func/git.sh b/func/git.sh index 4b77c95..c9809eb 100644 --- a/func/git.sh +++ b/func/git.sh @@ -1,3 +1,13 @@ +#!/bin/bash + +if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then + WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" +fi + +#region INCLUDES +. "${WELCOME_SCRIPT_PATH}/config/config_git.sh" +#endregion + getbranch(){ local branch @@ -8,7 +18,16 @@ getbranch(){ exit fi - echo $branch + echo "$branch" +} + +gitinit(){ + git init + git add . + git commit -m "Initial commit" + git branch -M main + git remote add origin "${1:-$CONFIG_SERVER_GIT}" + git push -u origin main } gitreset(){ @@ -67,8 +86,7 @@ script_update() { cd "$WELCOME_SCRIPT_PATH" || return 2 - git fetch origin >/dev/null 2>&1 - if [ $? -ne 0 ]; then + if ! git fetch origin >/dev/null 2>&1; then msg_error "Erreur lors du Fetch" cd "$current_path" || : return 3 @@ -85,8 +103,8 @@ script_update() { # update echo "" - git reset --hard origin/"$BRANCH" - if [ $? -eq 0 ]; then + + if git reset --hard origin/"$BRANCH"; then msg_success "Les script de welcome a été mis à jour !! relancer le ssh pour profiter des nouvelles fonctionnalités" echo "" cd "$current_path" || : diff --git a/inc/alias.sh b/inc/alias.sh index 94aa5f8..1cec102 100644 --- a/inc/alias.sh +++ b/inc/alias.sh @@ -54,8 +54,11 @@ alias wlog='tail -fn 100 /var/log/apache2/access.log /var/log/apache2/error.log' if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)" fi +. "${WELCOME_SCRIPT_PATH}/config/config_git.sh" . "${WELCOME_SCRIPT_PATH}/func/git.sh" +# init repo +alias gitinit='gitinit' # get last changes alias gitsync='gitsync' # restore as depot