update logic check node, npm
This commit is contained in:
parent
d8b569b5e8
commit
7d3f9b28d9
11
install.sh
11
install.sh
|
|
@ -1,5 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
NODE_BIN=$(which node)
|
||||||
|
NPM_BIN=$(which npm)
|
||||||
|
|
||||||
|
echo $NODE_BIN
|
||||||
|
echo $NPM_BIN
|
||||||
if [ -d "/etc/systemd/system" ]; then
|
if [ -d "/etc/systemd/system" ]; then
|
||||||
echo "|---------------------------|"
|
echo "|---------------------------|"
|
||||||
echo -e "|***** \e[33mINSTALL SERVICE\e[0m *****|"
|
echo -e "|***** \e[33mINSTALL SERVICE\e[0m *****|"
|
||||||
|
|
@ -27,6 +32,12 @@ if [ -d "/etc/systemd/system" ]; then
|
||||||
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service_run/giteaService.conf &&
|
sudo sed -i "s#HOOK_PATH=.*#HOOK_PATH=$escaped_pwd_install#" $pwd_install/service_run/giteaService.conf &&
|
||||||
echo -e "* \e[32mHOOK_PATH\e[0m *" &&
|
echo -e "* \e[32mHOOK_PATH\e[0m *" &&
|
||||||
|
|
||||||
|
sudo sed -i "s#NODE_BIN=.*#NODE_BIN=$NODE_BIN#" $pwd_install/service_run/giteaService.conf &&
|
||||||
|
echo -e "* \e[32mNODE_BIN\e[0m *" &&
|
||||||
|
|
||||||
|
sudo sed -i "s#NPM_BIN=.*#NPM_BIN=$NPM_BIN#" $pwd_install/service_run/giteaService.conf &&
|
||||||
|
echo -e "* \e[32mNPM_BIN\e[0m *" &&
|
||||||
|
|
||||||
sudo sed -i "s#source .*#source $escaped_pwd_install/service_run/giteaService.conf#" $pwd_install/service_run/giteaHook.sh &&
|
sudo sed -i "s#source .*#source $escaped_pwd_install/service_run/giteaService.conf#" $pwd_install/service_run/giteaHook.sh &&
|
||||||
echo -e "* \e[32mEXEC_FILE\e[0m *" &&
|
echo -e "* \e[32mEXEC_FILE\e[0m *" &&
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
# The variable is automatically filled in by the system
|
# The variable is automatically filled in by the system
|
||||||
HOOK_PATH=/home/gitea_CICD
|
HOOK_PATH=/home/gitea_CICD
|
||||||
|
NODE_BIN=/path/to/node
|
||||||
|
NPM_BIN=/path/to/npm
|
||||||
# Git account (*)
|
# Git account (*)
|
||||||
GIT_USERNAME=<your_username>
|
GIT_USERNAME=<your_username>
|
||||||
GIT_PASSWORD=<your_password>
|
GIT_PASSWORD=<your_password>
|
||||||
|
|
|
||||||
|
|
@ -1,60 +1,75 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e # Dừng script nếu có lỗi
|
||||||
|
|
||||||
source /home/phuc/gitea_CICD/service_run/giteaService.conf
|
source /home/phuc/gitea_CICD/service_run/giteaService.conf
|
||||||
export HOME=$PROJECT_PATH
|
export HOME=$PROJECT_PATH
|
||||||
# Đường dẫn tới tệp index.js
|
|
||||||
indexjs_path=$HOOK_PATH/index.js
|
indexjs_path="$HOOK_PATH/index.js"
|
||||||
project_path=$HOOK_PATH
|
project_path="$HOOK_PATH"
|
||||||
|
|
||||||
USERNAME=$(echo "$GIT_USERNAME" | sed 's/@/%40/g')
|
USERNAME=$(echo "$GIT_USERNAME" | sed 's/@/%40/g')
|
||||||
PASSWORD=$(echo "$GIT_PASSWORD" | sed 's/@/%40/g')
|
PASSWORD=$(echo "$GIT_PASSWORD" | sed 's/@/%40/g')
|
||||||
|
|
||||||
REPOSITORY_AUTH="https://$USERNAME:$PASSWORD@$(echo $GIT_REPOSITORY | sed 's#https://##')"
|
REPOSITORY_AUTH="https://$USERNAME:$PASSWORD@$(echo $GIT_REPOSITORY | sed 's#https://##')"
|
||||||
|
|
||||||
cd "$PROJECT_PATH" &&
|
# Debug PATH nếu cần
|
||||||
|
# echo "Current PATH: $PATH"
|
||||||
|
# # Thiết lập lại PATH nếu thiếu (thường gặp khi chạy từ systemd)
|
||||||
|
# if ! command -v node &> /dev/null; then
|
||||||
|
# echo "Node.js not found in PATH, attempting to locate..."
|
||||||
|
# NODE_PATH=$(find /usr /opt /home -type f -name "node" -executable 2>/dev/null | head -n 1)
|
||||||
|
# if [ -x "$NODE_PATH" ]; then
|
||||||
|
# export PATH=$(dirname "$NODE_PATH"):$PATH
|
||||||
|
# echo "Added $(dirname "$NODE_PATH") to PATH"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
|
||||||
git config --global --add safe.directory $HOME &&
|
# if ! command -v node &> /dev/null; then
|
||||||
|
# echo -e "\e[41mNode.js is not installed or not in PATH\e[0m"
|
||||||
|
# exit 1
|
||||||
|
# else
|
||||||
|
# echo -e "\e[32mNode.js is installed!\e[0m"
|
||||||
|
# node -v
|
||||||
|
# fi
|
||||||
|
|
||||||
SET_ORIGIN=$(git remote set-url origin $REPOSITORY_AUTH) &&
|
# # Kiểm tra npm tương tự
|
||||||
|
# if ! command -v npm &> /dev/null; then
|
||||||
|
# echo "npm not found in PATH, attempting to locate..."
|
||||||
|
# NPM_PATH=$(find /usr /opt /home -type f -name "npm" -executable 2>/dev/null | head -n 1)
|
||||||
|
# if [ -x "$NPM_PATH" ]; then
|
||||||
|
# export PATH=$(dirname "$NPM_PATH"):$PATH
|
||||||
|
# echo "Added $(dirname "$NPM_PATH") to PATH"
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
|
||||||
# Ki?m tra xem Node.js đ? cài đ?t chưa
|
# if ! command -v npm &> /dev/null; then
|
||||||
if ! command -v node &> /dev/null; then
|
# echo -e "\e[41mnpm is not installed or not in PATH\e[0m"
|
||||||
# echo -e "\e[31mNode.js is not installed.\e[0m"
|
# exit 1
|
||||||
# echo -e "\e[32mInstall Node.js...\e[0m"
|
# else
|
||||||
# curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &&
|
# echo -e "\e[32mnpm is installed!\e[0m"
|
||||||
# sudo apt-get install nodejs -y &&
|
# npm -v
|
||||||
echo -e "\e[41mNodejs is not install\e[0m"
|
# fi
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo -e "\e[32mNodejs is installed!\e[0m" &&
|
|
||||||
node -v
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Ki?m tra xem npm đ? cài đ?t chưa
|
cd "$PROJECT_PATH"
|
||||||
if ! command -v npm &> /dev/null; then
|
git config --global --add safe.directory "$HOME"
|
||||||
echo -e "\e[41mNPM is not install\e[0m"
|
git remote set-url origin "$REPOSITORY_AUTH"
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo -e "\e[32mnpm is installed!\e[0m" &&
|
|
||||||
npm -v
|
|
||||||
fi
|
|
||||||
|
|
||||||
if git ls-remote -q --exit-code "$REPOSITORY_AUTH" > /dev/null; then
|
if git ls-remote -q --exit-code "$REPOSITORY_AUTH" > /dev/null; then
|
||||||
echo -e "\e[32mOK: Repository $GIT_REPOSITORY exists\e[0m"
|
echo -e "\e[32mOK: Repository $GIT_REPOSITORY exists\e[0m"
|
||||||
sleep 1
|
|
||||||
else
|
else
|
||||||
echo ""
|
echo -e "\e[41mError: Repository $GIT_REPOSITORY does not exist.\e[0m"
|
||||||
echo -e "\e[41mError: Repository $GIT_REPOSITORY not exists.\e[0m"
|
|
||||||
echo ""
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ki?m tra xem t?p index.js có t?n t?i không
|
# Chạy index.js nếu tồn tại
|
||||||
if [ -f "$indexjs_path" ]; then
|
if [ -f "$indexjs_path" ]; then
|
||||||
echo "Run file $indexjs_path..."
|
echo "Run file $indexjs_path..."
|
||||||
|
echo $NPM_BIN
|
||||||
|
echo $NODE_BIN
|
||||||
|
export PATH="$(dirname $NODE_BIN):$PATH"
|
||||||
cd "$project_path" &&
|
cd "$project_path" &&
|
||||||
npm install &&
|
$NPM_BIN install &&
|
||||||
node "$indexjs_path"
|
$NODE_BIN "$indexjs_path"
|
||||||
else
|
else
|
||||||
echo -e "\e[31mFile $indexjs_path not exists\e[0m"
|
echo -e "\e[31mFile $indexjs_path not exists\e[0m"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue