mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 22:01:15 +02:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ac5d9a677 | ||
|
|
f0bfc92295 |
@@ -15,14 +15,14 @@ jobs:
|
|||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: '1.20.2'
|
go-version: ^1.15
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make build
|
run: make build
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test-with-coverage
|
run: make test-with-coverage
|
||||||
# - uses: codecov/codecov-action@v1
|
- uses: codecov/codecov-action@v1
|
||||||
# with:
|
with:
|
||||||
# token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
# files: coverage.out
|
files: coverage.out
|
||||||
|
|||||||
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
FROM golang:1.20.2
|
FROM golang:latest
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY ./ /app
|
COPY ./ /app
|
||||||
|
|
||||||
RUN go install github.com/githubnemo/CompileDaemon@latest
|
RUN go mod download
|
||||||
|
|
||||||
ENTRYPOINT CompileDaemon --build="make build" --command=./bin/edgeboxctl-$(go env GOOS)-$(go env GOARCH)
|
RUN go get github.com/githubnemo/CompileDaemon
|
||||||
|
|
||||||
|
ENTRYPOINT CompileDaemon --build="make build" --command=./bin/edgeboxctl
|
||||||
@@ -1,18 +1,29 @@
|
|||||||
.DEFAULT_GOAL := build
|
PROJECT?=github.com/edgebox-iot/edgeboxctl
|
||||||
|
|
||||||
PROJECT ?= github.com/edgebox-iot/edgeboxctl
|
|
||||||
RELEASE ?= dev
|
RELEASE ?= dev
|
||||||
COMMIT := $(shell git rev-parse --short HEAD)
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
|
||||||
BUILD_DIR = bin
|
BUILD_DIR = bin
|
||||||
GOOS := $(shell go env GOOS)
|
|
||||||
GOARCH := $(shell go env GOARCH)
|
|
||||||
|
|
||||||
|
build-all:
|
||||||
build-all: clean
|
|
||||||
GOOS=linux GOARCH=amd64 make build
|
GOOS=linux GOARCH=amd64 make build
|
||||||
GOOS=linux GOARCH=arm make build
|
GOOS=linux GOARCH=arm make build
|
||||||
GOOS=linux GOARCH=arm64 make build
|
|
||||||
|
build-prod:
|
||||||
|
GOOS=linux GOARCH=arm RELEASE=prod make build
|
||||||
|
|
||||||
|
build-cloud:
|
||||||
|
GOOS=linux GOARCH=amd64 RELEASE=cloud make build
|
||||||
|
|
||||||
|
build-arm64:
|
||||||
|
GOOS=linux GOARCH=arm64 RELEASE=prod make build
|
||||||
|
|
||||||
|
build-armhf:
|
||||||
|
GOOS=linux GOARCH=arm RELEASE=prod make build
|
||||||
|
|
||||||
|
build-amd64:
|
||||||
|
GOOS=linux GOARCH=amd64 RELEASE=prod make build
|
||||||
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@echo "Building ${GOOS}-${GOARCH}"
|
@echo "Building ${GOOS}-${GOARCH}"
|
||||||
@@ -21,6 +32,7 @@ build:
|
|||||||
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
|
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
|
||||||
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE}" \
|
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE}" \
|
||||||
-o bin/edgeboxctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/edgeboxctl
|
-o bin/edgeboxctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/edgeboxctl
|
||||||
|
cp ./bin/edgeboxctl-${GOOS}-${GOARCH} ./bin/edgeboxctl
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${BUILD_DIR}
|
rm -rf ${BUILD_DIR}
|
||||||
@@ -35,14 +47,18 @@ test-with-coverage:
|
|||||||
install:
|
install:
|
||||||
sudo systemctl stop edgeboxctl || true
|
sudo systemctl stop edgeboxctl || true
|
||||||
sudo rm -rf /usr/local/bin/edgeboxctl /usr/local/sbin/edgeboctl /lib/systemd/system/edgeboxctl.service
|
sudo rm -rf /usr/local/bin/edgeboxctl /usr/local/sbin/edgeboctl /lib/systemd/system/edgeboxctl.service
|
||||||
sudo cp ./bin/edgeboxctl-${GOOS}-${GOARCH} /usr/local/bin/edgeboxctl
|
sudo cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
||||||
sudo cp ./bin/edgeboxctl-${GOOS}-${GOARCH} /usr/local/sbin/edgeboxctl
|
sudo cp ./bin/edgeboxctl /usr/local/sbin/edgeboxctl
|
||||||
sudo cp ./edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
sudo cp ./edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
||||||
sudo systemctl daemon-reload
|
sudo systemctl daemon-reload
|
||||||
@echo "Edgeboxctl installed successfully"
|
@echo "Edgeboxctl installed successfully"
|
||||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
||||||
|
|
||||||
build-install: build install
|
install-prod: build-prod install
|
||||||
|
install-cloud: build-cloud install
|
||||||
|
install-arm64: build-arm64 install
|
||||||
|
install-armhf: build-armhf install
|
||||||
|
install-amd64: build-amd64 install
|
||||||
|
|
||||||
start:
|
start:
|
||||||
systemctl start edgeboxctl
|
systemctl start edgeboxctl
|
||||||
@@ -52,3 +68,4 @@ stop:
|
|||||||
|
|
||||||
log: start
|
log: start
|
||||||
journalctl -fu edgeboxctl
|
journalctl -fu edgeboxctl
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<h3 align="center">Edgebox Control Module</h3>
|
<h3 align="center">Edgebox Control Module</h3>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
A System Control module written in Go. Its responsibility is to configure dependencies and perform system tasks, automatically on a schedule, or on demand.
|
A System Control module written in Go. Its resonsability is to configure dependencies and perform system tasks, automatically in a schedule, or by command.
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<a href="https://github.com/github_username/edgeboxctl/issues">Report Bug</a>
|
<a href="https://github.com/github_username/edgeboxctl/issues">Report Bug</a>
|
||||||
@@ -38,6 +38,8 @@
|
|||||||
<!-- ABOUT THE PROJECT -->
|
<!-- ABOUT THE PROJECT -->
|
||||||
## About The Project
|
## About The Project
|
||||||
|
|
||||||
|
[![Edgebox Screen Shot][product-screenshot]](https://edgebox.co)
|
||||||
|
|
||||||
Edgebox is an easy to configure and use system. It brings powerful features that go alongside or can even completely replace various services that you already use in the day-to-day.
|
Edgebox is an easy to configure and use system. It brings powerful features that go alongside or can even completely replace various services that you already use in the day-to-day.
|
||||||
|
|
||||||
|
|
||||||
@@ -56,15 +58,18 @@ To get a local copy up and running follow these simple steps.
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
If you're running for development purposes, a docker container suffices, so make sure you have:
|
If you're installing this to run natively in the system, you better be doing it inside of the [Development Virtual Machine](https://github.com/edgebox-iot/devm). This software can do destructive action in the system is is running. You've been warned.
|
||||||
|
|
||||||
* docker
|
If you're running for development purposes, a Docker container suffices, so make sure you have:
|
||||||
* docker compose
|
* Docker
|
||||||
|
* Docker Compose
|
||||||
|
```sh
|
||||||
|
sudo apt-get install docker docker-compose
|
||||||
|
```
|
||||||
|
|
||||||
Check the following links for more info on [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/).
|
Check the following links for more info on [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/).
|
||||||
|
|
||||||
Aditionally, `edgeboxctl` needs the following bash commands available wherever it runs:
|
Aditionally, edgeboxctl needs the following bash commands available wherever it runs:
|
||||||
|
|
||||||
* `arm-linux-gnueabi-gcc` (`sudo apt-get install gcc-arm*`)
|
* `arm-linux-gnueabi-gcc` (`sudo apt-get install gcc-arm*`)
|
||||||
* `sh`
|
* `sh`
|
||||||
* `rm`
|
* `rm`
|
||||||
@@ -116,4 +121,4 @@ Contributions are what make the open source community such an amazing place to b
|
|||||||
<!-- LICENSE -->
|
<!-- LICENSE -->
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Distributed under the Elastic License 2.0. See `LICENSE` for more information.
|
Distributed under the MIT License. See `LICENSE` for more information.
|
||||||
|
|||||||
+2
-3
@@ -1,4 +1,3 @@
|
|||||||
codecov:
|
|
||||||
require_ci_to_pass: no
|
|
||||||
|
|
||||||
comment: false
|
comment: false
|
||||||
|
github_checks:
|
||||||
|
annotations: false
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
package diagnostics
|
package diagnostics
|
||||||
|
|
||||||
|
type ReleaseVersion string
|
||||||
|
|
||||||
var Version string
|
var Version string
|
||||||
var Commit string
|
var Commit string
|
||||||
var BuildDate string
|
var BuildDate string
|
||||||
|
|
||||||
|
const (
|
||||||
|
DEV_VERSION ReleaseVersion = "dev"
|
||||||
|
PROD_VERSION ReleaseVersion = "prod"
|
||||||
|
CLOUD_VERSION ReleaseVersion = "cloud"
|
||||||
|
OTHER_VERSION ReleaseVersion = "other"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetReleaseVersion() ReleaseVersion {
|
||||||
|
return ReleaseVersion(Version)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||||
"github.com/shirou/gopsutil/disk"
|
"github.com/shirou/gopsutil/disk"
|
||||||
)
|
)
|
||||||
@@ -74,9 +75,20 @@ const (
|
|||||||
DISK_TYPE_VDA DeviceIdentifier = "vda"
|
DISK_TYPE_VDA DeviceIdentifier = "vda"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetDeviceIdentifier(release_version diagnostics.ReleaseVersion) DeviceIdentifier {
|
||||||
|
switch release_version {
|
||||||
|
case diagnostics.CLOUD_VERSION:
|
||||||
|
return DISK_TYPE_VDA
|
||||||
|
case diagnostics.PROD_VERSION:
|
||||||
|
return DISK_TYPE_MCBLK
|
||||||
|
}
|
||||||
|
|
||||||
|
return DISK_TYPE_SDA
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDevices : Returns a list of all available sotrage devices in structs filled with information
|
||||||
|
func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||||
|
|
||||||
// GetDevices : Returns a list of all available storage devices in structs filled with information
|
|
||||||
func GetDevices() []Device {
|
|
||||||
var devices []Device
|
var devices []Device
|
||||||
|
|
||||||
cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
|
cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
|
||||||
@@ -88,6 +100,8 @@ func GetDevices() []Device {
|
|||||||
firstDevice := true
|
firstDevice := true
|
||||||
currentDeviceInUseFlag := false
|
currentDeviceInUseFlag := false
|
||||||
|
|
||||||
|
mainDiskID := GetDeviceIdentifier(release_version)
|
||||||
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
// 1 Device is represented here. Extract words in order for filling a Device struct
|
// 1 Device is represented here. Extract words in order for filling a Device struct
|
||||||
// Example deviceRawInfo: "mmcblk0 179:0 0 29.7G 0 disk"
|
// Example deviceRawInfo: "mmcblk0 179:0 0 29.7G 0 disk"
|
||||||
@@ -139,9 +153,14 @@ func GetDevices() []Device {
|
|||||||
Status: DeviceStatus{ID: 1, Description: "healthy"},
|
Status: DeviceStatus{ID: 1, Description: "healthy"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if device.ID == mainDiskID {
|
||||||
|
device.MainDevice = true
|
||||||
|
}
|
||||||
|
|
||||||
currentDevice = device
|
currentDevice = device
|
||||||
|
|
||||||
} else if isPartition {
|
} else if isPartition {
|
||||||
|
|
||||||
mountpoint := ""
|
mountpoint := ""
|
||||||
if len(deviceRawInfo) >= 7 {
|
if len(deviceRawInfo) >= 7 {
|
||||||
mountpoint = deviceRawInfo[6]
|
mountpoint = deviceRawInfo[6]
|
||||||
|
|||||||
@@ -7,7 +7,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGetDevices(t *testing.T) {
|
func TestGetDevices(t *testing.T) {
|
||||||
assertGetDevices(GetDevices(), t)
|
|
||||||
|
t.Log("Testing with release version dev")
|
||||||
|
assertGetDevices(GetDevices("dev"), t)
|
||||||
|
t.Log("Testing with release version prod")
|
||||||
|
assertGetDevices(GetDevices("prod"), t)
|
||||||
|
t.Log("Testing with release version cloud")
|
||||||
|
assertGetDevices(GetDevices("cloud"), t)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertGetDevices(devices []Device, t *testing.T) {
|
func assertGetDevices(devices []Device, t *testing.T) {
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ func SetupCloudOptions() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error loading .env file for cloud version setup")
|
fmt.Println("Error loading .env file for cloud version setup")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cloudEnv["NAME"] != "" {
|
if cloudEnv["NAME"] != "" {
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ func ExecuteTask(task Task) Task {
|
|||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if diagnostics.GetReleaseVersion() == diagnostics.DEV_VERSION {
|
||||||
|
log.Printf("Dev environemnt. Not executing tasks.")
|
||||||
|
} else {
|
||||||
log.Println("Task: " + task.Task)
|
log.Println("Task: " + task.Task)
|
||||||
log.Println("Args: " + task.Args.String)
|
log.Println("Args: " + task.Args.String)
|
||||||
switch task.Task {
|
switch task.Task {
|
||||||
@@ -363,8 +366,10 @@ func ExecuteTask(task Task) Task {
|
|||||||
log.Println("Disabling online access to Dashboard...")
|
log.Println("Disabling online access to Dashboard...")
|
||||||
taskResult := taskDisablePublicDashboard()
|
taskResult := taskDisablePublicDashboard()
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
statement, err = db.Prepare("Update task SET status = ?, result = ?, updated = ? WHERE ID = ?;") // Prepare SQL Statement
|
statement, err = db.Prepare("Update task SET status = ?, result = ?, updated = ? WHERE ID = ?;") // Prepare SQL Statement
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -422,9 +427,10 @@ func ExecuteSchedules(tick int) {
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if diagnostics.GetReleaseVersion() == diagnostics.CLOUD_VERSION {
|
||||||
log.Println("Setting up cloud version options (name, email, api token)")
|
log.Println("Setting up cloud version options (name, email, api token)")
|
||||||
taskSetupCloudOptions()
|
taskSetupCloudOptions()
|
||||||
|
}
|
||||||
|
|
||||||
// Executing on startup (first tick). Schedules run before tasks in the SystemIterator
|
// Executing on startup (first tick). Schedules run before tasks in the SystemIterator
|
||||||
uptime := taskGetSystemUptime()
|
uptime := taskGetSystemUptime()
|
||||||
@@ -1190,7 +1196,7 @@ func taskGetSystemUptime() string {
|
|||||||
func taskGetStorageDevices() string {
|
func taskGetStorageDevices() string {
|
||||||
fmt.Println("Executing taskGetStorageDevices")
|
fmt.Println("Executing taskGetStorageDevices")
|
||||||
|
|
||||||
devices := storage.GetDevices()
|
devices := storage.GetDevices(diagnostics.GetReleaseVersion())
|
||||||
devicesJSON, _ := json.Marshal(devices)
|
devicesJSON, _ := json.Marshal(devices)
|
||||||
|
|
||||||
utils.WriteOption("STORAGE_DEVICES_LIST", string(devicesJSON))
|
utils.WriteOption("STORAGE_DEVICES_LIST", string(devicesJSON))
|
||||||
|
|||||||
Reference in New Issue
Block a user