From 7ad0b8b385be14dc69e1d2032ae1ff8fb3898e29 Mon Sep 17 00:00:00 2001 From: Joseph Le Date: Fri, 13 Oct 2023 17:31:05 +1100 Subject: [PATCH] update README, atuo auth git --- README.md | 7 ++++--- install.sh | 19 ++++++++++++++++++- service/giteaService.conf | 4 ++++ service/giteaService.sh | 6 ++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 626f233..ba94298 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ ### 1) Clone project to your server ```sh - git clone https://:@gitea.nswteam.net/joseph/gitea_CICD.git + git clone https://gitea.nswteam.net/joseph/gitea_CICD.git ``` -- Get username: -
getUsername
### 2) Access the folder you just cloned @@ -39,6 +37,9 @@ Copy environment file ### 5) Fill in environment variables (\*) +- Git username: +
getUsername
+ root@root# ```sh nano service_run/giteaService.conf diff --git a/install.sh b/install.sh index fe41720..f779308 100755 --- a/install.sh +++ b/install.sh @@ -13,7 +13,7 @@ if [ -d "/etc/systemd/system" ]; then echo -e "|***** \e[33mUPDATE ENVIRONMENT\e[0m *****|" echo "|------------------------------|" echo "" - + find $pwd_install/service -type f -not -name "giteaService.conf" -exec cp {} $pwd_install/service_run \; sleep 2 && @@ -33,6 +33,7 @@ if [ -d "/etc/systemd/system" ]; then echo -e "* \e[32mEXEC_FILE\e[0m *" && echo "" sleep 1 && + systemctl stop giteaHook.service input_file="$pwd_install/service_run/giteaService.conf" && @@ -55,8 +56,24 @@ if [ -d "/etc/systemd/system" ]; then echo -e "\e[32mOK: $path exists\e[0m" sleep 1 fi + else + if [[ $line == *"REPOSITORY"* ]]; then + path="${line#*=}" + if git ls-remote -q --exit-code "$path" > /dev/null; then + echo -e "\e[32mOK: Repository $path exists\e[0m" + sleep 1 + else + echo "" + echo -e "\e[41mError: Repository $path not exists.\e[0m" + echo "" + exit 1 + fi + fi fi done <"$input_file" && + + + cp $pwd_install/service_run/giteaHook.service /etc/systemd/system/giteaHook.service && echo "" && echo -e "* \e[32mCopy service file\e[0m *" && diff --git a/service/giteaService.conf b/service/giteaService.conf index 36af598..5c00a29 100755 --- a/service/giteaService.conf +++ b/service/giteaService.conf @@ -4,6 +4,10 @@ HOOK_PATH=/home/gitea_CICD # Git account (*) +GIT_USERNAME= +GIT_PASSWORD= +GIT_REPOSITORY= +# Example: https://gitea.nswteam.net/username/repo_name.git GIT_BRANCH= # Port of server (*) diff --git a/service/giteaService.sh b/service/giteaService.sh index 4e4cedd..2eaf847 100755 --- a/service/giteaService.sh +++ b/service/giteaService.sh @@ -3,6 +3,11 @@ # Đường dẫn tới tệp index.js indexjs_path=$HOOK_PATH/index.js project_path=$HOOK_PATH +REPOSITORY_AUTH="https://$GIT_USERNAME:$GIT_PASSWORD@$(echo $GIT_REPOSITORY | sed 's#https://##')" + +cd "$PROJECT_PATH" && +SET_ORIGIN=$(git remote set-url origin $REPOSITORY_AUTH) +echo "$SET_ORIGIN" # Kiểm tra xem Node.js đã cài đặt chưa if ! command -v node &> /dev/null; then @@ -34,3 +39,4 @@ if [ -f "$indexjs_path" ]; then else echo -e "\e[31mFile $indexjs_path not exists\e[0m" fi +