Skip to content

Commit

Permalink
alpine linux support added
Browse files Browse the repository at this point in the history
  • Loading branch information
mmchougule committed Oct 26, 2023
1 parent 4f4f9e6 commit 4fa36fa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GetCommandsFromConfig(path string, commanderRegistry map[string]NodeCommand
if commander != nil {
initConf.SpaceCore = currentComponent
if initConf.Analytics.Enabled {
go utils.SendAnonymousData(initConf)
go utils.SaveAnalyticsData(initConf)
}
commander.Start(c, args, ntype)
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func InitializeSystem(force bool, noTrack bool) error {
}
// Only prompt if initializing for the first time
if config.Analytics.Enabled {
fmt.Println("Vimana collects anonymous usage data to improve our software and show our network growth.")
fmt.Println("Vimana collects usage data to improve our software and show our network growth.")
var response string
fmt.Println("Would you like to contribute? [Y/n]")
fmt.Scanln(&response)
Expand Down
24 changes: 22 additions & 2 deletions cmd/utils/tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)

const APIEndpoint = "http://localhost:8080/save-vimana-usage"
// record usage data if user agrees to contribute
const APIEndpoint = "https://api-api-dev.bk7bbm.oss-acorn.io/save-vimana-usage"

type APIVimanaUsage struct {
EthAddress string `json:"eth_address,omitempty"`
Expand All @@ -18,9 +20,11 @@ type APIVimanaUsage struct {
DiskSize float64 `json:"disk_size"`
InitDate string `json:"init_date"`
SpaceCore string `json:"space_core"`
IpAddress string `json:"ip_address"`
}

func SendAnonymousData(conf *InitConfig) {
func SaveAnalyticsData(conf *InitConfig) {
ip, _ := GetExternalIP()
data := APIVimanaUsage{
EthAddress: conf.EthAddress,
Kvm: conf.Kvm,
Expand All @@ -29,6 +33,7 @@ func SendAnonymousData(conf *InitConfig) {
DiskSize: conf.DiskSize,
InitDate: conf.InitDate,
SpaceCore: conf.SpaceCore,
IpAddress: ip,
}

jsonData, err := json.Marshal(data)
Expand Down Expand Up @@ -57,3 +62,18 @@ func SendAnonymousData(conf *InitConfig) {
log.Println("Failed to send analytics data, status:", resp.Status)
}
}

func GetExternalIP() (string, error) {
response, err := http.Get("https://api.ipify.org?format=text")
if err != nil {
return "", err
}
defer response.Body.Close()

ip, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}

return string(ip), nil
}
18 changes: 12 additions & 6 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ fi

echo "💻 OS: $OS"
echo "🏗️ ARCH: $ARCH"

# if OS is linux then install unzip
if [[ "$OS" == "linux" ]]; then
if which apt > /dev/null; then
sudo apt-get update > /dev/null
sudo apt-get install unzip > /dev/null
elif which apk > /dev/null; then
sudo apk update > /dev/null
sudo apk add unzip > /dev/null
ARCH="arm64_alpine"
fi
fi
TGZ_URL="https://github.com/Vistara-Labs/vimana/releases/download/celestia-v0.11.0-rc15/${OS}_${ARCH}.zip"

sudo mkdir -p "$INTERNAL_DIR"
Expand All @@ -38,12 +50,6 @@ sudo mkdir -p "/tmp/vimcel"
echo "💈 Downloading Celestia..."
sudo curl -o /tmp/vimcel/${OS}_${ARCH}.zip -L "$TGZ_URL" --progress-bar

# if OS is linux then install unzip
if [[ "$OS" == "linux" ]]; then
# accept default yes
sudo apt-get update > /dev/null
sudo apt-get install unzip > /dev/null
fi
sudo unzip -q /tmp/vimcel/${OS}_${ARCH}.zip -d /tmp/vimcel/
sudo mv "/tmp/vimcel/${OS}_${ARCH}"/* "$INTERNAL_DIR"
sudo chmod +x "$INTERNAL_DIR"
Expand Down

0 comments on commit 4fa36fa

Please sign in to comment.