mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-24 05:41:43 +02:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cb36dff1e | ||
|
|
03f7ac8468 |
@@ -13,11 +13,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20.2'
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: make build
|
||||
- name: Test
|
||||
|
||||
Vendored
-236
@@ -1,236 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build All",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-all"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build Prod",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-prod"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build Cloud",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-cloud"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build ARM64",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-arm64"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build ARMHF",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-armhf"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Build AMD64",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["build-amd64"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"group": "build",
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Clean",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["clean"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Test",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["test"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Test with Coverage",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["test-with-coverage"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Run",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["run"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install Prod",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install-prod"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install Cloud",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install-cloud"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install ARM64",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install-arm64"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install ARMHF",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install-armhf"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Install AMD64",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["install-amd64"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Start",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["start"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Stop",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["stop"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Restart",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["restart"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Status",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["status"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
},
|
||||
{
|
||||
"label": "Logs",
|
||||
"type": "shell",
|
||||
"command": "make",
|
||||
"args": ["log"],
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
"problemMatcher": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## [1.3.2] - 08-12-2024
|
||||
|
||||
* Fix to Browser Dev feature:
|
||||
* Checking browser dev url when internet_accessible was checking the incorrect path. This is now fixed.
|
||||
|
||||
## [1.3.1] - 08-12-2024
|
||||
|
||||
* Fixes to Browser Dev feature:
|
||||
* Now edgeboxctl also fetches or generates the browser dev environment url and saves it into an option both when starting, and every time the browser dev status is fetched.
|
||||
|
||||
## [1.3.0] - 05-12-2024
|
||||
|
||||
* Added Edgebox Browser Development Environment Feature Support
|
||||
* Added tasks for handling browser development environment into tasks.go
|
||||
* Added executable tasks to ExecuteTask and scheduled ones to ExecuteSchedules
|
||||
* Other bug fixes and improvements.
|
||||
|
||||
### Missing Past Releases
|
||||
|
||||
Release notes for past versions are not available in this file. Please refer to the [GitHub releases](https://hithub.com/edgebox-iot/edgeboxctl/releases) for more information. Feel free to contribute to this file by adding missing release notes.
|
||||
|
||||
@@ -9,106 +9,46 @@ GOOS := $(shell go env GOOS)
|
||||
GOARCH := $(shell go env GOARCH)
|
||||
|
||||
|
||||
build-all:
|
||||
@echo "\n🏗️ Building all architectures for ${RELEASE} mode"
|
||||
@echo "🟡 This will build all supported architectures and release combinations. It can take a while...\n"
|
||||
|
||||
build-all: clean
|
||||
GOOS=linux GOARCH=amd64 make build
|
||||
GOOS=linux GOARCH=arm make build
|
||||
|
||||
@echo "\n🟢 All builds completed and available at ./bin/ \n"
|
||||
|
||||
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
|
||||
|
||||
GOOS=linux GOARCH=arm64 make build
|
||||
|
||||
build:
|
||||
@echo "\n🏗️ Building edgeboxctl (${RELEASE} release) on ${GOOS} (${GOARCH})"
|
||||
@echo "📦 Binary will be saved in ./${BUILD_DIR}/edgeboxctl-${GOOS}-${GOARCH}\n"
|
||||
|
||||
@echo "Building ${GOOS}-${GOARCH}"
|
||||
GOOS=${GOOS} GOARCH=${GOARCH} go build \
|
||||
-trimpath -ldflags "-s -w -X ${PROJECT}/internal/diagnostics.Version=${RELEASE} \
|
||||
-X ${PROJECT}/internal/diagnostics.Commit=${COMMIT} \
|
||||
-X ${PROJECT}/internal/diagnostics.BuildDate=${BUILD_DATE}" \
|
||||
-o bin/edgeboxctl-${GOOS}-${GOARCH} ${PROJECT}/cmd/edgeboxctl
|
||||
|
||||
@echo "\n🟢 Build task completed\n"
|
||||
|
||||
clean:
|
||||
@echo "🧹 Cleaning build directory and go cache\n"
|
||||
|
||||
rm -rf ${BUILD_DIR}
|
||||
go clean
|
||||
|
||||
@echo "\n🟢 Clean task completed\n"
|
||||
|
||||
test:
|
||||
go test -tags=unit -timeout=600s -v ./...
|
||||
|
||||
test-with-coverage:
|
||||
go test -tags=unit -timeout=600s -v ./... -coverprofile=coverage.out
|
||||
|
||||
run:
|
||||
@echo "\n🚀 Running edgeboxctl\n"
|
||||
./bin/edgeboxctl-${GOOS}-${GOARCH}
|
||||
|
||||
install:
|
||||
@echo "📦 Installing edgeboxctl service (${RELEASE}) for ${GOOS} (${GOARCH})\n"
|
||||
|
||||
@echo "�🚧 Stopping edgeboxctl service if it is running"
|
||||
sudo systemctl stop edgeboxctl || true
|
||||
|
||||
@echo "\n🗑️ Removing old edgeboxctl binary and service"
|
||||
sudo rm -rf /usr/local/bin/edgeboxctl /usr/local/sbin/edgeboctl /lib/systemd/system/edgeboxctl.service
|
||||
|
||||
@echo "\n🚚 Copying edgeboxctl binary to /usr/local/bin"
|
||||
sudo cp ./bin/edgeboxctl-${GOOS}-${GOARCH} /usr/local/bin/edgeboxctl
|
||||
sudo cp ./bin/edgeboxctl-${GOOS}-${GOARCH} /usr/local/sbin/edgeboxctl
|
||||
|
||||
@echo "\n🚚 Copying edgeboxctl service to /lib/systemd/system"
|
||||
sudo cp ./edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
||||
sudo systemctl daemon-reload
|
||||
@echo "Edgeboxctl installed successfully"
|
||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
||||
|
||||
@echo "\n 🚀 To start edgeboxctl run: make start"
|
||||
@echo "🟢 Edgeboxctl installed successfully\n"
|
||||
|
||||
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
|
||||
build-install: build install
|
||||
|
||||
start:
|
||||
@echo "\n 🚀 Starting edgeboxctl service\n"
|
||||
systemctl start edgeboxctl
|
||||
@echo "\n 🟢 Edgebox service started\n"
|
||||
|
||||
stop:
|
||||
@echo "\n✋ Stopping edgeboxctl service\n"
|
||||
systemctl stop edgeboxctl
|
||||
@echo "\n 🟢 Edgebox service stopped\n"
|
||||
|
||||
restart:
|
||||
@echo "\n💫 Restarting edgeboxctl service\n"
|
||||
systemctl restart edgeboxctl
|
||||
@echo "\n 🟢 Edgebox service restarted\n"
|
||||
|
||||
status:
|
||||
@echo "\nℹ️ edgeboxctl Service Info:\n"
|
||||
systemctl status edgeboxctl
|
||||
|
||||
log:
|
||||
@echo "\n📰 edgeboxctl service logs:\n"
|
||||
log: start
|
||||
journalctl -fu edgeboxctl
|
||||
|
||||
@@ -59,12 +59,10 @@ To get a local copy up and running follow these simple steps.
|
||||
If you're running for development purposes, a docker container suffices, so make sure you have:
|
||||
|
||||
* docker
|
||||
* docker compose (docker-compose-v2 package)
|
||||
* docker compose
|
||||
|
||||
Check the following links for more info on [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/).
|
||||
|
||||
**Note:** If you don't have `docker compose` available, install it with: `sudo apt-get install docker-compose-v2`
|
||||
|
||||
Aditionally, `edgeboxctl` needs the following bash commands available wherever it runs:
|
||||
|
||||
* `arm-linux-gnueabi-gcc` (`sudo apt-get install gcc-arm*`)
|
||||
@@ -81,10 +79,10 @@ Aditionally, `edgeboxctl` needs the following bash commands available wherever i
|
||||
```sh
|
||||
git clone https://github.com/edgebox-iot/edgeboxctl.git
|
||||
```
|
||||
2. Run Docker Compose
|
||||
|
||||
2. Run Docker-Compose
|
||||
```sh
|
||||
docker-compose up
|
||||
```
|
||||
docker compose up
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ require (
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||
github.com/go-sql-driver/mysql v1.5.0
|
||||
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
||||
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
||||
|
||||
@@ -11,8 +11,6 @@ github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
|
||||
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
package diagnostics
|
||||
|
||||
type ReleaseVersion string
|
||||
|
||||
var Version string
|
||||
var Commit 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)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/system"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
)
|
||||
|
||||
// EdgeApp : Struct representing an EdgeApp in the system
|
||||
@@ -19,7 +18,6 @@ type EdgeApp struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Experimental bool `json:"experimental"`
|
||||
Status EdgeAppStatus `json:"status"`
|
||||
Services []EdgeAppService `json:"services"`
|
||||
InternetAccessible bool `json:"internet_accessible"`
|
||||
@@ -71,7 +69,6 @@ const optionsEnvFilename = "/edgeapp.env"
|
||||
const authEnvFilename = "/auth.env"
|
||||
const runnableFilename = "/.run"
|
||||
const appdataFoldername = "/appdata"
|
||||
const postInstallFilename = "/edgebox-postinstall.done"
|
||||
const myEdgeAppServiceEnvFilename = "/myedgeapp.env"
|
||||
const defaultContainerOperationSleepTime time.Duration = time.Second * 10
|
||||
|
||||
@@ -89,7 +86,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
||||
|
||||
edgeAppName := ID
|
||||
edgeAppDescription := ""
|
||||
edgeAppExperimental := false
|
||||
edgeAppOptions := []EdgeAppOption{}
|
||||
|
||||
edgeAppEnv, err := godotenv.Read(utils.GetPath(utils.EdgeAppsPath) + ID + envFilename)
|
||||
@@ -103,9 +99,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
||||
if edgeAppEnv["EDGEAPP_DESCRIPTION"] != "" {
|
||||
edgeAppDescription = edgeAppEnv["EDGEAPP_DESCRIPTION"]
|
||||
}
|
||||
if edgeAppEnv["EDGEAPP_EXPERIMENTAL"] == "true" {
|
||||
edgeAppExperimental = true
|
||||
}
|
||||
}
|
||||
|
||||
needsConfig := false
|
||||
@@ -238,7 +231,6 @@ func GetEdgeApp(ID string) MaybeEdgeApp {
|
||||
ID: ID,
|
||||
Name: edgeAppName,
|
||||
Description: edgeAppDescription,
|
||||
Experimental: edgeAppExperimental,
|
||||
Status: GetEdgeAppStatus(ID),
|
||||
Services: GetEdgeAppServices(ID),
|
||||
InternetAccessible: edgeAppInternetAccessible,
|
||||
@@ -271,54 +263,22 @@ func IsEdgeAppInstalled(ID string) bool {
|
||||
|
||||
}
|
||||
|
||||
func writeAppRunnableFiles(ID string) bool {
|
||||
edgeAppPath := utils.GetPath(utils.EdgeAppsPath)
|
||||
_, err := os.Stat(edgeAppPath + ID + runnableFilename)
|
||||
if os.IsNotExist(err) {
|
||||
_, err := os.Create(edgeAppPath + ID + runnableFilename)
|
||||
if err != nil {
|
||||
log.Fatal("Runnable file for EdgeApp could not be created!")
|
||||
return false
|
||||
}
|
||||
|
||||
// Check the block default apps option
|
||||
blockDefaultAppsOption := utils.ReadOption("DASHBOARD_BLOCK_DEFAULT_APPS_PUBLIC_ACCESS")
|
||||
if blockDefaultAppsOption != "yes" {
|
||||
// Create myedgeapp.env file with default network URL
|
||||
envFilePath := edgeAppPath + ID + myEdgeAppServiceEnvFilename
|
||||
|
||||
var networkURL string
|
||||
domainName := utils.ReadOption("DOMAIN_NAME")
|
||||
|
||||
if domainName != "" {
|
||||
networkURL = ID + "." + domainName
|
||||
} else if diagnostics.GetReleaseVersion() == diagnostics.CLOUD_VERSION {
|
||||
cluster := utils.ReadOption("CLUSTER")
|
||||
username := utils.ReadOption("USERNAME")
|
||||
if cluster != "" && username != "" {
|
||||
networkURL = username + "-" + ID + "." + cluster
|
||||
}
|
||||
} else {
|
||||
networkURL = ID + "." + system.GetHostname() + ".local" // default
|
||||
}
|
||||
|
||||
env, _ := godotenv.Unmarshal("INTERNET_URL=" + networkURL)
|
||||
err = godotenv.Write(env, envFilePath)
|
||||
if err != nil {
|
||||
log.Printf("Error creating myedgeapp.env file: %s", err)
|
||||
// result = false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func SetEdgeAppInstalled(ID string) bool {
|
||||
|
||||
result := true
|
||||
edgeAppPath := utils.GetPath(utils.EdgeAppsPath)
|
||||
|
||||
_, err := os.Stat(edgeAppPath + ID + runnableFilename)
|
||||
if os.IsNotExist(err) {
|
||||
|
||||
_, err := os.Create(edgeAppPath + ID + runnableFilename)
|
||||
result = true
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("Runnable file for EdgeApp could not be created!")
|
||||
result = false
|
||||
}
|
||||
|
||||
if writeAppRunnableFiles(ID) {
|
||||
|
||||
buildFrameworkContainers()
|
||||
|
||||
} else {
|
||||
@@ -332,21 +292,6 @@ func SetEdgeAppInstalled(ID string) bool {
|
||||
|
||||
}
|
||||
|
||||
func SetEdgeAppBulkInstalled(IDs []string) bool {
|
||||
|
||||
result := true
|
||||
|
||||
for _, ID := range IDs {
|
||||
writeAppRunnableFiles(ID)
|
||||
}
|
||||
|
||||
buildFrameworkContainers()
|
||||
|
||||
return result
|
||||
|
||||
}
|
||||
|
||||
|
||||
func SetEdgeAppNotInstalled(ID string) bool {
|
||||
|
||||
// Stop the app first
|
||||
@@ -385,12 +330,6 @@ func SetEdgeAppNotInstalled(ID string) bool {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
err = os.Remove(utils.GetPath(utils.EdgeAppsPath) + ID + postInstallFilename)
|
||||
if err != nil {
|
||||
result = false
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
buildFrameworkContainers()
|
||||
|
||||
return result
|
||||
@@ -477,24 +416,12 @@ func GetEdgeAppServices(ID string) []EdgeAppService {
|
||||
var edgeAppServices []EdgeAppService
|
||||
|
||||
for _, serviceID := range serviceSlices {
|
||||
shouldBeRunning := false
|
||||
cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "exec", "-T", serviceID, "echo", "'Service Check'"}
|
||||
cmdResult := utils.Exec(wsPath, "docker-compose", cmdArgs)
|
||||
isRunning := false
|
||||
|
||||
// Is service "runnable" when .run lockfile in the app folder
|
||||
_, err := os.Stat(utils.GetPath(utils.EdgeAppsPath) + ID + runnableFilename)
|
||||
if !os.IsNotExist(err) {
|
||||
shouldBeRunning = true
|
||||
if cmdResult != "" {
|
||||
isRunning = true
|
||||
}
|
||||
|
||||
// Check if the service is actually running
|
||||
if shouldBeRunning {
|
||||
cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "exec", "-T", serviceID, "echo", "'Service Check'"}
|
||||
cmdResult := utils.Exec(wsPath, "docker", append([]string{"compose"}, cmdArgs...))
|
||||
if cmdResult != "" {
|
||||
isRunning = true
|
||||
}
|
||||
}
|
||||
|
||||
edgeAppServices = append(edgeAppServices, EdgeAppService{ID: serviceID, IsRunning: isRunning})
|
||||
}
|
||||
|
||||
@@ -511,7 +438,7 @@ func RunEdgeApp(ID string) EdgeAppStatus {
|
||||
for _, service := range services {
|
||||
|
||||
cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "start", service.ID}
|
||||
utils.Exec(wsPath, "docker", append([]string{"compose"}, cmdArgs...))
|
||||
utils.Exec(wsPath, "docker-compose", cmdArgs)
|
||||
}
|
||||
|
||||
// Wait for it to settle up before continuing...
|
||||
@@ -529,7 +456,7 @@ func StopEdgeApp(ID string) EdgeAppStatus {
|
||||
for _, service := range services {
|
||||
|
||||
cmdArgs = []string{"-f", wsPath + "/docker-compose.yml", "stop", service.ID}
|
||||
utils.Exec(wsPath, "docker", append([]string{"compose"}, cmdArgs...))
|
||||
utils.Exec(wsPath, "docker-compose", cmdArgs)
|
||||
}
|
||||
|
||||
// Wait for it to settle up before continuing...
|
||||
|
||||
@@ -2,12 +2,10 @@ package storage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||
"github.com/shirou/gopsutil/disk"
|
||||
)
|
||||
@@ -74,23 +72,11 @@ const (
|
||||
DISK_TYPE_SDA DeviceIdentifier = "sda"
|
||||
DISK_TYPE_MCBLK DeviceIdentifier = "mmcblk0"
|
||||
DISK_TYPE_VDA DeviceIdentifier = "vda"
|
||||
MIN_DISK_SIZE int = 1048576 // 1GB in bytes
|
||||
)
|
||||
|
||||
func GetDeviceIdentifier(release_version diagnostics.ReleaseVersion) DeviceIdentifier {
|
||||
switch release_version {
|
||||
case diagnostics.CLOUD_VERSION:
|
||||
return DISK_TYPE_SDA
|
||||
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
|
||||
|
||||
cmdArgs := []string{"--raw", "--bytes", "--noheadings"}
|
||||
@@ -102,8 +88,6 @@ func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||
firstDevice := true
|
||||
currentDeviceInUseFlag := false
|
||||
|
||||
mainDiskID := GetDeviceIdentifier(release_version)
|
||||
|
||||
for scanner.Scan() {
|
||||
// 1 Device is represented here. Extract words in order for filling a Device struct
|
||||
// Example deviceRawInfo: "mmcblk0 179:0 0 29.7G 0 disk"
|
||||
@@ -136,13 +120,7 @@ func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||
currentDevice.InUse = currentDeviceInUseFlag
|
||||
currentDeviceInUseFlag = false
|
||||
currentPartitions = []Partition{}
|
||||
size, err := strconv.Atoi(currentDevice.Size)
|
||||
if err != nil {
|
||||
size = 0
|
||||
}
|
||||
if size > MIN_DISK_SIZE {
|
||||
devices = append(devices, currentDevice)
|
||||
}
|
||||
devices = append(devices, currentDevice)
|
||||
} else {
|
||||
firstDevice = false
|
||||
}
|
||||
@@ -161,14 +139,9 @@ func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||
Status: DeviceStatus{ID: 1, Description: "healthy"},
|
||||
}
|
||||
|
||||
if device.ID == mainDiskID {
|
||||
device.MainDevice = true
|
||||
}
|
||||
|
||||
currentDevice = device
|
||||
|
||||
} else if isPartition {
|
||||
|
||||
mountpoint := ""
|
||||
if len(deviceRawInfo) >= 7 {
|
||||
mountpoint = deviceRawInfo[6]
|
||||
@@ -201,22 +174,8 @@ func GetDevices(release_version diagnostics.ReleaseVersion) []Device {
|
||||
currentDevice.Status.Description = "Not configured"
|
||||
}
|
||||
currentDevice.InUse = currentDeviceInUseFlag
|
||||
devices = append([]Device{currentDevice}, devices...) // Prepending the first device...
|
||||
|
||||
fmt.Println("Secondary Storage Devices Found: ", len(devices))
|
||||
fmt.Println("Main Storage Device size: ", currentDevice.Size)
|
||||
|
||||
// only append device if size > 1GB
|
||||
if currentDevice.Size != "" && currentDevice.Size != "0" {
|
||||
// Convert size to int
|
||||
// Convert string to int
|
||||
size, err := strconv.Atoi(currentDevice.Size)
|
||||
if err != nil {
|
||||
size = 0
|
||||
}
|
||||
if size > MIN_DISK_SIZE {
|
||||
devices = append([]Device{currentDevice}, devices...) // Prepending the first device...
|
||||
}
|
||||
}
|
||||
devices = getDevicesSpaceUsage(devices)
|
||||
|
||||
return devices
|
||||
|
||||
@@ -7,14 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetDevices(t *testing.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)
|
||||
|
||||
assertGetDevices(GetDevices(), t)
|
||||
}
|
||||
|
||||
func assertGetDevices(devices []Device, t *testing.T) {
|
||||
|
||||
+1
-173
@@ -7,7 +7,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"io"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"bufio"
|
||||
"path/filepath"
|
||||
@@ -18,7 +17,6 @@ import (
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
type cloudflaredTunnelJson struct {
|
||||
@@ -84,6 +82,7 @@ func SetupCloudOptions() {
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error loading .env file for cloud version setup")
|
||||
return
|
||||
}
|
||||
|
||||
if cloudEnv["NAME"] != "" {
|
||||
@@ -427,174 +426,3 @@ func CopyFile(src string, dest string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckUpdates() {
|
||||
fmt.Println("Checking for Edgebox System Updates.")
|
||||
|
||||
// Configure the service and start it
|
||||
cmd := exec.Command("sh", "/home/system/components/updater/run.sh", "--check")
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for scanner.Scan() {
|
||||
// fmt.Println(scanner.Text())
|
||||
text := scanner.Text()
|
||||
fmt.Println(text)
|
||||
}
|
||||
if scanner.Err() != nil {
|
||||
cmd.Process.Kill()
|
||||
cmd.Wait()
|
||||
fmt.Println("Error running updates check.")
|
||||
utils.WriteOption("SYSTEM_UPDATES", "[]")
|
||||
return
|
||||
}
|
||||
|
||||
// Read targets.env file into JSON list structure
|
||||
targets := []string{}
|
||||
targetsFile, err := os.Open("/home/system/components/updater/targets.env")
|
||||
if err != nil {
|
||||
fmt.Println("No targets.env file found. Skipping.")
|
||||
utils.WriteOption("SYSTEM_UPDATES", "[]")
|
||||
return
|
||||
}
|
||||
defer targetsFile.Close()
|
||||
scanner = bufio.NewScanner(targetsFile)
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
// text line should look like: {"target": "<target>", "version": "<version>"}
|
||||
target := strings.Split(text, "=")
|
||||
newText := "{\"target\": \"" + strings.Replace(target[0], "_VERSION", "", -1) + "\", \"version\": \"" + target[1] + "\"}"
|
||||
targets = append(targets, newText)
|
||||
}
|
||||
if scanner.Err() != nil {
|
||||
fmt.Println("Error reading update targets file.")
|
||||
utils.WriteOption("SYSTEM_UPDATES", "[]")
|
||||
return
|
||||
}
|
||||
|
||||
// convert targets to string
|
||||
targetsString := strings.Join(targets, ",")
|
||||
targetsString = "[" + targetsString + "]"
|
||||
|
||||
fmt.Println(targetsString)
|
||||
|
||||
// Write option with targets
|
||||
utils.WriteOption("SYSTEM_UPDATES", targetsString)
|
||||
}
|
||||
|
||||
func ApplyUpdates() {
|
||||
fmt.Println("Applying Edgebox System Updates.")
|
||||
|
||||
utils.WriteOption("UPDATING_SYSTEM", "true")
|
||||
|
||||
// Configure the service and start it
|
||||
cmd := exec.Command("sh", "/home/system/components/updater/run.sh", "--update")
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
scanner := bufio.NewScanner(stdout)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for scanner.Scan() {
|
||||
fmt.Println(scanner.Text())
|
||||
text := scanner.Text()
|
||||
fmt.Println(text)
|
||||
}
|
||||
if scanner.Err() != nil {
|
||||
cmd.Process.Kill()
|
||||
cmd.Wait()
|
||||
panic(scanner.Err())
|
||||
}
|
||||
|
||||
// If the system did not yet restart, set updating system to false
|
||||
utils.WriteOption("UPDATING_SYSTEM", "false")
|
||||
}
|
||||
|
||||
func FetchBrowserDevPasswordFromFile() (string, error) {
|
||||
fmt.Println("Executing FetchBrowserDevPasswordFromFile")
|
||||
|
||||
// Read the "password" entry on the yaml file
|
||||
// Read the yaml file in system.GetPath(BrowserDevPasswordFileLocation)
|
||||
yamlFile, err := ioutil.ReadFile(utils.GetPath(utils.BrowserDevPasswordFileLocation))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Parse the yaml file and get the "password" entry
|
||||
var yamlFileMap yaml.MapSlice
|
||||
err = yaml.Unmarshal(yamlFile, &yamlFileMap)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, item := range yamlFileMap {
|
||||
key, value := item.Key, item.Value
|
||||
if key == "password" {
|
||||
if pwString, ok := value.(string); ok {
|
||||
return pwString, nil
|
||||
} else {
|
||||
return "", errors.New("password value is not a string")
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", errors.New("password key not found")
|
||||
}
|
||||
|
||||
func SetBrowserDevPasswordFile(password string) error {
|
||||
// Get current password from file
|
||||
currentPassword, err := FetchBrowserDevPasswordFromFile()
|
||||
if err != nil {
|
||||
fmt.Println("Error fetching current password from file.")
|
||||
return err
|
||||
}
|
||||
|
||||
// Write the new password on the file using ReplaceTextInFile
|
||||
err = ReplaceTextInFile(utils.GetPath(utils.BrowserDevPasswordFileLocation), currentPassword, password)
|
||||
if err != nil {
|
||||
fmt.Println("Error writing new password to file.")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReplaceTextInFile(filePath string, oldText string, newText string) error {
|
||||
// Open the file for reading
|
||||
file, err := os.OpenFile(filePath, os.O_RDWR, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Read the file contents
|
||||
data, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Close the file
|
||||
err = file.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Replace the text in the file
|
||||
newData := strings.Replace(string(data), oldText, newText, -1)
|
||||
|
||||
// Write the new data back to the file
|
||||
err = ioutil.WriteFile(filePath, []byte(newData), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
+201
-695
File diff suppressed because it is too large
Load Diff
@@ -111,10 +111,7 @@ const ApiPath string = "apiPath"
|
||||
const EdgeAppsPath string = "edgeAppsPath"
|
||||
const EdgeAppsBackupPath string = "edgeAppsBackupPath"
|
||||
const WsPath string = "wsPath"
|
||||
const BrowserDevPath string = "browserDevPath"
|
||||
const LoggerPath string = "loggerPath"
|
||||
const BrowserDevPasswordFileLocation string = "browserDevPasswordFileLocation"
|
||||
const BrowserDevProxyPath string = "browserDevProxyPath"
|
||||
|
||||
|
||||
// GetPath : Returns either the hardcoded path, or a overwritten value via .env file at project root. Register paths here for seamless working code between dev and prod environments ;)
|
||||
@@ -177,14 +174,6 @@ func GetPath(pathKey string) string {
|
||||
targetPath = "/home/system/components/ws/"
|
||||
}
|
||||
|
||||
case BrowserDevPath:
|
||||
|
||||
if env["BROWSERDEV_PATH"] != "" {
|
||||
targetPath = env["BROWSERDEV_PATH"]
|
||||
} else {
|
||||
targetPath = "/home/system/components/dev/"
|
||||
}
|
||||
|
||||
case LoggerPath:
|
||||
if env["LOGGER_PATH"] != "" {
|
||||
targetPath = env["LOGGER_PATH"]
|
||||
@@ -200,20 +189,6 @@ func GetPath(pathKey string) string {
|
||||
targetPath = "/home/system/components/backups/pw.txt"
|
||||
}
|
||||
|
||||
case BrowserDevPasswordFileLocation:
|
||||
if env["BROWSERDEV_PASSWORD_FILE_LOCATION"] != "" {
|
||||
targetPath = env["BROWSERDEV_PASSWORD_FILE_LOCATION"]
|
||||
} else {
|
||||
targetPath = "/root/.config/code-server/config.yaml"
|
||||
}
|
||||
|
||||
case BrowserDevProxyPath:
|
||||
if env["BROWSERDEV_PROXY_PATH"] != "" {
|
||||
targetPath = env["BROWSERDEV_PROXY_PATH"]
|
||||
} else {
|
||||
targetPath = "/home/system/components/dev/"
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
log.Printf("path_key %s nonexistant in GetPath().\n", pathKey)
|
||||
|
||||
Reference in New Issue
Block a user