From 5e0dd4d4bb9f38e2e4d23b46ded5c895dacf40c2 Mon Sep 17 00:00:00 2001 From: Adi Iyengar Date: Tue, 28 May 2019 13:56:06 -0400 Subject: [PATCH 1/2] Add notes changes --- NOTES.md | 39 --------------------------------------- README.md | 18 +++++++++++++++++- adify.sh | 11 +++-------- 3 files changed, 20 insertions(+), 48 deletions(-) delete mode 100644 NOTES.md diff --git a/NOTES.md b/NOTES.md deleted file mode 100644 index 01bdf36..0000000 --- a/NOTES.md +++ /dev/null @@ -1,39 +0,0 @@ -# NOTES WHILE SETTING UP FOR THE FIRST TIME: - -### GIT Config ### -# git config --global push.default simple (Push only the branch you intended to) - -### NEOVIM Ubuntu ### -### Source: https://github.com/neovim/neovim/wiki/Installing-Neovim ### - -# COMMANDS: -# sudo apt-get install software-properties-common -# sudo add-apt-repository ppa:neovim-ppa/stable -# sudo apt-get update -# sudo apt-get install neovim - -________________________________________________________________________ - -### XClip Ubuntu (PbCopy alternative) ### -### Source: https://garywoodfine.com/use-pbcopy-on-ubuntu/ - -# COMMANDS: -# sudo apt-get install xclip -y -# ADD ALIASES: -# alias pbcopy='xclip -selection clipboard' -# alias pbpaste='xclip -selection clipboard -o' - - -### ALIASES TO ADD ### -# alias genki='ssh-keygen -t rsa -C ""' - - -### CURL #### -# sudo apt install curl - - -### ZSH ### -# sudo apt-get -y install zsh - -### Virtual Box ### -# 5.1 diff --git a/README.md b/README.md index 2329079..eddf0ac 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ # Adify -Set of scripts that install necessary tools and configurations for me to work on a computer. + +Set of scripts that install necessary tools for Annkissam developers and +project managers on their computers. + +This has been adapted from `aditya7iyengar/adify` + +## USAGE + +* From the terminal: + +``` +$ bash <(wget -qO- https://raw.githubusercontent.com/annkissam/adify/master/adify.sh) + +OR + +$ bash <(curl -s https://raw.githubusercontent.com/annkissam/adify/master/adify.sh) +``` diff --git a/adify.sh b/adify.sh index 240103e..20084f3 100755 --- a/adify.sh +++ b/adify.sh @@ -1,10 +1,5 @@ #!/usr/bin/env bash -############# -### ABOUT ### -############# -# TODO: Better Description - ############# ### USAGE ### ############# @@ -220,9 +215,9 @@ install_mac_tools() { else _announce_error "Failed!" fi - + if [ $? -eq 0 ]; then - _announce_info "Installing autoconf" + _announce_info "Installing autoconf" brew install autoconf else _announce_error "Failed!" @@ -235,7 +230,7 @@ install_mac_tools() { _announce_error "Failed!" fi - + if [ $? -eq 0 ]; then _announce_info "Installing wxwidgets, ODBC, gnupg and gnuppg2" brew install wxwidgets From b33461d2d3f6568638524e241e47c2c43df5f76a Mon Sep 17 00:00:00 2001 From: Adi Iyengar Date: Tue, 28 May 2019 14:05:53 -0400 Subject: [PATCH 2/2] Upgrade elixir version * Add formatter * Add circleci * Add tool versions * Format elixir code --- .circleci/config.yml | 43 +++++++++++++ adifier/.formatter.exs | 4 ++ adifier/.tool-versions | 1 + adifier/lib/adifier.ex | 3 +- adifier/lib/adifier/invoker.ex | 11 ++-- adifier/lib/adifier/package_manager.ex | 2 + adifier/lib/adifier/tool.ex | 14 ++--- adifier/lib/adifier/tool/docker.ex | 6 +- adifier/lib/adifier/tool/mysql.ex | 2 +- adifier/lib/adifier/tool/neovim.ex | 2 +- adifier/lib/adifier/tool/nodejs.ex | 12 ++-- adifier/lib/adifier/tool/postgresql.ex | 16 ++--- adifier/lib/adifier/tool/ruby.ex | 8 +-- adifier/lib/adifier/tool/spideroak.ex | 14 ++--- adifier/lib/applier.ex | 4 +- adifier/lib/appliers/configurations.ex | 2 +- .../lib/appliers/package_manager_updater.ex | 19 ++++-- adifier/lib/appliers/tools_installer.ex | 60 +++++++++++-------- adifier/lib/mix/tasks/adify.ex | 5 +- adifier/mix.exs | 13 ++-- adifier/test/adifier_test.exs | 4 -- 21 files changed, 152 insertions(+), 93 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 adifier/.formatter.exs create mode 100644 adifier/.tool-versions diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2ab1022 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,43 @@ +version: 2 +jobs: + build: + parallelism: 4 + docker: + - image: circleci/elixir:1.8.1 + + working_directory: ~/app/adifier + + steps: + - checkout + + - restore_cache: + keys: + - adify-dependency-cache-{{ .Branch }}-{{ checksum "mix.lock" }} + - adify-dependency-cache-{{ .Branch }} + - adify-dependency-cache + - restore_cache: + keys: + - adify-build-cache-{{ .Branch }} + - adify-build-cache + + - run: mix local.hex --force + - run: mix local.rebar --force + - run: mix do deps.get, compile + + - save_cache: + key: adify-dependency-cache-{{ .Branch }}-{{ checksum "mix.lock" }} + paths: "deps" + - save_cache: + key: adify-dependency-cache-{{ .Branch }} + paths: "deps" + - save_cache: + key: adify-dependency-cache + paths: "deps" + - save_cache: + key: adify-build-cache-{{ .Branch }} + paths: "_build" + - save_cache: + key: adify-build-cache + paths: "_build" + + - run: ../adify.sh diff --git a/adifier/.formatter.exs b/adifier/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/adifier/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/adifier/.tool-versions b/adifier/.tool-versions new file mode 100644 index 0000000..ffcf012 --- /dev/null +++ b/adifier/.tool-versions @@ -0,0 +1 @@ +elixir 1.8.2 diff --git a/adifier/lib/adifier.ex b/adifier/lib/adifier.ex index 603546d..6672459 100644 --- a/adifier/lib/adifier.ex +++ b/adifier/lib/adifier.ex @@ -7,7 +7,8 @@ defmodule Adifier do @default_os "ubuntu" def adify(opts) do - os = opts + os = + opts |> Keyword.get(:os, @default_os) |> String.to_atom() diff --git a/adifier/lib/adifier/invoker.ex b/adifier/lib/adifier/invoker.ex index 625518e..9e12314 100644 --- a/adifier/lib/adifier/invoker.ex +++ b/adifier/lib/adifier/invoker.ex @@ -5,12 +5,13 @@ defmodule Adifier.Invoker do @doc false def call("sudo" <> cmd) do - System.cmd("sh", ["-c" , "sudo -A #{cmd}"], - env: [{"SUDO_ASKPASS", "./askpass.sh"}], - into: IO.stream(:stdio, :line)) + System.cmd("sh", ["-c", "sudo -A #{cmd}"], + env: [{"SUDO_ASKPASS", "./askpass.sh"}], + into: IO.stream(:stdio, :line) + ) end + def call(cmd) do - System.cmd("sh", ["-c", cmd], - into: IO.stream(:stdio, :line)) + System.cmd("sh", ["-c", cmd], into: IO.stream(:stdio, :line)) end end diff --git a/adifier/lib/adifier/package_manager.ex b/adifier/lib/adifier/package_manager.ex index 545013a..74bac12 100644 --- a/adifier/lib/adifier/package_manager.ex +++ b/adifier/lib/adifier/package_manager.ex @@ -8,9 +8,11 @@ defmodule Adifier.PackageManager do def install_cmd(:arch_linux, pkg), do: "sudo pacman -S #{pkg} --noconfirm" def install_cmd(:mac, pkg), do: "brew install #{pkg}" def install_cmd(:debian, pkg), do: "sudo apt -y install #{pkg}" + def install_cmd(os, pkg) when os in [:ubuntu, :pop_os] do "sudo apt-get -y install #{pkg}" end + def install_cmd(os, pkg) when os in [:centos, :fedora] do "sudo yum -y install #{pkg}" end diff --git a/adifier/lib/adifier/tool.ex b/adifier/lib/adifier/tool.ex index f3d2cea..bd5c111 100644 --- a/adifier/lib/adifier/tool.ex +++ b/adifier/lib/adifier/tool.ex @@ -21,11 +21,11 @@ defmodule Adifier.Tool do defstruct ~w{errors}a ++ @enforce_keys @type t :: %__MODULE__{ - ran_at: Datetime.t(), - name: String.t(), - install_cmd: String.t(), - description: String.t() - } + ran_at: Datetime.t(), + name: String.t(), + install_cmd: String.t(), + description: String.t() + } @callback install_cmd(Atom.t()) :: {:ok | :error, __MODULE__.t()} @callback description() :: String.t() @@ -61,7 +61,7 @@ defmodule Adifier.Tool do @impl true def __name__ do - case unquote(name)do + case unquote(name) do :default -> unquote(__MODULE__).__get_name__(__MODULE__) name -> name end @@ -75,7 +75,7 @@ defmodule Adifier.Tool do """ end - defoverridable [install_cmd: 1, description: 0] + defoverridable install_cmd: 1, description: 0 end end diff --git a/adifier/lib/adifier/tool/docker.ex b/adifier/lib/adifier/tool/docker.ex index 7e1a792..c2610d7 100644 --- a/adifier/lib/adifier/tool/docker.ex +++ b/adifier/lib/adifier/tool/docker.ex @@ -1,8 +1,8 @@ defmodule Adifier.Tool.Docker do @moduledoc """ - Docker enables true independence between applications and infrastructure - and developers and IT ops to unlock their potential and creates a model - for better collaboration and innovation. + Docker enables true independence between applications and infrastructure + and developers and IT ops to unlock their potential and creates a model + for better collaboration and innovation. """ use Adifier.Tool, name: "docker" diff --git a/adifier/lib/adifier/tool/mysql.ex b/adifier/lib/adifier/tool/mysql.ex index 8819b8e..14fb963 100644 --- a/adifier/lib/adifier/tool/mysql.ex +++ b/adifier/lib/adifier/tool/mysql.ex @@ -1,6 +1,6 @@ defmodule Adifier.Tool.Mysql do @moduledoc """ - The most popular Open-source Relational Database Mangement System. + The most popular Open-source Relational Database Mangement System. """ use Adifier.Tool, name: "mysql" diff --git a/adifier/lib/adifier/tool/neovim.ex b/adifier/lib/adifier/tool/neovim.ex index b9cba48..00f619a 100644 --- a/adifier/lib/adifier/tool/neovim.ex +++ b/adifier/lib/adifier/tool/neovim.ex @@ -1,6 +1,6 @@ defmodule Adifier.Tool.Neovim do @moduledoc """ - Neovim is a refactor, and sometimes redactor, in the tradition of Vim + Neovim is a refactor, and sometimes redactor, in the tradition of Vim """ use Adifier.Tool, name: "neovim" diff --git a/adifier/lib/adifier/tool/nodejs.ex b/adifier/lib/adifier/tool/nodejs.ex index 1e48b8c..79cef0b 100644 --- a/adifier/lib/adifier/tool/nodejs.ex +++ b/adifier/lib/adifier/tool/nodejs.ex @@ -12,18 +12,18 @@ defmodule Adifier.Tool.Nodejs do @impl true def install_cmd(:ubuntu) do """ - asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git - bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring - asdf install nodejs 9.0.0 + asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git + bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring + asdf install nodejs 9.0.0 """ end @impl true def install_cmd(_os) do """ - asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git - bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring - asdf install nodejs 9.0.0 + asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git + bash ~/.asdf/plugins/nodejs/bin/import-release-team-keyring + asdf install nodejs 9.0.0 """ end diff --git a/adifier/lib/adifier/tool/postgresql.ex b/adifier/lib/adifier/tool/postgresql.ex index d23bc76..7d1517d 100644 --- a/adifier/lib/adifier/tool/postgresql.ex +++ b/adifier/lib/adifier/tool/postgresql.ex @@ -12,9 +12,9 @@ defmodule Adifier.Tool.Postgresql do """ sudo sh -c " apt-get -y install linux-headers-$(uname -r) build-essential - apt-get -y install libreadline-dev - asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git - asdf install postgres 9.6.2 + apt-get -y install libreadline-dev + asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git + asdf install postgres 9.6.2 " """ end @@ -24,9 +24,9 @@ defmodule Adifier.Tool.Postgresql do """ sudo sh -c " apt-get -y install linux-headers-$(uname -r) build-essential - apt-get -y install libreadline-dev - asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git - asdf install postgres 9.6.2 + apt-get -y install libreadline-dev + asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git + asdf install postgres 9.6.2 " """ end @@ -34,8 +34,8 @@ defmodule Adifier.Tool.Postgresql do @impl true def install_cmd(_os) do """ - asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git - asdf install postgres 9.6.2 + asdf plugin-add postgres https://github.com/smashedtoatoms/asdf-postgres.git + asdf install postgres 9.6.2 """ end diff --git a/adifier/lib/adifier/tool/ruby.ex b/adifier/lib/adifier/tool/ruby.ex index a52697c..03ca0c5 100644 --- a/adifier/lib/adifier/tool/ruby.ex +++ b/adifier/lib/adifier/tool/ruby.ex @@ -7,16 +7,16 @@ defmodule Adifier.Tool.Ruby do @impl true def install_cmd(:ubuntu) do """ - asdf plugin-add ruby - asdf install ruby 2.5.0 + asdf plugin-add ruby + asdf install ruby 2.5.0 """ end @impl true def install_cmd(_os) do """ - asdf plugin-add ruby - asdf install ruby 2.5.0 + asdf plugin-add ruby + asdf install ruby 2.5.0 """ end diff --git a/adifier/lib/adifier/tool/spideroak.ex b/adifier/lib/adifier/tool/spideroak.ex index 0b4c6c8..d41979c 100644 --- a/adifier/lib/adifier/tool/spideroak.ex +++ b/adifier/lib/adifier/tool/spideroak.ex @@ -1,6 +1,6 @@ defmodule Adifier.Tool.Spideroak do @moduledoc """ - This is a half decent backup tool! + This is a half decent backup tool! """ use Adifier.Tool @@ -10,9 +10,9 @@ defmodule Adifier.Tool.Spideroak do """ sudo sh -c " deb http://apt.spideroak.com/ubuntu-spideroak-hardy/ release restricted - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 573E3D1C51AE1B3D - apt-get -y update - apt-get -y install spideroakone + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 573E3D1C51AE1B3D + apt-get -y update + apt-get -y install spideroakone " """ end @@ -22,9 +22,9 @@ defmodule Adifier.Tool.Spideroak do """ sudo sh -c " deb http://apt.spideroak.com/ubuntu-spideroak-hardy/ release restricted - apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 573E3D1C51AE1B3D - apt-get -y update - apt-get -y install spideroakone + apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 573E3D1C51AE1B3D + apt-get -y update + apt-get -y install spideroakone " """ end diff --git a/adifier/lib/applier.ex b/adifier/lib/applier.ex index 8d0914c..4f4269f 100644 --- a/adifier/lib/applier.ex +++ b/adifier/lib/applier.ex @@ -10,9 +10,9 @@ defmodule Adifier.Applier do @behaviour unquote(__MODULE__) @impl true - def run(_, _), do: raise "run/2 isn't defined for #{__MODULE__}" + def run(_, _), do: raise("run/2 isn't defined for #{__MODULE__}") - defoverridable [run: 2] + defoverridable run: 2 end end end diff --git a/adifier/lib/appliers/configurations.ex b/adifier/lib/appliers/configurations.ex index 63fdb4f..a424e3d 100644 --- a/adifier/lib/appliers/configurations.ex +++ b/adifier/lib/appliers/configurations.ex @@ -7,6 +7,6 @@ defmodule Adifier.Applier.Configurations do @behaviour Adifier.Applier def run(os, noconfirm) do - Logger.warn "No Configurations setup" + Logger.warn("No Configurations setup") end end diff --git a/adifier/lib/appliers/package_manager_updater.ex b/adifier/lib/appliers/package_manager_updater.ex index 4977e5f..e196d69 100644 --- a/adifier/lib/appliers/package_manager_updater.ex +++ b/adifier/lib/appliers/package_manager_updater.ex @@ -18,19 +18,26 @@ defmodule Adifier.Applier.PackageManagerUpdater do @impl true def run(os, noconfirm) do case noconfirm || IO.gets(ask(os)) do - true -> update_pm(os) - "Y" <> _tali -> update_pm(os) - "y" <> _tali -> update_pm(os) + true -> + update_pm(os) + + "Y" <> _tali -> + update_pm(os) + + "y" <> _tali -> + update_pm(os) + _ -> - Logger.warn "Not updating Package Manager..." + Logger.warn("Not updating Package Manager...") {:ok, :done} end end def update_pm(os) do - Logger.info "Updating Package Manager" + Logger.info("Updating Package Manager") - result = os + result = + os |> Adifier.PackageManager.pm_update_cmd() |> Adifier.Invoker.call() diff --git a/adifier/lib/appliers/tools_installer.ex b/adifier/lib/appliers/tools_installer.ex index c24162a..adb406a 100644 --- a/adifier/lib/appliers/tools_installer.ex +++ b/adifier/lib/appliers/tools_installer.ex @@ -15,73 +15,83 @@ defmodule Adifier.Applier.ToolsInstaller do @tool_modules |> Enum.map(&Module.concat("Adifier.Tool", &1)) |> Enum.map(&install_with_prompt(os, &1)) + {:ok, :done} end defp install_with_prompt(os, package) when is_binary(package) do - proceed = IO.gets """ - Adify wants to install package, #{package}. - Proceed? (Y/N) - """ + proceed = + IO.gets(""" + Adify wants to install package, #{package}. + Proceed? (Y/N) + """) + case proceed do - "Y" <> _tail -> - Logger.info """ + "Y" <> _tail -> + Logger.info(""" Installing package #{package} - """ + """) os |> Adifier.Tool.BasicTools.install_cmd(package) |> Adifier.Invoker.call() - "y" <> _tail -> - Logger.info """ + "y" <> _tail -> + Logger.info(""" Installing package #{package} - """ + """) os |> Adifier.Tool.BasicTools.install_cmd(package) |> Adifier.Invoker.call() _ -> - Logger.warn """ + Logger.warn(""" Skipping package #{package} - """ + """) + nil end end defp install_with_prompt(os, package) do - proceed = IO.gets """ - Adify wants to install package, #{package}. - Proceed? (Y/N) - """ + proceed = + IO.gets(""" + Adify wants to install package, #{package}. + Proceed? (Y/N) + """) case proceed do - "Y" <> _tail -> - Logger.info """ + "Y" <> _tail -> + Logger.info(""" Installing package #{package} - """ + """) + Elixir |> Module.concat(package) |> apply(:install_cmd, [os]) |> Adifier.Invoker.call() - "y" <> _tail -> - Logger.info """ + + "y" <> _tail -> + Logger.info(""" Installing package #{package} - """ + """) + Elixir |> Module.concat(package) |> apply(:install_cmd, [os]) |> Adifier.Invoker.call() + _ -> - Logger.warn """ + Logger.warn(""" Skipping package #{package} - """ + """) + nil end end defp run_cmd(cmd) do - System.cmd("sh", ["-c" , cmd], into: IO.stream(:stdio, :line)) + System.cmd("sh", ["-c", cmd], into: IO.stream(:stdio, :line)) end end diff --git a/adifier/lib/mix/tasks/adify.ex b/adifier/lib/mix/tasks/adify.ex index 51eb1b7..d092099 100644 --- a/adifier/lib/mix/tasks/adify.ex +++ b/adifier/lib/mix/tasks/adify.ex @@ -10,8 +10,7 @@ defmodule Mix.Tasks.Adify do @aliases [o: :os] def run(argv) do - {parsed, _, _} = - OptionParser.parse(argv, switches: @switches, aliases: @aliases) + {parsed, _, _} = OptionParser.parse(argv, switches: @switches, aliases: @aliases) appliers = ~w{ToolsInstaller Configurations} @@ -23,6 +22,6 @@ defmodule Mix.Tasks.Adify do appliers = Keyword.put(parsed, :appliers, appliers) - adify parsed + adify(parsed) end end diff --git a/adifier/mix.exs b/adifier/mix.exs index 415263c..27f1a09 100644 --- a/adifier/mix.exs +++ b/adifier/mix.exs @@ -4,25 +4,20 @@ defmodule Adifier.Mixfile do def project do [ app: :adifier, - version: "0.1.0", - elixir: "~> 1.5", - start_permanent: Mix.env == :prod, + version: "0.0.1", + elixir: "~> 1.8", + start_permanent: Mix.env() == :prod, deps: deps() ] end - # Run "mix help compile.app" to learn about applications. def application do [ extra_applications: [:logger] ] end - # Run "mix help deps" to learn about dependencies. defp deps do - [ - # {:dep_from_hexpm, "~> 0.3.0"}, - # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, - ] + [] end end diff --git a/adifier/test/adifier_test.exs b/adifier/test/adifier_test.exs index 84e3aef..d20a62b 100644 --- a/adifier/test/adifier_test.exs +++ b/adifier/test/adifier_test.exs @@ -1,8 +1,4 @@ defmodule AdifierTest do use ExUnit.Case doctest Adifier - - test "greets the world" do - # assert Adifier.hello() == :world - end end