From 2d644bc7b4719c437261a106127a15523186bb52 Mon Sep 17 00:00:00 2001 From: asandikci Date: Wed, 2 Aug 2023 23:08:48 +0300 Subject: [PATCH] feat: initialize installation scripts for testing --- scripts/install.sh | 70 ++++++++++++++++++++++++++++++++++++++++ scripts/local-install.sh | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 scripts/install.sh create mode 100644 scripts/local-install.sh diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..1d36fd7 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +### Ahenk Agent Local Installation Script + +### --> Prerequisites +# git +# go 1.20+ +# systemd + +# Change directory to main repo (cd ahenk-go) +# bash scripts/local-install.sh + +### --> Variable Set +REPO_NAME="ahenk-go" +REPO_LINK="https://git.aliberksandikci.com.tr/liderahenk/${REPO_NAME}" +DAEMON_NAME="ahenkd-go" +CONF_DIR="/etc/ahenk-go/" +TEMP_DIR="$(mktemp -d)" +MAIN_DIR="${TEMP_DIR}/${REPO_NAME}/" +echo -e "VARIABLES SET\n" + + +### --> Pre-Cleaning +sudo rm /usr/bin/${DAEMON_NAME} +sudo killall "$DAEMON_NAME" +sudo systemctl disable "$DAEMON_NAME" +sudo systemctl stop "$DAEMON_NAME" +sudo systemctl daemon-reload +sudo rm -rf "$CONF_DIR" +sudo mkdir -p "$CONF_DIR" +echo -e "PRE-CLENING DONE\n" + + +### --> Building +cp -r ../ "$TEMP_DIR" +cd "$TEMP_DIR" || exit +git clone "$REPO_LINK" +echo "$TEMP_DIR" +cd "$MAIN_DIR" || exit + +# cmd/ahenkd-go +cd cmd/ahenkd-go || exit +sudo go build -o "/usr/bin/ahenkd-go" + +echo -e "BUILDING DONE\n" + +### --> Configurations +sudo touch "$CONF_DIR/user.info" +sudo cat << EOF | sudo tee -a "$CONF_DIR/user.info" > /dev/null +The current working directory is: $PWD +You are logged in as $(whoami) +$HOME $USER $SUDO_USER +EOF +sudo chown root:root "$CONF_DIR/user.info" +sudo chmod 640 "$CONF_DIR/user.info" +echo -e "CONFIGURATIONS DONE\n" + +### --> Installing +if [[ $(ps -p 1 | awk 'FNR == 2 {print $4} ') == "systemd" ]] +then + sudo mv "${MAIN_DIR}build/package/deb/${DAEMON_NAME}.service" /etc/systemd/system/ +fi +sudo systemctl daemon-reload +sudo systemctl enable "$DAEMON_NAME" +sudo systemctl start "$DAEMON_NAME" +echo -e "INSTALLING DONE\n" + +### --> Post-Cleaning +sudo rm -rf "$TEMP_DIR" +echo -e "POST-CLEANING DONE\n" \ No newline at end of file diff --git a/scripts/local-install.sh b/scripts/local-install.sh new file mode 100644 index 0000000..468196f --- /dev/null +++ b/scripts/local-install.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +### Ahenk Agent Local Installation Script + +### --> Prerequisites +# go 1.20+ +# systemd + +# Change directory to main repo (cd ahenk-go) +# bash scripts/local-install.sh + +### --> Variable Set +REPO_NAME="ahenk-go" +DAEMON_NAME="ahenkd-go" +CONF_DIR="/etc/ahenk-go/" +TEMP_DIR="$(mktemp -d)" +MAIN_DIR="${TEMP_DIR}/${REPO_NAME}/" +echo -e "VARIABLES SET\n" + + +### --> Pre-Cleaning +sudo rm /usr/bin/${DAEMON_NAME} +sudo killall "$DAEMON_NAME" +sudo systemctl disable "$DAEMON_NAME" +sudo systemctl stop "$DAEMON_NAME" +sudo systemctl daemon-reload +sudo rm -rf "$CONF_DIR" +sudo mkdir -p "$CONF_DIR" +echo -e "PRE-CLENING DONE\n" + + +### --> Building +cp -r ../ "$TEMP_DIR" +cd "$TEMP_DIR" || exit +echo "$TEMP_DIR" +cd "$MAIN_DIR" || exit + +# cmd/ahenkd-go +cd cmd/ahenkd-go || exit +sudo go build -o "/usr/bin/ahenkd-go" + +echo -e "BUILDING DONE\n" + +### --> Configurations +sudo touch "$CONF_DIR/user.info" +sudo cat << EOF | sudo tee -a "$CONF_DIR/user.info" > /dev/null +The current working directory is: $PWD +You are logged in as $(whoami) +$HOME $USER $SUDO_USER +EOF +sudo chown root:root "$CONF_DIR/user.info" +sudo chmod 640 "$CONF_DIR/user.info" +echo -e "CONFIGURATIONS DONE\n" + +### --> Installing +if [[ $(ps -p 1 | awk 'FNR == 2 {print $4} ') == "systemd" ]] +then + sudo mv "${MAIN_DIR}build/package/deb/${DAEMON_NAME}.service" /etc/systemd/system/ +fi +sudo systemctl daemon-reload +sudo systemctl enable "$DAEMON_NAME" +sudo systemctl start "$DAEMON_NAME" +echo -e "INSTALLING DONE\n" + +### --> Post-Cleaning +sudo rm -rf "$TEMP_DIR" +echo -e "POST-CLEANING DONE\n" \ No newline at end of file