Add license and readme files, update dependencies, and add installation script

This commit is contained in:
Andras Bacsai
2024-03-06 12:21:10 +01:00
parent c2f44ee6b9
commit 7e4309301b
6 changed files with 93 additions and 9 deletions
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2024 Andras Bacsai
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+1
View File
@@ -0,0 +1 @@
# CLI for [Coolify](https://coolify.io)
+12 -7
View File
@@ -7,11 +7,11 @@ import (
"log"
"net/http"
"os"
"reflect"
"sort"
"text/tabwriter"
"time"
"github.com/adrg/xdg"
compareVersion "github.com/hashicorp/go-version"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -21,6 +21,8 @@ var CliVersion = "0.0.1"
var LastUpdateCheckTime time.Time
var CheckInverval = 10 * time.Minute
var ConfigDir = xdg.ConfigHome
var Version string
var Name string
var Fqdn string
@@ -167,10 +169,7 @@ func Execute() {
os.Exit(1)
}
}
func isNumber(value interface{}) bool {
kind := reflect.TypeOf(value).Kind()
return kind >= reflect.Int && kind <= reflect.Float64
}
func init() {
cobra.OnInitialize(initConfig)
@@ -201,10 +200,13 @@ func getLastUpdateCheckTime() {
func initConfig() {
viper.SetConfigName("config")
viper.SetConfigType("json")
viper.AddConfigPath(".")
viper.AddConfigPath(ConfigDir + "/coolify")
if _, err := os.Stat(ConfigDir + "/coolify"); os.IsNotExist(err) {
os.MkdirAll(ConfigDir+"/coolify", 0755)
}
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Println("Config file not found. Creating a new one.")
log.Println("Config file not found. Creating a new one at", ConfigDir+"/coolify/config.json")
viper.Set("lastUpdateCheckTime", time.Now())
viper.Set("instances", []interface{}{map[string]interface{}{
"default": true,
@@ -226,6 +228,9 @@ func initConfig() {
}
}
if Debug {
log.Println("Using config file:", viper.ConfigFileUsed())
}
instancesMap := viper.Get("instances").([]interface{})
for _, instance := range instancesMap {
instanceMap := instance.(map[string]interface{})
+3 -2
View File
@@ -3,6 +3,8 @@ module github.com/coollabsio/coolify-cli
go 1.21.0
require (
github.com/creativeprojects/go-selfupdate v1.1.3
github.com/hashicorp/go-version v1.6.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
)
@@ -10,7 +12,7 @@ require (
require (
code.gitea.io/sdk/gitea v0.17.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/creativeprojects/go-selfupdate v1.1.3 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-fed/httpsig v1.1.0 // indirect
@@ -19,7 +21,6 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
+3
View File
@@ -2,6 +2,8 @@ code.gitea.io/sdk/gitea v0.17.1 h1:3jCPOG2ojbl8AcfaUCRYLT5MUcBMFwS0OSK2mA5Zok8=
code.gitea.io/sdk/gitea v0.17.1/go.mod h1:aCnBqhHpoEWA180gMbaCtdX9Pl6BWBAuuP2miadoTNM=
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creativeprojects/go-selfupdate v1.1.3 h1:p+Mx6rCZGBMrYWa5XhHCHYsS+w9v21fSfItuEUlxIGo=
github.com/creativeprojects/go-selfupdate v1.1.3/go.mod h1:sL4LPc1cei5kkQ8MG9EmhvUdLEcbfn7Z2nY+aYfAvrA=
@@ -119,6 +121,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+55
View File
@@ -0,0 +1,55 @@
#!/bin/bash
# Function to detect platform, architecture, etc.
detect_platform() {
OS=$(uname -s)
ARCH=$(uname -m)
case $OS in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*)
echo "Unsupported operating system: $OS"
exit 1
;;
esac
case $ARCH in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
}
# Function to download file from GitHub release
download_from_github() {
local repo=$1
local release=$2
local name=$3
local filename=${name}_${release}_${OS}_${ARCH}.tar.gz
# https://github.com/coollabsio/coolify-cli/releases/download/0.0.1/coolify-cli_0.0.1_linux_amd64.tar.gz
# Construct download URL
local download_url="https://github.com/${repo}/releases/download/${release}/${filename}"
# Use curl to download the file
curl -L -o "${filename}" $download_url
# Determine the binary directory
local binary_dir=""
if [ "$OS" == "linux" ] || [ "$OS" == "darwin" ]; then
binary_dir="/usr/local/bin"
fi
sudo tar -xzvf "${filename}" -C "${binary_dir}"
# Cleanup
rm "${filename}"
echo "${name} installed successfully to ${binary_dir}"
}
detect_platform
download_from_github "coollabsio/coolify-cli" "0.0.1" "coolify-cli"