@@ -9,7 +9,6 @@ NC='\033[0m' # No Color
99
1010REPO=" RustLangES/grhooks"
1111VERSION=${VERSION:- " latest" }
12- INSTALL_DIR=${INSTALL_DIR:- " /usr/local/bin" }
1312CONFIG_DIR=${CONFIG_DIR:- " /etc/grhooks" }
1413SERVICE_NAME=${SERVICE_NAME:- " grhooks" }
1514LOG_LEVEL=${LOG_LEVEL:- " info" }
@@ -19,21 +18,18 @@ if [[ "$(uname)" == "Darwin" ]]; then
1918 exit 1
2019fi
2120
22- echo -e " ${YELLOW} Install Configuration:${NC} "
23- echo -e " Version: ${GREEN}${VERSION}${NC} "
24- echo -e " Install Dir: ${GREEN}${INSTALL_DIR}${NC} "
25- echo -e " Configuration: ${GREEN}${CONFIG_DIR}${NC} "
26- echo -e " Service: ${GREEN}${SERVICE_NAME}${NC} "
27- echo -e " Log Level: ${GREEN}${LOG_LEVEL}${NC} "
28- echo " "
29-
3021ARCH=$( uname -m)
3122case $ARCH in
32- x86_64) ARCH=" x86_64" ;;
33- aarch64) ARCH=" arm64" ;;
23+ x86_64) ARCH=" x86_64" ; ARCH_NAME= " x86_64 (64-bit) " ;;
24+ aarch64) ARCH=" arm64" ; ARCH_NAME= " ARM64 " ;;
3425 * ) echo -e " ${RED} Arquitectura no soportada: $ARCH ${NC} " ; exit 1 ;;
3526esac
3627
28+ if [[ " $( uname) " == " Darwin" ]]; then
29+ echo -e " ${RED} Error: This script is just for linux systems${NC} "
30+ exit 1
31+ fi
32+
3733if [ -f /etc/debian_version ]; then
3834 PKG_TYPE=" deb"
3935elif [ -f /etc/redhat-release ]; then
4238 PKG_TYPE=" tar.xz"
4339fi
4440
41+ if [[ " $PKG_TYPE " == " tar.xz" ]]; then
42+ INSTALL_DIR=${INSTALL_DIR:- " /usr/local/bin" }
43+ fi
44+
45+ echo -e " ${YELLOW} System Information:${NC} "
46+ echo -e " Architecture: ${GREEN}${ARCH_NAME}${NC} "
47+ echo -e " Package Type: ${GREEN}${PKG_TYPE}${NC} "
48+ echo -e " Version: ${GREEN}${VERSION}${NC} "
49+ [[ -n " $INSTALL_DIR " ]] && echo -e " Install Dir: ${GREEN}${INSTALL_DIR}${NC} "
50+ echo -e " Configuration: ${GREEN}${CONFIG_DIR}${NC} "
51+ echo -e " Service: ${GREEN}${SERVICE_NAME}${NC} "
52+ echo -e " Log Level: ${GREEN}${LOG_LEVEL}${NC} "
53+ echo " "
54+
4555function prompt_yes_no {
4656 while true ; do
4757 read -p " $1 [y/N]: " yn
@@ -59,7 +69,7 @@ if [ "$confirmed" -eq 1 ]; then
5969 exit 1
6070fi
6171
62- echo -e " ${YELLOW} [1/4] Downloading ...${NC} "
72+ echo -e " ${YELLOW} [1/4] Downloading package ...${NC} "
6373
6474if [ " $VERSION " == " latest" ]; then
6575 DOWNLOAD_URL=$( curl -s https://api.github.com/repos/$REPO /releases/latest | grep " browser_download_url.*$ARCH " | grep " linux.*$PKG_TYPE \" " | cut -d ' "' -f 4)
6878fi
6979
7080if [ -z " $DOWNLOAD_URL " ]; then
71- echo -e " ${RED} Cannot found package for your system (Arch: $ARCH , Pkg Type: $PKG_TYPE )${NC} "
81+ echo -e " ${RED} Cannot find package for your system (Arch: $ARCH , Pkg Type: $PKG_TYPE )${NC} "
7282 exit 1
7383fi
7484
7585echo " Downloading: $DOWNLOAD_URL "
7686TEMP_DIR=$( mktemp -d)
77- curl -sSL $DOWNLOAD_URL -o " $TEMP_DIR /grhooks.${PKG_TYPE} " || {
78- echo -e " ${RED} Fail to download package${NC} "
87+ curl -sSL " $DOWNLOAD_URL " -o " $TEMP_DIR /grhooks.${PKG_TYPE} " || {
88+ echo -e " ${RED} Failed to download package${NC} "
7989 exit 1
8090}
8191
82- echo -e " ${YELLOW} [2/4] Installing...${NC} "
92+ echo -e " ${YELLOW} [2/4] Installing package ...${NC} "
8393
84- case $PKG_TYPE in
85- deb)
94+ if [[ " $PKG_TYPE " == " deb" || " $PKG_TYPE " == " rpm" ]]; then
95+ if [[ " $PKG_TYPE " == " deb" && $( dpkg -l | grep -q " grhooks" ) ]]; then
96+ echo -e " ${YELLOW} Removing previous version...${NC} "
97+ sudo dpkg --remove grhooks || true
98+ elif [[ " $PKG_TYPE " == " rpm" && $( rpm -qa | grep -q " grhooks" ) ]]; then
99+ echo -e " ${YELLOW} Removing previous version...${NC} "
100+ sudo rpm --erase grhooks || true
101+ fi
102+
103+ if [[ " $PKG_TYPE " == " deb" ]]; then
86104 sudo dpkg -i " $TEMP_DIR /grhooks.deb" || sudo apt-get install -f -y
87- ;;
88- rpm)
105+ INSTALL_DIR= $( which grhooks || echo " /usr/bin/grhooks " )
106+ else
89107 sudo rpm -ivh " $TEMP_DIR /grhooks.rpm" || sudo yum install -y
90- ;;
91- tar.xz)
92- sudo tar -xJf " $TEMP_DIR /grhooks.tar.xz " -C $TEMP_DIR
93- sudo install -Dm755 " $TEMP_DIR /grhooks" " $INSTALL_DIR /grhooks "
94- sudo chmod +x " $INSTALL_DIR /grhooks"
95- ;;
96- esac
108+ INSTALL_DIR= $( which grhooks || echo " /usr/bin/grhooks " )
109+ fi
110+ else
111+ sudo tar -xJf " $TEMP_DIR /grhooks.tar.xz " -C " $TEMP_DIR "
112+ sudo install -Dm755 " $TEMP_DIR /grhooks " " $INSTALL_DIR /grhooks"
113+ sudo chmod +x " $INSTALL_DIR /grhooks "
114+ fi
97115
98- echo -e " ${YELLOW} [3/4] Creating Config Directory ...${NC} "
99- sudo mkdir -p $CONFIG_DIR
100- sudo chown $USER :$USER $CONFIG_DIR
116+ echo -e " ${YELLOW} [3/4] Configuring directories ...${NC} "
117+ sudo mkdir -p " $CONFIG_DIR "
118+ sudo chown " $USER :$USER " " $CONFIG_DIR "
101119
102120if prompt_yes_no " Do you want to configure GRHooks as a systemd service?" ; then
103121 echo -e " ${YELLOW} [4/4] Configuring systemd service...${NC} "
104122
105123 SERVICE_FILE=" /etc/systemd/system/${SERVICE_NAME} .service"
106- cat << EOL | sudo tee $SERVICE_FILE > /dev/null
124+ cat << EOL | sudo tee " $SERVICE_FILE " > /dev/null
107125[Unit]
108126Description=GRHooks Webhook Server
109127After=network.target
110128
111129[Service]
112130Type=simple
113131User=$USER
114- ExecStart=${INSTALL_DIR} /grhooks ${CONFIG_DIR}
132+ ExecStart=${INSTALL_DIR} /grhooks --config-dir ${CONFIG_DIR}
115133Restart=always
116134RestartSec=5
117135Environment="GRHOOKS_LOG=${LOG_LEVEL} "
@@ -121,22 +139,26 @@ WantedBy=multi-user.target
121139EOL
122140
123141 sudo systemctl daemon-reload
124- sudo systemctl enable $SERVICE_NAME
142+ sudo systemctl enable " $SERVICE_NAME "
125143
126144 if prompt_yes_no " Do you want to start the service now?" ; then
127- sudo systemctl start $SERVICE_NAME
145+ sudo systemctl start " $SERVICE_NAME "
128146 echo -e " ${GREEN} Service started. You can view the logs with: journalctl -u $SERVICE_NAME -f${NC} "
129147 fi
130148else
131149 echo -e " ${YELLOW} [4/4] Skipping systemd service configuration.${NC} "
132150fi
133151
134- rm -rf $TEMP_DIR
152+ rm -rf " $TEMP_DIR "
135153
136- echo -e " ${GREEN} Installation completed!${NC} "
154+ echo -e " ${GREEN} Installation completed successfully !${NC} "
137155echo " "
138- echo -e " Post your manifests here: ${YELLOW}${CONFIG_DIR}${NC} "
139- echo -e " Binary: ${YELLOW}${INSTALL_DIR} /grhooks${NC} "
156+ echo -e " Configuration directory: ${YELLOW}${CONFIG_DIR}${NC} "
157+ echo -e " Binary location: ${YELLOW}${INSTALL_DIR} /grhooks${NC} "
140158if [ -f " $SERVICE_FILE " ]; then
141- echo -e " Service: ${YELLOW} systemctl status ${SERVICE_NAME}${NC} "
159+ echo -e " Service commands:"
160+ echo -e " Status: ${YELLOW} systemctl status ${SERVICE_NAME}${NC} "
161+ echo -e " Start: ${YELLOW} systemctl start ${SERVICE_NAME}${NC} "
162+ echo -e " Stop: ${YELLOW} systemctl stop ${SERVICE_NAME}${NC} "
163+ echo -e " Restart: ${YELLOW} systemctl restart ${SERVICE_NAME}${NC} "
142164fi
0 commit comments