Merge pull request 'merge temporary changes in to main branch' (#1) from pufff into main

Reviewed-on: #1
This commit is contained in:
Aliberk Sandıkçı 2023-08-24 21:35:53 +03:00
commit c84dbc9def
21 changed files with 320 additions and 350 deletions

View file

@ -3,23 +3,16 @@
# after cd ahenk-go
# docker run -it -d --name CONT_NAME --mount type=bind,source=".",target=/ahenk-go/ IMAGE_NAME:VERSION "/bin/bash"
ARG CODE_VERSION=sid
FROM debian:${CODE_VERSION}
RUN su -c "echo 'deb http://ftp.tr.debian.org/debian sid main' >> /etc/apt/sources.list.d/sid.list"
FROM bitnami/minideb
RUN apt-get update
RUN apt-get upgrade -y
### INSTALL USEFUL UTILITIES ###
RUN apt-get install curl wget tree nano -y
RUN apt-get install git curl wget tree nano procps lintian -y
### INSTALL BUILD DEPENDENCIES ###
RUN apt-get install dh-golang -y
RUN apt-get install dh-make-golang -y
RUN apt-get install golang-github-sevlyar-go-daemon-dev -y
RUN apt-get install golang-golang-x-exp-dev -y
RUN apt-get install sudo dpkg-dev debhelper golang-any -y
### CONFIGURATIONS ###
# Enable UTF8 Encoding

51
Makefile Normal file
View file

@ -0,0 +1,51 @@
REPO_NAME=ahenk-go
REPO_LINK=https://git.aliberksandikci.com.tr/liderahenk/${REPO_NAME}
DAEMON_NAME=ahenk-go
OLD_DAEMON_NAME=ahenkd-go
PYTHON_DAEMON_NAME=ahenkd
DATA_DIR=/etc/ahenk-go/
LIB_DIR=/usr/share/ahenk-go/
PLUGIN_DIR=${LIB_DIR}/plugins/
TEMP_DIR=$(mktemp -d)
MAIN_DIR=${TEMP_DIR}/${REPO_NAME}/
info:
@echo "Made by Aliberk Sandıı - 2023"
@echo "preclean: for cleaning old files, configurations"
@echo "TODO test: Test go files"
@echo "install: Build and install ahenk-go to DESTDIR"
@echo "uninstall: Uninstall ahenk-go from DESTDIR"
preclean:
sudo rm -rf /usr/bin/$(DAEMON_NAME)
sudo rm -rf /usr/bin/${OLD_DAEMON_NAME}
sudo rm -rf /usr/bin/${PYTHON_DAEMON_NAME}
@# TODO systemd control for both three process for docker
@# REVIEW are both killall and systemctl commands running?
@pgrep -x ${DAEMON_NAME} && (sudo killall "${DAEMON_NAME}" || sudo systemctl disable "${DAEMON_NAME}" || sudo systemctl stop "${DAEMON_NAME}") || echo "no ${DAEMON_NAME} found"
@pgrep -x ${OLD_DAEMON_NAME} && (sudo killall "${OLD_DAEMON_NAME}" || sudo systemctl disable "${OLD_DAEMON_NAME}" || sudo systemctl stop "${OLD_DAEMON_NAME}") || echo "no ${OLD_DAEMON_NAME} found"
@# TODO
@# echo -e "Do you want to remove python implementation of ahenk if installed in system?"
@# read -rp "(Y/N) " input
@pgrep -x ${PYTHON_DAEMON_NAME} && (sudo killall "${PYTHON_DAEMON_NAME}" || sudo systemctl disable "${PYTHON_DAEMON_NAME}" || sudo systemctl stop "${PYTHON_DAEMON_NAME}") || echo "no ${PYTHON_DAEMON_NAME} found"
sudo systemctl daemon-reload
sudo rm -rf ${DATA_DIR}
@echo -e "PRE-CLENING DONE\n"
test:
@echo -e "Testing go files not implemented yet!"
install:
sudo go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/ahenk-go/
@sudo mkdir -p "${DESTDIR}/${LIB_DIR}"
@sudo mkdir -p "${DESTDIR}/${PLUGIN_DIR}"
sudo go build -buildmode=plugin -o ${DESTDIR}/${PLUGIN_DIR}/resources.so ./plugins/resources
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
uninstall:
@sudo rm -rf ${DESTDIR}/usr/bin/${REPO_NAME}

View file

@ -1,34 +1,45 @@
# Ahenk Go
Ahenk Agent for Liderahenk Central Management System - Go Implementation
**Liderahenk** is an open source project which provides solutions to manage, monitor and audit unlimited number of different systems and users on a network.
You can find binary packages in [Releases](/releases) section or build from source code yourself<!-- See section [Packaging](#packaging)-->.
Ahenk-go is a Linux agent written in Go which enables Lider to manage & monitor clients remotely.
<!-- ### Packaging
Install necessary packages
## Packaging
1. Install necessary packages (You dont need this step if you are using docker file)
```sh
sudo apt install sudo dpkg-dev debhelper golang-any
```
2. Clone the repository and move to main directory
```sh
git clone https://git.aliberksandikci.com.tr/Liderahenk/ahenk-go/
cd ahenk-go/
```
-
3. Build program and create binary/source packages
```sh
dpkg-buildpackage
```
> Refer to Makefile for more info
TODO https://github.com/Pardus-LiderAhenk/ahenk/#packaging
-->
### Documentation
- See comprehensively prepared [documentation](https://git.aliberksandikci.com.tr/Liderahenk/ahenk-docs/)
- See how to [setup development environment](https://git.aliberksandikci.com.tr/Liderahenk/ahenk-docs/src/branch/main/dev/environment.md)
<!-- Web Documentation Link Here -->
If you do not prefer to use binary packages you can also use installation scripts <!-- TODO temporary solution, will be removed -->
Development Dependencies
```bash
go > 1.20
git
```
Install with Script
```bash
wget -qO- https://git.aliberksandikci.com.tr/liderahenk/ahenk-go/raw/branch/main/scripts/install.sh | bash
```
### Useful Links
| Explanation | Link |
| ----------- | ---- |
| Ahenk-go documentation | [Liderahenk/ahenk-docs](https://git.aliberksandikci.com.tr/Liderahenk/ahenk-docs/) |
| Current Python Implementation of Ahenk | [Pardus-LiderAhenk/ahenk](https://github.com/Pardus-LiderAhenk/ahenk/) |
## Other Liderahenk Projects
- [Pardus-LiderAhenk/ahenk](https://github.com/Pardus-LiderAhenk/ahenk/): Current Python Implementation of Ahenk
- [Lider UI](https://github.com/Pardus-LiderAhenk/liderui): Lider Administration User Interface
- [Lider API](https://github.com/Pardus-LiderAhenk/liderapi): Lider API
- [Liderahenk-ansible](https://github.com/Pardus-LiderAhenk/liderahenk-ansible): Liderahenk setup with ansible
- [Ahenkdesk](https://github.com/Pardus-LiderAhenk/ahenkdesk): Ahenk User Interface
- See more in our [GitHub Page](https://github.com/Pardus-LiderAhenk)
## Changelog
- [ahenk-docs/admin/changelog](https://git.aliberksandikci.com.tr/Liderahenk/ahenk-docs/src/branch/main/admin/changelog.md): changes between releases with easy-to-understand annotations
- [ahenk-docs/dev/changelog](https://git.aliberksandikci.com.tr/Liderahenk/ahenk-docs/src/branch/main/dev/changelog.md): detailed development changelog, includes all issues, feature implementations, breaking changes, code comments, todo etc. - **long**
- [debian/changelog](./debian/changelog): changes between debian releases
<!-- https://doc.liderahenk.org/ahenk/changelog/ -->
## License
Liderahenk and its sub projects are licensed under the [LGPL v3](./LICENSE).

View file

@ -1,51 +1,35 @@
package main
import (
"ahenk-go/pkg/utils"
"log"
"os"
"syscall"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/sevlyar/go-daemon"
"golang.org/x/exp/slices"
)
const PidFile = "/run/ahenkd-go.pid"
const ExecutablePath = "/usr/bin/ahenkd-go"
const ConfDir = "/etc/ahenk-go/"
// FIXME there isn't any difference with Stop() function
// TODO There can be a Start() function in it but start function doesnt work properly right now
func Restart(pid, signal int) {
Stop(pid, signal)
}
// Stop Ahenkd Daemon with a specific PID (running from second copy)
// do not forget to use also os.Exit() when using in ExecStop
func Stop(pid, signal int) {
log.Println("Stop Signal Caught")
// FILLME what you want to do before stopping daemon?
if err := syscall.Kill(pid, syscall.Signal(signal)); err == nil {
log.Printf("Ahenk Daemon with pid number %v Successfully stopped", pid) // TODO Also log to /etc/ahenk-go/ahenkd.log
} else {
log.Fatal(err)
}
}
const DataDir = "/etc/ahenk-go/"
const LogFile = DataDir + "ahenk.log"
const LibDir = "/usr/share/ahenk-go/"
const PluginDir = LibDir + "/plugins/"
// Main Function that starts daemon and controls arguments
func main() {
if len(os.Args) == 2 && slices.Contains([]string{"start", "stop", "restart", "nodaemon"}, os.Args[1]) {
if len(os.Args) == 2 && slices.Contains([]string{"start", "stop", "restart", "nodaemon", "tmptest"}, os.Args[1]) {
switch os.Args[1] {
case "start":
utils.CreatePath(ConfDir)
utils.CreatePath(DataDir)
cntxt := &daemon.Context{
PidFileName: PidFile,
PidFilePerm: 0644,
LogFileName: ConfDir + "ahenkd.log",
LogFileName: LogFile,
LogFilePerm: 0640,
WorkDir: ConfDir,
WorkDir: LibDir,
Umask: 027,
Args: []string{ExecutablePath, "start"},
}
@ -62,18 +46,46 @@ func main() {
case "stop":
i, _ := daemon.ReadPidFile(PidFile)
Stop(i, 15)
os.Exit(0)
case "restart":
i, _ := daemon.ReadPidFile(PidFile)
Restart(i, 15)
os.Exit(0)
case "nodaemon":
log.Print("STARTED AS NO-DAEMON")
f := utils.OpenLogFile(LogFile)
defer f.Close()
log.SetOutput(f)
case "tmptest":
log.Print("TEMPORARY TEST STARTED, log files are NOT redirecting!")
}
} else {
log.Print("Please enter a valid option !")
panic("Please enter a valid option !")
}
PluginManager()
log.Print("Plugin Manager Started Succesfully")
// NEXT Make PluginManager async !
}
// FIXME there isn't any difference with Stop() function
// TODO There can be a Start() function in it but start function doesnt work properly right now
// Restart ahenk daemon with a specific PID (running from second copy)
func Restart(pid, signal int) {
Stop(pid, signal)
}
// Stop ahenk daemon with a specific PID (running from second copy)
func Stop(pid, signal int) {
log.Println("Stop Signal Caught")
// FILLME what you want to do before stopping daemon?
if err := syscall.Kill(pid, syscall.Signal(signal)); err == nil {
log.Printf("Ahenk Daemon with pid number %v Successfully stopped", pid)
f := utils.OpenLogFile(LogFile)
defer f.Close()
log.SetOutput(f)
log.Printf("Ahenk Daemon with pid number %v Successfully stopped", pid)
} else {
log.Fatal(err)
}
os.Exit(0)
}

View file

@ -0,0 +1,39 @@
package main
import (
"fmt"
"time"
)
// plugins/resources
type Resources interface {
AgentInfo() map[string]interface{}
}
// type NewPluginInterface interface {
// PluginMethod() returnType
// }
// Loads Plugins and runs them.
// When you create a new plugin create a new interface and call this plugin in this function
func PluginManager() {
var resources Resources = LoadPlugin("resources").(Resources)
// var pluginName NewPluginInterface = LoadPlugin("pluginName").(NewPluginInterface)
for {
logPlugin("AgentInfo", resources.AgentInfo())
time.Sleep(30 * time.Second)
}
}
// Logs plugin outputs.
func logPlugin(title string, mp map[string]interface{}) {
fmt.Printf("\n----- %v -----\n", title)
for i, v := range mp {
fmt.Printf("%v: %v\n", i, v)
}
}
// // TODO response to Lider
// // func createResponse() {
// // }

View file

@ -0,0 +1,32 @@
package main
import (
"fmt"
"os"
"plugin"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
)
// Load Plugin placed in PluginDir, returns empty interface.
// Do not forget to cast in plugin manager
//
// Give Plugin Name as argument and be sure you compiled plugins with `-buildmode=plugin` to PluginDir as `pluginname.so`
func LoadPlugin(plugName string) interface{} {
// TODO if error caugth try without relative path, this will be good for local testing
plug, err := plugin.Open(PluginDir + plugName + ".so")
utils.Check(err)
// TODO also allow lookup another symbol other than PlugnameConnect
symPlug, err := plug.Lookup(utils.FirstUpperEN(plugName) + "Connect")
utils.Check(err)
var plugOut interface{}
plugOut, ok := symPlug.(interface{})
if !ok {
fmt.Println("unexpected type from module symbol")
os.Exit(1)
}
return plugOut
}

View file

@ -1,30 +0,0 @@
package main
import (
"ahenk-go/pkg/plugins/resources"
"fmt"
"log"
"time"
)
func PluginManager() {
log.Print("Plugin Manager Started")
for {
logPlugin(resources.AgentInfo())
time.Sleep(30 * time.Second)
}
}
func logPlugin(mp map[string]interface{}) {
fmt.Printf("\nOs Info:\n")
for i, v := range mp {
fmt.Printf("%v: %v\n", i, v)
}
}
// TODO response to Lider
// func createResponse() {
// }

View file

@ -7,8 +7,8 @@ After=network.target network-online.target
Type=forking
User=root
Group=root
ExecStart=/usr/bin/ahenkd-go start
ExecStop=/usr/bin/ahenkd-go stop
ExecStart=/usr/bin/ahenk-go start
ExecStop=/usr/bin/ahenk-go stop
ExecReload=kill -HUP $MAINPID
PIDFile=/run/ahenkd-go.pid
Restart=always

5
debian/changelog vendored Normal file
View file

@ -0,0 +1,5 @@
ahenk-go (0.0.1-1) UNRELEASED; urgency=low
* Initial release
-- Aliberk Sandıı <asandikci@aliberksandikci.com.tr> Mon, 21 Aug 2023 13:05:24 +0000

23
debian/control vendored Normal file
View file

@ -0,0 +1,23 @@
Source: ahenk-go
Maintainer: Aliberk Sandıı <asandikci@aliberksandikci.com.tr>
Section: utils
Testsuite: autopkgtest-pkg-go
Priority: optional
Build-Depends: debhelper (>= 13),
debhelper-compat (= 10),
Standards-Version: 4.6.0
Vcs-Browser: https://git.aliberksandikci.com.tr/Liderahenk/go-ahenk
Vcs-Git: https://git.aliberksandikci.com.tr/Liderahenk/go-ahenk.git
Homepage: https://liderahenk.org
Rules-Requires-Root: no
XS-Go-Import-Path: git.aliberksandikci.com.tr/Liderahenk/ahenk-go
Package: ahenk-go
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends}
Built-Using: ${misc:Built-Using}
Description: The client side of the Lider Ahenk Project
Lider Ahenk is an open source project which provides solutions
to manage, monitor and audit unlimited number of different
systems and users on a network.

13
debian/copyright vendored Normal file
View file

@ -0,0 +1,13 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ahenk-go
Upstream-Contact: Aliberk Sandıı <asandikci@aliberksandikci.com.tr>
Source: https://git.aliberksandikci.com.tr/Liderahenk/ahenk-go
Files: *
Copyright: 2023 Aliberk Sandıı <asandikci@aliberksandikci.com.tr>
License: LGPL-3.0+
Files: debian/*
Copyright: 2023 Aliberk Sandıı <asandikci@aliberksandikci.com.tr>
License: LGPL-3.0+
Comment: Debian packaging is licensed under the same terms as upstream

8
debian/rules vendored Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/make -f
%:
dh $@
override_dh_auto_install:
dh_auto_install
dh_installsystemd

3
go.mod
View file

@ -1,4 +1,4 @@
module ahenk-go
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go
go 1.20
@ -10,6 +10,7 @@ require (
require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/text v0.12.0 // indirect
)
require (

2
go.sum
View file

@ -38,6 +38,8 @@ golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View file

@ -1,10 +1,11 @@
package osinfo
import (
"ahenk-go/pkg/utils"
"syscall"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
)
const KB = uint64(1024)
@ -35,8 +36,10 @@ func GetDisks() []disk.PartitionStat {
return parts
}
// return disk usage as MiB
// TODO different function for all disks / a specified disk?
// return disk usage as GiB
//
// TODO different functions for all disks / a specified disk?
// FIXME Wrong Disk values for docker !!! (probably because counting also virtual mountpoints?)
func GetDiskUsage() map[string]float64 {
var totalSize, freeSize, usedSize uint64
for _, part := range GetDisks() {
@ -52,3 +55,17 @@ func GetDiskUsage() map[string]float64 {
"used": utils.Byte2GiB(usedSize),
}
}
// return memory usage as GiB
//
// TODO also implement swap usage
func GetMemoryUsage() map[string]float64 {
v, _ := mem.VirtualMemory()
return map[string]float64{
"total": utils.Byte2GiB(v.Total),
"free": utils.Byte2GiB(v.Free),
"used": utils.Byte2GiB(v.Used),
"avaliable": utils.Byte2GiB(v.Available),
"cached": utils.Byte2GiB(v.Cached),
}
}

View file

@ -3,6 +3,9 @@ package utils
import (
"log"
"os"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func Byte2String(arr []int8) string {
@ -47,3 +50,16 @@ func Check(err error) {
panic(err)
}
}
func OpenLogFile(path string) *os.File {
f, err := os.OpenFile(path, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
if err != nil {
panic(err)
}
return f
}
// Makes first character uppercase of given English string
func FirstUpperEN(str string) string {
return cases.Title(language.English).String(str)
} // TODO cases.NoLower vs cases.Compact !

View file

@ -1,10 +1,16 @@
package resources
package main
import (
"ahenk-go/pkg/osinfo"
"runtime"
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/osinfo"
)
type plug string
// exported plugin Symbol
var ResourcesConnect plug
// return instant resource usage information
func ResourceUsage() map[string]string {
data := map[string]string{
@ -27,28 +33,33 @@ func ResourceUsage() map[string]string {
}
// return general Agent information (that changes rarely)
func AgentInfo() map[string]interface{} {
func (p plug) AgentInfo() map[string]interface{} {
data := map[string]interface{}{
"System": runtime.GOOS, "Release": osinfo.GetKernelInfo()["Release"],
"System": runtime.GOOS, "Kernel": osinfo.GetKernelInfo()["Release"],
"hostname": osinfo.GetKernelInfo()["Hostname"],
"osMachine": osinfo.GetKernelInfo()["Machine"],
"diskTotal": osinfo.GetDiskUsage()["total"],
"diskUsed": osinfo.GetDiskUsage()["used"],
"diskFree": osinfo.GetDiskUsage()["free"],
"diskUsage": osinfo.GetDiskUsage()["used"] / osinfo.GetDiskUsage()["total"],
"memoryTotal": osinfo.GetMemoryUsage()["total"],
"memoryFree": osinfo.GetMemoryUsage()["free"],
"memoryAvaliable": osinfo.GetMemoryUsage()["avaliable"],
"memoryUsed": osinfo.GetMemoryUsage()["used"],
"memoryCached": osinfo.GetMemoryUsage()["cached"],
"memoryUsage": (osinfo.GetMemoryUsage()["used"] + osinfo.GetMemoryUsage()["cached"]) / osinfo.GetMemoryUsage()["total"], //REVIEW just used/total ?
// TODO is calling all functions one by one slow downs code?
// TODO 'agentVersion': self.get_agent_version(),
"hostname": osinfo.GetKernelInfo()["Hostname"],
// TODO 'ipAddresses': str(self.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''),
// "osName": osinfo.GetKernelInfo()["Sysname"], // TODO is it necessary?
// "osNodeName": osinfo.GetKernelInfo()["NodeName"],// TODO is it necessary?
// "osVersion": osinfo.GetKernelInfo()["Version"], // TODO is it necessary?
"osMachine": osinfo.GetKernelInfo()["Machine"],
// TODO get distrubition name also (pardus,arch,debian,windows10 for example ...)
// TODO get distrubition name also (pardus,arch,debian,windows10 for example ...)
// TODO 'macAddresses': str(self.Hardware.Network.mac_addresses()).replace('[', '').replace(']', ''),
// TODO 'hardware.systemDefinitions': self.Hardware.system_definitions(),
// TODO 'hardware.monitors': self.Hardware.monitors(),
// TODO 'hardware.screens': self.Hardware.screens(),
// TODO 'hardware.usbDevices': self.Hardware.usb_devices(),
// TODO 'hardware.printers': self.Hardware.printers(),
"diskTotal": osinfo.GetDiskUsage()["total"],
"diskUsed": osinfo.GetDiskUsage()["used"],
"diskFree": osinfo.GetDiskUsage()["free"],
// TODO "diskUsage": osinfo.GetDiskUsage()["Usage"],
// TODO 'memory': self.Hardware.Memory.total(),
// TODO 'Device': device,
}
return data
@ -57,13 +68,9 @@ func AgentInfo() map[string]interface{} {
func Info() map[string]string {
inf := make(map[string]string)
inf["name"] = "resources"
inf["version"] = "0.0.1"
inf["version"] = "0.0.2"
inf["support"] = "debian"
inf["description"] = "Resource Usage Information and Controls"
inf["developer"] = "asandikci@aliberksandikci.com.tr"
// inf["task"] = "true"
// inf["user_oriented"] = "false"
// inf["machine_oriented"] = "false"
return inf
}

View file

@ -1,92 +0,0 @@
#!/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ıı"
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"

View file

@ -1,68 +0,0 @@
#!/bin/bash
### Ahenk Agent Local Installation Script
### --> 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"

View file

@ -1,3 +0,0 @@
#!/bin/bash
sudo go build -o "build/package/bin/ahenkd-go" cmd/ahenkd-go/ahenkd-go.go

View file

@ -1,67 +0,0 @@
#!/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"