diff --git a/Makefile b/Makefile index 9f08cb8..8a128e5 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' setup-env: ## Copy sample files - bash scripts/setup.sh + bash scripts/make/setup.sh run: ## Up the docker-compose without cache or orphans go run cmd/flamin-go/main.go diff --git a/cmd/flamin-go/main.go b/cmd/flamin-go/main.go index eb28770..ca55901 100644 --- a/cmd/flamin-go/main.go +++ b/cmd/flamin-go/main.go @@ -1,9 +1,11 @@ -// - package main import ( + "bytes" "fmt" + "io" + "os" + "os/exec" "strings" "github.com/blyndusk/flamin-go/internal/core" @@ -12,7 +14,20 @@ import ( "github.com/ttacon/chalk" ) -func main() { +func execAction(file string) { + pwd, _ := os.Getwd() + actionFile := fmt.Sprintf("%s/scripts/%s.sh", pwd, file) + cmd := exec.Command("/bin/bash", actionFile) + + var stdoutBuf, stderrBuf bytes.Buffer + cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf) + cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf) + + err := cmd.Run() + helpers.ExitOnError("cmd.Run() failed with", err) + +} +func run() { fmt.Print("\033[H\033[2J") searcher := func(input string, index int) bool { @@ -49,7 +64,7 @@ func main() { action := task.Actions[j] choice := chalk.Green.NewStyle().WithBackground(chalk.ResetColor).WithTextStyle(chalk.Bold).Style(action.Description) - + fmt.Print("\033[H\033[2J") fmt.Print("Task: ", chalk.Red, task.Name, chalk.Reset, "\n") fmt.Print("Action: ", chalk.Yellow, chalk.Bold, action.Name, chalk.Reset, "\n") @@ -63,7 +78,11 @@ func main() { result, err := confirmPrompt.Run() helpers.ExitOnError("confirmPrompt failed:", err) - if (result == "" || result == "Y" || result == "y") { - action.Exec() + if result == "" || result == "Y" || result == "y" { + execAction(action.Exec) + run() } } +func main() { + run() +} diff --git a/config/.env.sample b/config/.env.sample deleted file mode 100644 index a31a2d3..0000000 --- a/config/.env.sample +++ /dev/null @@ -1,5 +0,0 @@ -DB_NAME=db -DB_USER=root -DB_PASSWORD=root -DB_HOST=postgres -DB_PORT=5432 \ No newline at end of file diff --git a/config/config.sh b/config/config.sh new file mode 100644 index 0000000..0529799 --- /dev/null +++ b/config/config.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +export __APT=( + "apt-transport-https" + "ca-certificates" + "git" + "htop" + "make" + "nodejs" + "shellcheck" + "software-properties-common" + "tmux" + "tree" + "xclip" + "zsh" + "ppppp" +) diff --git a/internal/core/tasks.go b/internal/core/tasks.go index a5b7103..0ceebdf 100644 --- a/internal/core/tasks.go +++ b/internal/core/tasks.go @@ -1,7 +1,5 @@ package core -import "github.com/sirupsen/logrus" - type Task struct { Name string Description string @@ -12,11 +10,7 @@ type Task struct { type Action struct { Name string Description string - Exec func() -} - -func foo() { - logrus.Info("test") + Exec string } var Tasks = []Task{ @@ -31,12 +25,12 @@ var Tasks = []Task{ { Name: "install", Description: "install all apt packages from cfg.sh", - Exec: foo, + Exec: "apt/install", }, { Name: "update", Description: "update all apt packages from cfg.sh", - Exec: foo, + Exec: "apt/update", }, }, }, @@ -51,12 +45,12 @@ var Tasks = []Task{ { Name: "install", Description: "install all snap packages from cfg.sh", - Exec: foo, + Exec: "apt/update", }, { Name: "refresh", Description: "refresh all snap packages from cfg.sh", - Exec: foo, + Exec: "apt/update", }, }, }, @@ -72,17 +66,17 @@ var Tasks = []Task{ { Name: "oh-my-zsh", Description: "install Oh-My-Zsh famework", - Exec: foo, + Exec: "apt/update", }, { Name: "zsh-users plugins", Description: "install zsh plugins from cfg.sh", - Exec: foo, + Exec: "apt/update", }, { Name: "spaceship-prompt", Description: "install spaceship-prompt for Zsh", - Exec: foo, + Exec: "apt/update", }, }, }, @@ -97,12 +91,12 @@ var Tasks = []Task{ { Name: "sync", Description: "sync all bash dotfiles from cfg.sh", - Exec: foo, + Exec: "apt/update", }, { Name: "rc", Description: "update the .bashrc or .zshrc file", - Exec: foo, + Exec: "apt/update", }, }, }, @@ -118,12 +112,12 @@ var Tasks = []Task{ { Name: "docker", Description: "install Docker and Docker Compose", - Exec: foo, + Exec: "apt/update", }, { Name: "kubernetes", Description: "install Kubectl and Helm", - Exec: foo, + Exec: "apt/update", }, }, }, @@ -139,17 +133,17 @@ var Tasks = []Task{ { Name: "extensions", Description: "install all VSCode extensions from cfg.sh", - Exec: foo, + Exec: "apt/update", }, { Name: "theme", Description: "install VSCode theme from cfg.sh", - Exec: foo, + Exec: "apt/update", }, { Name: "settings", Description: "sync settings to VSCode from cfg.sh", - Exec: foo, + Exec: "apt/update", }, }, }, diff --git a/scripts/apt/install.sh b/scripts/apt/install.sh new file mode 100755 index 0000000..c06242a --- /dev/null +++ b/scripts/apt/install.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# shellcheck source=/dev/null +source "$PWD"/scripts/colors.sh +source "$PWD"/config/config.sh + +fyellow "[-] starting..." ; sleep 1 + +sudo apt install "${__APT[*]}" -y + +fgreen "[-] done !" ; sleep 1 \ No newline at end of file diff --git a/scripts/apt/update.sh b/scripts/apt/update.sh new file mode 100755 index 0000000..4d92d71 --- /dev/null +++ b/scripts/apt/update.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# shellcheck source=/dev/null +source "$PWD"/scripts/colors.sh + +fyellow "[-] starting..." ; sleep 1 + +sudo apt update -y +sudo apt upgrade -y + +fgreen "[-] done !" ; sleep 1 \ No newline at end of file diff --git a/scripts/colors.sh b/scripts/colors.sh new file mode 100644 index 0000000..26c18eb --- /dev/null +++ b/scripts/colors.sh @@ -0,0 +1,26 @@ +#!/bin/bash +fdefault() { echo -e "\e[39m$1\e[0m"; } +fblack() { echo -e "\e[30m$1\e[0m"; } +fred() { echo -e "\e[31m$1\e[0m"; } +fgreen() { echo -e "\e[32m$1\e[0m"; } +fyellow() { echo -e "\e[33m$1\e[0m"; } +fblue() { echo -e "\e[34m$1\e[0m"; } +fmagenta() { echo -e "\e[35m$1\e[0m"; } +fcyan() { echo -e "\e[36m$1\e[0m"; } + +bdefault() { echo -e "\e[49m$1\e[0m"; } +bblack() { echo -e "\e[40m$1\e[0m"; } +bred() { echo -e "\e[41m$1\e[0m"; } +bgreen() { echo -e "\e[42m$1\e[0m"; } +byellow() { echo -e "\e[43m$1\e[0m"; } +bblue() { echo -e "\e[44m$1\e[0m"; } +bmagenta() { echo -e "\e[45m$1\e[0m"; } +bcyan() { echo -e "\e[46m$1\e[0m"; } + +red() { echo -e "\e[1;30;41m$1\e[0m"; } +green() { echo -e "\e[1;30;42m$1\e[0m"; } +yellow() { echo -e "\e[1;30;43m$1\e[0m"; } +blue() { echo -e "\e[1;30;44m$1\e[0m"; } +magenta() { echo -e "\e[1;30;45m$1\e[0m"; } +cyan() { echo -e "\e[1;30;46m$1\e[0m"; } +neg() { echo -e "\e[7$1\e[0m"; } diff --git a/scripts/setup.sh b/scripts/make/setup.sh similarity index 100% rename from scripts/setup.sh rename to scripts/make/setup.sh diff --git a/scripts/start.sh b/scripts/make/start.sh similarity index 100% rename from scripts/start.sh rename to scripts/make/start.sh