|
| 1 | +//go:generate go run gen.go |
| 2 | + |
| 3 | +package main |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "log" |
| 8 | + "os" |
| 9 | + "os/exec" |
| 10 | +) |
| 11 | + |
| 12 | +func main() { |
| 13 | + if err := darwinDownload(); err != nil { |
| 14 | + log.Fatalf("failed to download file for macos: %v", err) |
| 15 | + } |
| 16 | + if err := linuxDownload(); err != nil { |
| 17 | + log.Fatalf("failed to download file for linux: %v", err) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +func darwinDownload() error { |
| 22 | + const path = "/opt/homebrew/lib" |
| 23 | + const name = "libemulator.dylib" |
| 24 | + |
| 25 | + log.Println("starting download lib for macos") |
| 26 | + |
| 27 | + initTonCmd := exec.Command("brew", "tap", "ton-blockchain/ton") |
| 28 | + if output, err := initTonCmd.CombinedOutput(); err != nil { |
| 29 | + return fmt.Errorf("[darwinDownload] failed to init ton: %v, output: %s", err, output) |
| 30 | + } |
| 31 | + |
| 32 | + _, err := os.Stat(fmt.Sprintf("%v/%v", path, name)) |
| 33 | + if err == nil { |
| 34 | + log.Println("file already exist, reinstalling lib...") |
| 35 | + reinstallCmd := exec.Command("brew", "reinstall", "ton") |
| 36 | + if output, err := reinstallCmd.CombinedOutput(); err != nil { |
| 37 | + return fmt.Errorf("[darwinDownload] failed to reinstall lib: %v, output: %s", err, output) |
| 38 | + } |
| 39 | + } else if os.IsNotExist(err) { |
| 40 | + log.Println("file doesn't exist, installing lib...") |
| 41 | + installCmd := exec.Command("brew", "install", "ton") |
| 42 | + if output, err := installCmd.CombinedOutput(); err != nil { |
| 43 | + return fmt.Errorf("[darwinDownload] failed to install lib: %v, output: %s", err, output) |
| 44 | + } |
| 45 | + } else { |
| 46 | + return fmt.Errorf("failed to check file: %v", err) |
| 47 | + } |
| 48 | + |
| 49 | + copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "darwin/") |
| 50 | + if output, err := copyCmd.CombinedOutput(); err != nil { |
| 51 | + return fmt.Errorf("[darwinDownload] failed to copy file: %v, output: %s", err, output) |
| 52 | + } |
| 53 | + |
| 54 | + log.Println("[darwinDownload] successfully update lib") |
| 55 | + |
| 56 | + return nil |
| 57 | +} |
| 58 | + |
| 59 | +func linuxDownload() error { |
| 60 | + const path = "/usr/lib" |
| 61 | + const name = "libemulator.so" |
| 62 | + |
| 63 | + log.Println("starting download lib for linux") |
| 64 | + |
| 65 | + commands := [][]string{ |
| 66 | + {"sudo", "apt-key", "adv", "--keyserver", "keyserver.ubuntu.com", "--recv-keys", "F6A649124520E5F3"}, |
| 67 | + {"sudo", "add-apt-repository", "ppa:ton-foundation/ppa"}, |
| 68 | + {"sudo", "apt", "update"}, |
| 69 | + {"sudo", "apt", "install", "ton"}, |
| 70 | + } |
| 71 | + for _, command := range commands { |
| 72 | + cmd := exec.Command(command[0], command[1:]...) |
| 73 | + if output, err := cmd.CombinedOutput(); err != nil { |
| 74 | + return fmt.Errorf("[linuxDownload] failed to install lib: %v, output: %s", err, output) |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + copyCmd := exec.Command("cp", fmt.Sprintf("%v/%v", path, name), "linux/") |
| 79 | + if output, err := copyCmd.CombinedOutput(); err != nil { |
| 80 | + return fmt.Errorf("[linuxDownload] failed to copy file: %v, output: %s", err, output) |
| 81 | + } |
| 82 | + |
| 83 | + log.Println("[linuxDownload] successfully update lib") |
| 84 | + |
| 85 | + return nil |
| 86 | +} |
0 commit comments