From 6786a05a67728e733f4280a551cf2c0efa1110f4 Mon Sep 17 00:00:00 2001 From: asandikci Date: Thu, 24 Aug 2023 17:54:59 +0300 Subject: [PATCH] move tmp scripts to this branch for reference --- scripts/docker-build.sh | 92 ++++++++++++++++++++++++++++++++++++++++ scripts/install.sh | 73 +++++++++++++++++++++++++++++++ scripts/local-build.sh | 3 ++ scripts/local-install.sh | 67 +++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+) create mode 100644 scripts/docker-build.sh create mode 100644 scripts/install.sh create mode 100644 scripts/local-build.sh create mode 100644 scripts/local-install.sh diff --git a/scripts/docker-build.sh b/scripts/docker-build.sh new file mode 100644 index 0000000..3dc7bf0 --- /dev/null +++ b/scripts/docker-build.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# see https://people.debian.org/~stapelberg/2015/07/27/dh-make-golang.html + +GIT_HOST="git.aliberksandikci.com.tr" +GIT_ORG="liderahenk" +GIT_REPO="ahenk-go" +FULL_URL="https://$GIT_HOST/$GIT_ORG/$GIT_REPO" +DEV_NAME="Aliberk Sandıkçı" +GIT_MAIL="git@aliberksandikci.com.tr" + +UPLOAD_URL="127.0.0.1" +UPLOAD_PORT="8000" + +echo "Editing git configs..." +git config --global init.defaultBranch main +git config --global user.name "$DEV_NAME" +git config --global user.email $GIT_MAIL +git config --global color.status auto +git config --global color.branch auto +git config --global color.interactive auto +git config --global color.diff auto + +mkdir /build +cd /build || exit + +if [[ "$1" != "update" ]]; then + + dh-make-golang make -allow_unknown_hoster "$GIT_HOST/$GIT_ORG/$GIT_REPO" + + if [[ ! ("$1" != "notodo" || "$2" != "notodo") ]]; then + + # TODO Add option to disable writing all these files all the time (-s --skip) + nano "itp-$GIT_REPO.txt" + sendmail -t <"itp-$GIT_REPO.txt" + + cd $GIT_REPO || exit + grep --color=always -r TODO debian + echo -e "\nThese files needs review. Starting reviewing automatically in 10sec...\n" + sleep 10 + # TODO Allow users to escape from automatic review and manually do it while in this script + + while [[ $(grep -r TODO debian | wc --lines) -ne 0 ]]; do + nano "$(grep -r TODO debian | awk '{sub(/:.*/,"")} NR==1')" + + echo "Continuing from next file..." + sleep 1 + grep --color=always -r TODO debian + sleep 5 + + # TODO Allow user to reviewing remaining files, choosing between them, optional skipping, and waiting for an answer (continue? [Y/n]) + done + echo "ALL FILES DONE" + + dh_installsystemd + echo """ +#!/usr/bin/make -f + +%: + dh \$@ --builddirectory=_build --buildsystem=golang --with=golang --with-systemd +override_dh_auto_install: + dh_auto_install -- --no-source +""" >debian/rules + sleep 5 + # FIXME Not working! + + else + cd $GIT_REPO || exit + fi +else + gbp clone "$FULL_URL" + cd $GIT_REPO || exit + git checkout debian/sid + pwd + if [[ "$1" == "nmu" ]]; then + dch --nmu + else + dch + fi + echo "Succesfully Updated deb package information" +fi + +# TODO ask user to continue + +git add debian && git commit -a -m 'Initial packaging' + +gbp buildpackage + +cd .. +lintian -- *.changes + +echo -e "SOLVE LINTIAN ERRORS / WARNINGS\nAFTER THAT, PUSH REPO" diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 0000000..9bd5670 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +### Ahenk Agent Local Installation Script +### IMPORTANT NOTICE ! +# Consider to use makefile for building or .deb file for installing package, +# using this scripts is not suggested anymore ! + +### --------------------- ### + +### --> Prerequisites +# git +# go 1.20+ +# systemd + +# wget -qO- https://git.aliberksandikci.com.tr/liderahenk/ahenk-go/raw/branch/main/scripts/install.sh | bash + +### --> Variable Set +REPO_NAME="ahenk-go" +REPO_LINK="https://git.aliberksandikci.com.tr/liderahenk/${REPO_NAME}" +DAEMON_NAME="ahenk-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 +cd "$TEMP_DIR" || exit +echo "$TEMP_DIR" +git clone "$REPO_LINK" +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-build.sh b/scripts/local-build.sh new file mode 100644 index 0000000..9c86f61 --- /dev/null +++ b/scripts/local-build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +sudo go build -o "build/package/bin/ahenkd-go" cmd/ahenkd-go/ahenkd-go.go \ No newline at end of file diff --git a/scripts/local-install.sh b/scripts/local-install.sh new file mode 100644 index 0000000..17cd6e5 --- /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="ahenk-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}debian/${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