-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
272 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
on: | ||
release: | ||
types: [created] | ||
|
||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
jobs: | ||
release-linux-amd64: | ||
name: release linux/amd64 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: wangyoucao577/go-release-action@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
goos: linux | ||
goarch: amd64 | ||
build_args: -ldflags "-s -w" | ||
build_tags: linux-amd64 | ||
release-mac-arm64: | ||
name: release linux/amd64 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: wangyoucao577/go-release-action@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
goos: darwin | ||
goarch: arm64 | ||
build_args: -ldflags "-s -w" | ||
build_tags: darwin-arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package helpers | ||
|
||
import ( | ||
"fmt" | ||
"genius/types" | ||
"os" | ||
"strings" | ||
) | ||
|
||
// CheckFileExists checks if the file exists in the given path | ||
// and returns a boolean value. | ||
func CheckFileExists(path string) bool { | ||
if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// ReadNTPConfFile reads the NTP configuration file and returns the content. | ||
// The NTP configuration file is located at /etc/ntp.conf | ||
// and it contains the NTP server addresses. | ||
// The NTP server addresses are used to get the time from the NTP server. | ||
func ReadNTPConfFile() (*[]types.NTPConfiguration, error) { | ||
ntpConfFile := "/etc/ntp.conf" | ||
// Or if it has chrony installed | ||
// ntpConfFile := "/etc/chrony/chrony.conf" | ||
|
||
if !CheckFileExists(ntpConfFile) { | ||
return nil, fmt.Errorf("NTP configuration file %s does not exist.", ntpConfFile) | ||
} | ||
// Read the NTP configuration file | ||
// and return the content | ||
ntpFile, err := os.ReadFile(ntpConfFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
stringNTPFile := string(ntpFile) | ||
|
||
// We have NTP config file something like this: | ||
// server 0.us.pool.ntp.org iburst | ||
// server 1.us.pool.ntp.org iburst | ||
// server 2.us.pool.ntp.org iburst | ||
// server 3.us.pool.ntp.org iburst | ||
|
||
// Find the server addresses in the NTP configuration file | ||
// and return them | ||
if strings.Index(stringNTPFile, "server") == -1 { | ||
return nil, fmt.Errorf("NTP server addresses not found in %s", ntpConfFile) | ||
} | ||
// Remove the comments and get the server addresses | ||
if strings.Index(stringNTPFile, "#") != -1 { | ||
stringNTPFile = stringNTPFile[:strings.Index(stringNTPFile, "#")] // Remove the comments | ||
} | ||
stringNTPFile = stringNTPFile[strings.Index(stringNTPFile, "server")+7:] // Get the server addresses | ||
// Replace the "server" keyword with an empty string | ||
stringNTPFile = strings.ReplaceAll(stringNTPFile, "server", "") | ||
|
||
stringNTPFile = strings.ReplaceAll(stringNTPFile, "\n", " ") | ||
stringArrayNTPFile := strings.Fields(stringNTPFile) | ||
|
||
var ntpConfig []types.NTPConfiguration | ||
for i, server := range stringArrayNTPFile { | ||
if server == "iburst" { | ||
continue | ||
} else if server == "" { | ||
continue | ||
} | ||
var iburst bool | ||
if i+1 >= len(stringArrayNTPFile) { | ||
iburst = false | ||
} else { | ||
iburst = stringArrayNTPFile[i+1] == "iburst" | ||
} | ||
ntpConfig = append(ntpConfig, types.NTPConfiguration{ | ||
Server: server, | ||
IBurst: iburst, | ||
}) | ||
} | ||
return &ntpConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package helpers | ||
|
||
import "runtime" | ||
|
||
func IsWindows() bool { | ||
// GOOS is the running program's operating system target: | ||
// one of darwin, freebsd, linux, and so on. | ||
if runtime.GOOS == "windows" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func IsMacOS() bool { | ||
if runtime.GOOS == "darwin" { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package helpers | ||
|
||
import ( | ||
"log" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func GetHomeBrewVersion() (string, error) { | ||
// Get the Homebrew version | ||
// brew --version | ||
cmd := exec.Command("brew", "--version") | ||
stdout, err := cmd.Output() | ||
if err != nil { | ||
if strings.Contains(err.Error(), "executable file not found") { | ||
return "Not found", nil | ||
} | ||
log.Println(err) | ||
// panic(err) | ||
return "", err | ||
} | ||
stringified := string(stdout) | ||
// Remove the new line character | ||
stringified = strings.TrimSuffix(stringified, "\n") | ||
// Remove the Homebrew keyword | ||
stringified = strings.ReplaceAll(stringified, "Homebrew", "") | ||
// Remove the whitespace | ||
stringified = strings.TrimSpace(stringified) | ||
return stringified, nil | ||
} | ||
|
||
func GetPythonVersion() (string, error) { | ||
// Get the Python version | ||
// python --version | ||
cmd := exec.Command("python3", "--version") | ||
stdout, err := cmd.Output() | ||
if err != nil { | ||
if strings.Contains(err.Error(), "executable file not found") { | ||
return "Not found", nil | ||
} | ||
log.Println(err) | ||
// panic(err) | ||
return "", err | ||
} | ||
stringified := string(stdout) | ||
// Remove the new line character | ||
stringified = strings.TrimSuffix(stringified, "\n") | ||
// Remove the Python keyword | ||
stringified = strings.ReplaceAll(stringified, "Python", "") | ||
// Remove the whitespace | ||
stringified = strings.TrimSpace(stringified) | ||
return stringified, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package types | ||
|
||
type NTPConfiguration struct { | ||
Server string `json:"server"` | ||
IBurst bool `json:"iburst"` | ||
} |