-
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
1 parent
3e85be6
commit 5cf74da
Showing
2 changed files
with
63 additions
and
0 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,54 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"ui/cli/module" | ||
|
||
"github.com/gookit/color" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func UpdateSelf(c *cli.Context) { | ||
var cmd = exec.Command("sudo", "-v") | ||
cmd.Stdout = nil | ||
err := cmd.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
color.Yellowln("Updating ui-cli") | ||
fmt.Println() | ||
|
||
filePath := module.DownloadFileToCache("https://github.com/Update-Install/CLI/releases/latest/download/ui-cli_linux_amd64") | ||
|
||
module.FullWidthMessage("installation log start", color.Gray) | ||
cmd = exec.Command("sudo", "mv", filePath, "/usr/local/bin/ui") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Moved", filePath, "to /usr/local/bin") | ||
cmd = exec.Command("sudo", "chmod", "+x", "/usr/local/bin/ui") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("Changed permission for /usr/local/bin/ui") | ||
module.FullWidthMessage("installation log end", color.Gray) | ||
|
||
color.Greenf("Successfully updated ui-cli to ") | ||
cmd = exec.Command("/usr/local/bin/ui", "version") | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
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