Skip to content

Commit

Permalink
Merge pull request #16 from blyndusk/feat_apt
Browse files Browse the repository at this point in the history
Implement apt exec script logic
  • Loading branch information
alexandre-delaloy authored Oct 15, 2021
2 parents 99f8fe7 + 311c1ea commit 1c9406b
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 25 additions & 6 deletions cmd/flamin-go/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//

package main

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"strings"

"github.com/blyndusk/flamin-go/internal/core"
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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()
}
5 changes: 0 additions & 5 deletions config/.env.sample

This file was deleted.

17 changes: 17 additions & 0 deletions config/config.sh
Original file line number Diff line number Diff line change
@@ -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"
)
36 changes: 15 additions & 21 deletions internal/core/tasks.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package core

import "github.com/sirupsen/logrus"

type Task struct {
Name string
Description string
Expand All @@ -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{
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand All @@ -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",
},
},
},
Expand Down
11 changes: 11 additions & 0 deletions scripts/apt/install.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions scripts/apt/update.sh
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions scripts/colors.sh
Original file line number Diff line number Diff line change
@@ -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"; }
File renamed without changes.
File renamed without changes.

0 comments on commit 1c9406b

Please sign in to comment.