-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from aditya7iyengar/feature/wrap_around_c
Feature/wrap around ruby
- Loading branch information
Showing
20 changed files
with
667 additions
and
369 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
elixir 1.5.2 | ||
erlang 21.0 | ||
elixir 1.6.6 |
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,2 @@ | ||
#!/bin/bash | ||
zenity --password --title=Authentication |
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
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,17 @@ | ||
defmodule Adifier.Invoker do | ||
@moduledoc """ | ||
This module invokes a command with specific command options. | ||
""" | ||
|
||
@cmd_opts [into: IO.stream(:stdio, :line)] | ||
|
||
@doc false | ||
def call("sudo" <> cmd) do | ||
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], @cmdopts) | ||
end | ||
end |
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 |
---|---|---|
@@ -1,25 +1,23 @@ | ||
defmodule Adifier.PackageManager do | ||
@moduledoc """ | ||
This module's responsibility is to return command to install a given `package` | ||
on a given `os`, or return command to update a package manager.`Adifier.Tool` | ||
and `Adifier.PackageManager` delegate to this module by default. | ||
""" | ||
|
||
@needsudo ~w(apt apt-get yum) | ||
@needyes ~w(apt apt-get yum) | ||
@cmdopts [into: IO.stream(:stdio, :line)] | ||
|
||
def package_managers(:ubuntu), do: ~w(apt apt-get) | ||
def package_managers(:centos), do: ~w(yum) | ||
def package_managers(:mac), do: ~w(brew) | ||
|
||
def invoke_cmd(pm, with: str) when pm in @needsudo do | ||
System.cmd("sudo", ["-A", pm | String.split(str)], | ||
[env: [{"SUDO_ASKPASS", "/usr/bin/ssh-askpass"}]] ++ @cmdopts) | ||
def install_cmd(:arch_linux, pkg), do: "sudo pacman -S #{pkg} --no-confirm" | ||
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 invoke_cmd(pm, with: str) do | ||
System.cmd(pm, String.split(str), @cmdopts) | ||
def install_cmd(os, pkg) when os in [:centos, :fedora] do | ||
"sudo yum -y install #{pkg}" | ||
end | ||
|
||
def update_cmd(pm), do: invoke_cmd(pm, with: "update") | ||
|
||
def install_pkg(pm, pkg) when pm in @needyes, do: invoke_cmd(pm, with: "install -y #{pkg}") | ||
def install_pkg(pm, pkg), do: invoke_cmd(pm, with: "install #{pkg}") | ||
def pm_update_cmd(:arch_linux), do: "sudo pacman -Syu --noconfirm" | ||
def pm_update_cmd(:debian), do: "sudo apt -y update" | ||
def pm_update_cmd(:mac), do: "brew update" | ||
def pm_update_cmd(os) when os in [:ubuntu, :pop_os], do: "sudo apt-get -y update" | ||
def pm_update_cmd(os) when os in [:centos, :fedora], do: "sudo yum -y update" | ||
end |
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 |
---|---|---|
@@ -1,29 +1,89 @@ | ||
defmodule Adifier.Tool do | ||
@moduledoc """ | ||
Represents metadata related to a tool. | ||
Defines a `struct` with following variables: | ||
* `ran_at`: `Datetime` | ||
* `name` : `String` | ||
* `install_cmd`: `String` | ||
* `description` : `String` | ||
* `errors` : `String` | ||
Defines a `behaviour` with two `callbacks`: | ||
* `install_cmd/1`: This function returns the command used to install the | ||
tool on the `os` (given as the argument) | ||
* `description/0`: This function returns a the description of the `tool`. | ||
* `__name__/0`: This function returns the `name` of the `tool` being installed. | ||
""" | ||
@enforce_keys ~w{ran_at name install_cmd description}a | ||
|
||
defstruct ~w{errors}a ++ @enforce_keys | ||
|
||
import Adifier.PackageManager | ||
@type t :: %__MODULE__{ | ||
ran_at: Datetime.t(), | ||
name: String.t(), | ||
install_cmd: String.t(), | ||
description: String.t() | ||
} | ||
|
||
@callback install_cmd(Atom.t()) :: {:ok, term} | {:error, String.t()} | ||
@callback description() :: String.t | ||
@callback install_cmd(Atom.t()) :: {:ok | :error, __MODULE__.t()} | ||
@callback description() :: String.t() | ||
@callback __name__() :: String.t() | ||
|
||
defmacro __using__(_opts) do | ||
quote do | ||
import Adifier.PackageManager | ||
@doc """ | ||
This macro allows us to exploit the default behaviour of | ||
`Adifier.Tool` module. | ||
def install_cmd(os) do | ||
raise "#{__MODULE__}.install_cmd/1 not implemented for os: #{os}" | ||
## USAGE | ||
```elixir | ||
defmodule Test.Tool do | ||
use Adifier.Tool, name: "tool" | ||
def description do | ||
"This tool runs `tool` tool" | ||
end | ||
end | ||
``` | ||
""" | ||
defmacro __using__(opts \\ []) do | ||
name = Keyword.get(opts, :name, :default) | ||
|
||
quote location: :keep do | ||
import unquote(__MODULE__) | ||
alias Adifier.PackageManager, as: PacMan | ||
|
||
@behaviour unquote(__MODULE__) | ||
|
||
@impl true | ||
def install_cmd(os), do: PacMan.install_cmd(os, __name__()) | ||
|
||
@impl true | ||
def __name__ do | ||
case unquote(name)do | ||
:default -> unquote(__MODULE__).__get_name__(__MODULE__) | ||
name -> name | ||
end | ||
end | ||
|
||
# TODO: Move to module attribute | ||
def description() do | ||
@impl true | ||
def description do | ||
raise """ | ||
No description given for module: #{__MODULE__}.. | ||
No description given for module: #{__MODULE__}. | ||
Please define the function #{__MODULE__}.description/0 | ||
""" | ||
end | ||
|
||
defoverridable [install_cmd: 1, description: 0] | ||
end | ||
end | ||
|
||
@doc false | ||
def __get_name__(module) do | ||
module | ||
|> Module.split() | ||
|> Enum.at(-1) | ||
|> String.downcase() | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
defmodule Adifier.Tool.Chromium do | ||
@moduledoc """ | ||
Chromium is an open-source browser project that aims to build a safer, | ||
faster, and more stable way for all Internet users to experience the web. | ||
""" | ||
|
||
use Adifier.Tool | ||
use Adifier.Tool, name: "chromium-browser" | ||
|
||
def install_cmd(:ubuntu) do | ||
@impl true | ||
def install_cmd(:mac) do | ||
""" | ||
sudo apt install chromium-browser | ||
brew tap domt4/chromium | ||
brew cask install mac-chromium | ||
""" | ||
end | ||
def install_cmd(os), do: super(os) | ||
|
||
def description() do | ||
""" | ||
Chromium is an open-source browser project that aims to build a safer, | ||
faster, and more stable way for all Internet users to experience the web. | ||
This is my default browser, as I don't have to worry about the RAM usage | ||
a lot | ||
""" | ||
end | ||
@impl true | ||
def description, do: @moduledoc | ||
end |
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,6 @@ | ||
defmodule Adifier.Tool.Clang do | ||
@moduledoc """ | ||
""" | ||
|
||
use Adifier.Tool, name: "clang" | ||
end |
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,18 @@ | ||
defmodule Adifier.Tool.Curl do | ||
@moduledoc """ | ||
CUrl is a tool to transfer data from or to a server, using one of the | ||
supported protocols (`DICT`, `FILE`, `FTP`, `FTPS`, `GOPHER`, `HTTP`, `HTTPS`, | ||
`IMAP`, `IMAPS`, `LDAP`, `LDAPS`, `POP3`, `POP3S`, `RTMP`, `RTSP`, `SCP`, | ||
`SFTP`, `SMB`, `SMBS`, `SMTP`, `SMTPS`, `TELNET` and `TFTP`). The command is | ||
designed to work without user interaction. | ||
CUrl offers a busload of useful tricks like proxy support, user | ||
authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer | ||
resume, Met‐ alink, and more. | ||
""" | ||
|
||
use Adifier.Tool, name: "curl" | ||
|
||
@impl true | ||
def description, do: @moduledoc | ||
end |
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
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 |
---|---|---|
@@ -1,23 +1,35 @@ | ||
defmodule Adifier.Tool.GoogleChrome do | ||
@moduledoc """ | ||
Google Chrome is a fast, secure, and free web browser, built for the modern web. | ||
""" | ||
|
||
use Adifier.Tool | ||
use Adifier.Tool, name: "google-chrome" | ||
|
||
@impl true | ||
def install_cmd(:ubuntu) do | ||
""" | ||
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - | ||
echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/google-chrome.list | ||
sudo apt-get update | ||
sudo apt-get install google-chrome-stable<Paste> | ||
sudo apt-get install google-chrome-stable | ||
""" | ||
end | ||
|
||
def description() do | ||
def install_cmd(:arch_linux) do | ||
""" | ||
git clone https://aur.archlinux.org/google-chrome.git ~/.adify/temp/tools/google-chrome/ | ||
cd ~/.adify/temp/tools/google-chrome/ | ||
makepkg -s --noconfirm | ||
sudo pacman -U --noconfirm google-chrome-*.pkg.tar.xz | ||
""" | ||
One fast, simple, and secure browser for all your devices. | ||
This is my browser for personal, non-work related usage. | ||
""" | ||
end | ||
def install_cmd(:mac) do | ||
""" | ||
brew install brew-cask | ||
brew cask install google-chrome | ||
""" | ||
end | ||
def install_cmd(os), do: super(os) | ||
|
||
@impl true | ||
def description, do: @moduledoc | ||
end |
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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
defmodule Adifier.Tool.Mysql do | ||
@moduledoc """ | ||
The most popular Open-source Relational Database Mangement System. | ||
""" | ||
|
||
use Adifier.Tool | ||
use Adifier.Tool, name: "mysql" | ||
|
||
@impl true | ||
def install_cmd(:ubuntu) do | ||
""" | ||
sudo apt-get update sudo apt-get install mysql-server | ||
sudo apt-get -y install mysql-server | ||
/usr/bin/mysql_secure_installation | ||
sudo service mysql start | ||
sudo systemctl start mysql | ||
""" | ||
end | ||
def install_cmd(os), do: super(os) | ||
|
||
def description() do | ||
""" | ||
The most popular RDMS! | ||
You WILL need it! | ||
""" | ||
end | ||
@impl true | ||
def description, do: @moduledoc | ||
end |
Oops, something went wrong.