feat: initialize installation scripts for testing

This commit is contained in:
Aliberk Sandıkçı 2023-08-02 23:08:48 +03:00
parent 7737513f17
commit 2d644bc7b4
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
2 changed files with 137 additions and 0 deletions

70
scripts/install.sh Normal file
View file

@ -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"

67
scripts/local-install.sh Normal file
View file

@ -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"