diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b2b6be..1b5c324 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,8 @@ If you have a bug fix, performance improvement, feature addition, documentation ### Coding +#### Dart + It does not really matter what editor you use; however, if you want to contribute to the Dart codebase and do not want to set up Dart on your local machine, you can use a containerized development environment with all of the requirements built-in. Here are two options: 1. Gitpod. This repo has a Gitpod config already setup, so all you have to do is visit: https://gitpod.io/#https://github.com/nyoungstudios/alfa. Or replace my GitHub url with your fork. @@ -31,6 +33,10 @@ It does not really matter what editor you use; however, if you want to contribut To build the Dart executable, just run `make` from the repository's root directory. Then, run the `./rename.sh` script to rename the executable to the filename the `install.sh` script expects. +#### Entries (Bash script functions) + +If you like to contribute a new entry with a function to install something, you can run this script `./tools/create_function.sh entry_name` from the repo's root directory to create the boilerplate code. For the guidelines and best practices for writing your function, please see the example [here](functions/_example/). + ### Style This respository uses EditorConfig to define the number of spaces for indentation as well as removing excess white characters. A lot of editors come bundled with native support, but if not you can always install an EditorConfig extension. For more information, visit their [website](https://editorconfig.org). Additionally, if you are using VS Code and are contributing to the Dart codebase, this repo includes a `settings.json` file with the recommended Dart style guidelines. diff --git a/README.md b/README.md index 48c0377..1f17894 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Config files are defined as `toml` files. This has the benefits of JSON, but fri The schema for the config file can be found [here](docs/ConfigSchema.md). -All the installation scripts are bash scripts, and they are defined in the [functions.sh](functions.sh) file. This script includes the functions to install popular tools such as brew, Oh My Zsh (and plugins), Anaconda, NVM, Docker, and much more! The documentation for all of the things you can install (along with its input arguments) can be found [here](docs/entries/). If there is not a function to install your favorite tool(s), it is easy to extend the bash script with a new function (and open a PR with your contribution). +All the different things that you can install are defined in the [functions](functions/) folder. Take a look at the `README.md` for each of the function entries to see how to add them to your configuration file and what options to pass to it. The built-in functions includes the ability to install popular tools such as brew, Oh My Zsh (and plugins), Anaconda, NVM, Docker, and much more! If there is not an entry to install your favorite tool(s), it is easy to add a new entry - just run `./tools/create_function.sh entry_name` from the repository's root directory to get started. ### Install list file diff --git a/bin/alfa.dart b/bin/alfa.dart index d6b2b2f..7c7a5a4 100644 --- a/bin/alfa.dart +++ b/bin/alfa.dart @@ -86,15 +86,14 @@ void main(List args) async { Map> tagToInstallKey = {}; for (MapEntry e in config.entries) { - for (String tag in e.value['tags']) { - tagToInstallKey.putIfAbsent(tag, () => []).add(e.key); + var tags = e.value['tags']; + if (tags != null) { + for (String tag in e.value['tags']) { + tagToInstallKey.putIfAbsent(tag, () => []).add(e.key); + } } } - // gets map of names to install functions - var dictionaryFile = await TomlDocument.load('dictionary.toml'); - var dictionary = dictionaryFile.toMap(); - // stores an ordered set of the names of the things to install var namesToInstall = Set(); @@ -108,8 +107,8 @@ void main(List args) async { if (tagToInstallKey.containsKey(line)) { namesToInstall.addAll(tagToInstallKey[line]); // in the case where the tag and config name has the same name - if (dictionary.containsKey(line.split('+')[0]) && - config.containsKey(line)) { + if (config.containsKey(line) && + await File("functions/${line.split('+')[0]}/install.sh").exists()) { namesToInstall.add(line); } } else { @@ -118,32 +117,48 @@ void main(List args) async { } } + // for storing map of names to install functions + Map dictionary = {}; List filteredNamesToInstall = []; // filters invalid names to install for (String name in namesToInstall) { var baseName = name.split('+')[0]; - if (!dictionary.containsKey(baseName)) { + String installScriptPath = "functions/${baseName}/install.sh"; + String configTomlPath = "functions/${baseName}/config.toml"; + File installScript = File(installScriptPath); + File configToml = File(configTomlPath); + + if (!config.containsKey(name)) { print( - "dictionary.toml does not have a reference for \"${baseName}\" to install."); + "${argResults['config']} does not have a reference for \"${name}\" to install."); print("Installer exiting"); exit(1); - } else if (!config.containsKey(name)) { + } else if (!await installScript.exists()) { print( - "${argResults['config']} does not have a reference for \"${name}\" to install."); + "Trying to install \"${baseName}\", but install script \"${installScriptPath}\" does not exist."); + print("Installer exiting"); + exit(1); + } else if (!await configToml.exists()) { + print( + "Trying to install \"${baseName}\", but config \"${configTomlPath}\" does not exist."); print("Installer exiting"); exit(1); } else if (config[name].containsKey("os") && !config[name]['os'].contains(osName)) { print( "Skipping install of \"${name}\" since the operating system, ${osName}, is not in ${config[name]['os']}."); - } else if (!dictionary[baseName].containsKey("install_function") && - !dictionary[baseName].containsKey(osName)) { - print( - "Skipping install of \"${name}\" since there is no install function for \"${baseName}\" on operating system, ${osName}."); } else { - filteredNamesToInstall.add(name); + var tempConfig = await TomlDocument.load(configTomlPath); + dictionary[baseName] = tempConfig.toMap(); + if (!dictionary[baseName].containsKey("install_function") && + !dictionary[baseName].containsKey(osName)) { + print( + "Skipping install of \"${name}\" since there is no install function for \"${baseName}\" on operating system, ${osName}."); + } else { + filteredNamesToInstall.add(name); + } } } @@ -173,7 +188,7 @@ void main(List args) async { var functionName = functionMap["install_function"]; - String command = 'source functions.sh; ${functionName}'; + String command = 'source functions/${baseName}/install.sh; ${functionName}'; // checks if there are any options to pass when installing this if (config[name].containsKey("options") && @@ -190,7 +205,8 @@ void main(List args) async { arguments = ['-u', user]; } - arguments.addAll(['--preserve-env=ALFA_USER,ALFA_ARCH', '--', '/bin/bash']); + arguments + .addAll(['--preserve-env=ALFA_USER,ALFA_ARCH', '--', '/bin/bash']); } arguments.addAll(['-euc', command]); diff --git a/dictionary.toml b/dictionary.toml deleted file mode 100644 index 3dd981c..0000000 --- a/dictionary.toml +++ /dev/null @@ -1,90 +0,0 @@ -# This file contains all names of things that you can install and the references to the appropriate shell function in functions.sh -# Here is the schema if you want to add more references to this dictionary -# [ name ] (the name that will referenced in your config.toml file) -# install_function = "function_name_in_functions.sh" -# sudo = false (false by default, true if you need sudo permissions to run the install function) -# -# if you have two different functions that will be called based on if the operating system is macos or linux, then nest the -# install_function and sudo keys under the os name. - -[ git_config ] -install_function = "create_git_config" - -[ brew ] -install_function = "install_brew" - -[ brew_packages ] -install_function = "brew_install" - -[ brew_cask_packages ] -install_function = "brew_install_cask" - -[ apt_get_packages ] -linux.install_function = "apt_get_install" -linux.sudo = true - -[ deb_package ] -linux.install_function = "install_deb_package" -linux.sudo = true - -[ snap_package ] -linux.install_function = "install_snap_package" -linux.sudo = true - -[ ohmyzsh ] -install_function = "install_ohmyzsh" - -[ zsh_successful_cmd_filter ] -install_function = "install_zsh_successful_cmd_filter" - -[ install_ohmyzsh_plugins ] -install_function = "install_ohmyzsh_plugins" - -[ add_ohmyzsh_plugins ] -macos.install_function = "add_ohmyzsh_plugins_macos" -linux.install_function = "add_ohmyzsh_plugins_linux" - -[ p10k ] -macos.install_function = "prettify_terminal_macos" -linux.install_function = "prettify_terminal_linux" - -[ zshenv ] -install_function = "append_to_zshenv" - -[ vimrc ] -install_function = "install_vimrc" - -[ jetbrains_toolbox ] -linux.install_function = "install_jetbrains_toolbox" - -[ docker ] -linux.install_function = "install_docker" -linux.sudo = true - -[ anaconda ] -macos.install_function = "install_anaconda3_macos" -linux.install_function = "install_anaconda3_linux" - -[ nvm ] -install_function = "install_nvm" - -[ node_lts ] -install_function = "install_node_lts" - -[ node_version ] -install_function = "install_node" - -[ sdkman ] -install_function = "install_sdkman" - -[ sdk_candidate ] -install_function = "install_sdk_candidate" - -[ atom_packages ] -install_function = "install_atom_packages" - -[ vscode_extensions ] -install_function = "install_vscode_extensions" - -[ git_clone ] -install_function = "git_clone_repo" diff --git a/docs/ConfigSchema.md b/docs/ConfigSchema.md index 71874e7..a1a2279 100644 --- a/docs/ConfigSchema.md +++ b/docs/ConfigSchema.md @@ -15,7 +15,7 @@ options = [] ### Name -The `name` field refers to the `name` field in the `dictionary.toml` file. Looking at the `dictionary.toml` file, you can find the associated bash function that is called in the `functions.sh` file. The name field is also what you would put in the install list file (passed with the `-f` argument in the `install.sh` script). Alternatively, you can always write a more friendly name in the `tags` array. See the next section for more detail on that. +The `name` field refers any of the folder names in the [functions](../functions/) directory. Read the `README.md` file within each of the folders and/or take a look at the `install.sh` file to see what any given entry does upon being called. The name field in your config is also what you would put in the install list file (passed with the `-f` argument in the `install.sh` script). Alternatively, you can always write a more friendly name in the `tags` array. See the next section for more detail on that. If you like to call a function more than once, but with different options; then, you can append a plus sign after the name followed by a string to help you remember what that entry does (sort of like email address aliases). This is so we do not have duplicate keys within the dictionary in the toml file. For example, if we wanted to call the `apt_get_packages` function twice, we could do something like this. diff --git a/docs/InstallListSchema.md b/docs/InstallListSchema.md index 3d5bd0a..7df0ed0 100644 --- a/docs/InstallListSchema.md +++ b/docs/InstallListSchema.md @@ -30,3 +30,10 @@ name // name2 custom ``` + +And in this case, only these items would be installed: +```txt +name +item1 +item2 +``` diff --git a/functions.sh b/functions.sh deleted file mode 100755 index 712836a..0000000 --- a/functions.sh +++ /dev/null @@ -1,313 +0,0 @@ -#!/bin/bash -# Contains the shell scripts to install all of your favorite tools -# Do not name the function to install something the same as the command. For example, the function to install brew is not called "brew", but -# rather "install_brew". -# To access the list of "options" in the config.toml file you pass to the installer, use the "$@" variable. -# To access the user that called the installer, do not user the environment variable "$SUDO_USER", but rather use "$ALFA_USER". -# To access the uname -m output (system architecture), you can use the environment variable "$ALFA_ARCH" - -create_git_config() { - # sets up git config name and email - git config --global user.name "$1" - git config --global user.email "$2" - ssh-keygen -q -t rsa -C "$2" -N '' <<< ""$'\n'"y" 2>&1 >/dev/null -} - -install_brew() { - # Installs homebrew - NONINTERACTIVE=1 - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -} - -brew_install() { - # installs brew packages - for package in "$@" - do - brew install "$package" - done -} - -brew_install_cask() { - # installs brew cask packages - for package in "$@" - do - brew install "$package" --cask - done -} - -apt_get_install() { - # installs apt-get packages - apt-get update - apt-get install -y "$@" -} - -install_deb_package() { - # installs a deb package - filepath="/tmp/file_to_install.deb" - wget -O "$filepath" "$@" - apt-get install -y "$filepath" - rm -f "$filepath" -} - -install_snap_package() { - # installs a single snap package - snap install "$@" -} - -install_ohmyzsh() { - # install ohmyzsh - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended -} - -install_zsh_successful_cmd_filter() { - # appends zshaddhistory and precmd hooks - echo "" >> ~/.zshrc - cat templates/zshrc_successful_cmd_hist.zsh >> ~/.zshrc -} - -install_ohmyzsh_plugins() { - # installs plugins for ohmyzsh - for repo in "$@" - do - git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins clone --depth=1 "$repo" - done -} - -add_ohmyzsh_plugins_macos() { - # adds ohmyzsh plugins to zshrc - # replaces default plugin string - sed -i '.old' 's+plugins=(git)+plugins=(\n ### NEW PLUGINS HERE ###\n)+g' ~/.zshrc - - # builds plugin string - plugins="" - for name in "$@" - do - if [[ -z "$plugins" ]]; then - plugins="$name" - else - plugins="${plugins}\n $name" - - fi - done - - plugins="${plugins}\n ### NEW PLUGINS HERE ###" - - # replaces flag with new plugin string - sed -i '.old' "s+### NEW PLUGINS HERE ###+${plugins}+g" ~/.zshrc - - rm ~/.zshrc.old -} - -add_ohmyzsh_plugins_linux() { - # adds ohmyzsh plugins to zshrc - # replaces default plugin string - sed -i 's+plugins=(git)+plugins=(\n ### NEW PLUGINS HERE ###\n)+g' ~/.zshrc - - # builds plugin string - plugins="" - for name in "$@" - do - if [[ -z "$plugins" ]]; then - plugins="$name" - else - plugins="${plugins}\n $name" - - fi - done - - plugins="${plugins}\n ### NEW PLUGINS HERE ###" - - # replaces flag with new plugin string - sed -i "s+### NEW PLUGINS HERE ###+${plugins}+g" ~/.zshrc -} - -prettify_terminal_macos() { - # clone Powerlevel10k repo and copy .p10k.zsh config file - echo "Cloning Powerlevel10k theme" - git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k - cp templates/.p10k.zsh ~/.p10k.zsh - - # edit the .zshrc - echo "Changing .zshrc file to Powerlevel10k theme" - cat ~/.zshrc | pbcopy && cat templates/p10k_init.zsh templates/zshrc_disable_flag.zsh > ~/.zshrc && pbpaste >> ~/.zshrc - echo "" >> ~/.zshrc - cat templates/p10k_config.zsh >> ~/.zshrc - - # replaces the default theme with the p10k theme - sed -i '.old' 's+ZSH_THEME="robbyrussell"+ZSH_THEME="powerlevel10k/powerlevel10k"+g' ~/.zshrc - rm ~/.zshrc.old -} - -prettify_terminal_linux() { - # clone Powerlevel10k repo and copy .p10k.zsh config file - echo "Cloning Powerlevel10k theme" - git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k - cp templates/.p10k.zsh ~/.p10k.zsh - - # edit the .zshrc - echo "Changing .zshrc file to Powerlevel10k theme" - sed -i '1 e cat templates/p10k_init.zsh && cat templates/zshrc_disable_flag.zsh' ~/.zshrc - echo "" >> ~/.zshrc - cat templates/p10k_config.zsh >> ~/.zshrc - - # replaces the default theme with the p10k theme - sed -i 's+ZSH_THEME="robbyrussell"+ZSH_THEME="powerlevel10k/powerlevel10k"+g' ~/.zshrc -} - -append_to_zshenv() { - # appends a line to zshenv file - for line in "$@" - do - echo "$line" >> ~/.zshenv - done -} - -install_vimrc() { - # install ultimate vimrc - git clone --depth=1 https://github.com/nyoungstudios/vimrc.git ~/.vim_runtime - sh ~/.vim_runtime/install_awesome_vimrc.sh - git config --global core.editor "vim" -} - -install_jetbrains_toolbox() { - # installs the jetbrains toolbox app (also should be run in non root mode) - filepath="/tmp/jetbrains-toolbox.tar.gz" - output_folder="/tmp/jetbrains-toolbox-tmp" - version="jetbrains-toolbox-1.25.12627" - mkdir -p "$output_folder" - wget -O "$filepath" "https://download.jetbrains.com/toolbox/${version}.tar.gz" - tar -xvf "$filepath" -C "$output_folder" - pushd "${output_folder}/${version}" - ./jetbrains-toolbox - popd - rm -rf "$filepath" "$output_folder" -} - -install_docker() { - # installs docker on linux - apt-get update - apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release - mkdir -p /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg - echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null - apt-get update - apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io - - echo "Configuring docker to be run without calling sudo" - groupadd -f docker - gpasswd -a $ALFA_USER docker - echo "Please restart your computer to use docker without calling sudo" -} - -install_anaconda3_common() { - chmod +x ~/anaconda3.sh - bash ~/anaconda3.sh -b -p ~/anaconda3 - rm ~/anaconda3.sh - - echo "Initializing Anaconda3..." - export PATH=~/anaconda3/bin:$PATH - if [[ -f "$HOME/.bashrc" ]]; then - conda init bash - fi - - if [[ -f "$HOME/.zshrc" ]]; then - conda init zsh - fi -} - -install_anaconda3_macos() { - # installs anaconda3 - echo "Installing Anaconda3..." - curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh - install_anaconda3_common -} - -install_anaconda3_linux() { - # installs anaconda3 - echo "Installing Anaconda3..." - curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh - install_anaconda3_common -} - -copy_pip_config() { - # copies pip config - mkdir -p ~/.pip && cp "$1" ~/.pip/pip.conf -} - -install_nvm() { - # installs nvm - if [[ "$1" -eq 0 ]]; then - # nvm installer will not change your profile or rc file. - export PROFILE="/dev/null" - fi - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash -} - -install_node_lts() { - # installs the latest node lts version - NVM_DIR="${NVM_DIR:-$HOME/.nvm}" - . $NVM_DIR/nvm.sh - nvm install --lts -} - -install_node() { - # installs specfied version of node; otherwise, will install latest version - NVM_DIR="${NVM_DIR:-$HOME/.nvm}" - . $NVM_DIR/nvm.sh - if [ -z "$1"]; - then - nvm install node - else - nvm install "$1" - fi -} - -install_sdkman() { - # installs sdkman - curl -s "https://get.sdkman.io?rcupdate=false" | bash - if [[ -f "$HOME/.bashrc" ]]; then - cat templates/sdkman.zsh >> ~/.bashrc - fi - - if [[ -f "$HOME/.zshrc" ]]; then - cat templates/sdkman.zsh >> ~/.zshrc - fi -} - -install_sdk_candidate() { - # installs an sdk candidate - set +eu - source "$HOME/.sdkman/bin/sdkman-init.sh" - sdk install "$@" - set -eu -} - -install_atom_packages() { - # installs atom packages - for package in "$@" - do - apm install "$package" - done -} - -install_vscode_extensions() { - # installs vs code extensions (needs to be installed in non sudo mode) - for extension in "$@" - do - code --install-extension "$extension" - done -} - -git_clone_repo() { - # clones any number of git repositories to a local folder while retaining the - # repo's project name. - # the first argument is the local directory and all arguments following - # are the urls - dir="$1" - shift - mkdir -p "$dir" - for repo in "$@" - do - git -C "$dir" clone "$repo" - done -} diff --git a/functions/_example/README.md b/functions/_example/README.md new file mode 100644 index 0000000..94b1c16 --- /dev/null +++ b/functions/_example/README.md @@ -0,0 +1,22 @@ +# Example + +Configuration for a `_example` entry. + +## Description + +This is a example function for demostration purposes. + +## Options + +Accepts any number of arguments. +- each argument is a printed to stdout + +## Example + +```toml +[ _example ] +options = [ + "arg1", + "arg2" +] +``` diff --git a/functions/_example/config.toml b/functions/_example/config.toml new file mode 100644 index 0000000..bac40cf --- /dev/null +++ b/functions/_example/config.toml @@ -0,0 +1,8 @@ +# The value of the "install_function" key references the bash function name in install.sh +# If you want to run the function in sudo mode, add `sudo = true` +# If you want have separate functions for macos and linux, you can nest the "install_function" +# and "sudo" keys under the operating system name. It will look something like this: +# +# linux.install_function = "install_example_linux" +# macos.install_function = "install_example_macos" +install_function = "install_example" diff --git a/functions/_example/install.sh b/functions/_example/install.sh new file mode 100755 index 0000000..625a099 --- /dev/null +++ b/functions/_example/install.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# A bash script to install something +# Do not name the function to install something the same as an existing command. For example, the function to install brew +# is not called "brew", but rather "install_brew". +# To access the list of "options" in the config.toml file you pass to the installer, use the "$@" variable. +# To access the user that called the installer, do not user the environment variable "$SUDO_USER", but rather use "$ALFA_USER". +# To access the uname -m output (system architecture), you can use the environment variable "$ALFA_ARCH" + +install_example() { + # example function + echo "$ALFA_USER called this function on a $ALFA_ARCH computer" + for item in "$@" + do + echo "$item" + done +} diff --git a/docs/entries/add_ohmyzsh_plugins.md b/functions/add_ohmyzsh_plugins/README.md similarity index 100% rename from docs/entries/add_ohmyzsh_plugins.md rename to functions/add_ohmyzsh_plugins/README.md diff --git a/functions/add_ohmyzsh_plugins/config.toml b/functions/add_ohmyzsh_plugins/config.toml new file mode 100644 index 0000000..b738bb1 --- /dev/null +++ b/functions/add_ohmyzsh_plugins/config.toml @@ -0,0 +1,2 @@ +macos.install_function = "add_ohmyzsh_plugins_macos" +linux.install_function = "add_ohmyzsh_plugins_linux" diff --git a/functions/add_ohmyzsh_plugins/install.sh b/functions/add_ohmyzsh_plugins/install.sh new file mode 100755 index 0000000..829a456 --- /dev/null +++ b/functions/add_ohmyzsh_plugins/install.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +add_ohmyzsh_plugins_macos() { + # adds ohmyzsh plugins to zshrc + # replaces default plugin string + sed -i '.old' 's+plugins=(git)+plugins=(\n ### NEW PLUGINS HERE ###\n)+g' ~/.zshrc + + # builds plugin string + plugins="" + for name in "$@" + do + if [[ -z "$plugins" ]]; then + plugins="$name" + else + plugins="${plugins}\n $name" + + fi + done + + plugins="${plugins}\n ### NEW PLUGINS HERE ###" + + # replaces flag with new plugin string + sed -i '.old' "s+### NEW PLUGINS HERE ###+${plugins}+g" ~/.zshrc + + rm ~/.zshrc.old +} + +add_ohmyzsh_plugins_linux() { + # adds ohmyzsh plugins to zshrc + # replaces default plugin string + sed -i 's+plugins=(git)+plugins=(\n ### NEW PLUGINS HERE ###\n)+g' ~/.zshrc + + # builds plugin string + plugins="" + for name in "$@" + do + if [[ -z "$plugins" ]]; then + plugins="$name" + else + plugins="${plugins}\n $name" + + fi + done + + plugins="${plugins}\n ### NEW PLUGINS HERE ###" + + # replaces flag with new plugin string + sed -i "s+### NEW PLUGINS HERE ###+${plugins}+g" ~/.zshrc +} diff --git a/docs/entries/anaconda.md b/functions/anaconda/README.md similarity index 100% rename from docs/entries/anaconda.md rename to functions/anaconda/README.md diff --git a/functions/anaconda/config.toml b/functions/anaconda/config.toml new file mode 100644 index 0000000..4d7091f --- /dev/null +++ b/functions/anaconda/config.toml @@ -0,0 +1,2 @@ +macos.install_function = "install_anaconda3_macos" +linux.install_function = "install_anaconda3_linux" diff --git a/functions/anaconda/install.sh b/functions/anaconda/install.sh new file mode 100755 index 0000000..c01ed38 --- /dev/null +++ b/functions/anaconda/install.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +install_anaconda3_macos() { + # installs anaconda3 + echo "Installing Anaconda3..." + curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-MacOSX-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh + install_anaconda3_common +} + +install_anaconda3_common() { + chmod +x ~/anaconda3.sh + bash ~/anaconda3.sh -b -p ~/anaconda3 + rm ~/anaconda3.sh + + echo "Initializing Anaconda3..." + export PATH=~/anaconda3/bin:$PATH + if [[ -f "$HOME/.bashrc" ]]; then + conda init bash + fi + + if [[ -f "$HOME/.zshrc" ]]; then + conda init zsh + fi +} + +install_anaconda3_linux() { + # installs anaconda3 + echo "Installing Anaconda3..." + curl "${1:-https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-${ALFA_ARCH}.sh}" -o ~/anaconda3.sh + install_anaconda3_common +} diff --git a/docs/entries/apt_get_packages.md b/functions/apt_get_packages/README.md similarity index 100% rename from docs/entries/apt_get_packages.md rename to functions/apt_get_packages/README.md diff --git a/functions/apt_get_packages/config.toml b/functions/apt_get_packages/config.toml new file mode 100644 index 0000000..0598819 --- /dev/null +++ b/functions/apt_get_packages/config.toml @@ -0,0 +1,2 @@ +linux.install_function = "apt_get_install" +linux.sudo = true diff --git a/functions/apt_get_packages/install.sh b/functions/apt_get_packages/install.sh new file mode 100755 index 0000000..7ecc799 --- /dev/null +++ b/functions/apt_get_packages/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +apt_get_install() { + # installs apt-get packages + apt-get update + apt-get install -y "$@" +} diff --git a/docs/entries/atom_packages.md b/functions/atom_packages/README.md similarity index 100% rename from docs/entries/atom_packages.md rename to functions/atom_packages/README.md diff --git a/functions/atom_packages/config.toml b/functions/atom_packages/config.toml new file mode 100644 index 0000000..b8efa07 --- /dev/null +++ b/functions/atom_packages/config.toml @@ -0,0 +1 @@ +install_function = "install_atom_packages" diff --git a/functions/atom_packages/install.sh b/functions/atom_packages/install.sh new file mode 100755 index 0000000..aaeebf4 --- /dev/null +++ b/functions/atom_packages/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +install_atom_packages() { + # installs atom packages + for package in "$@" + do + apm install "$package" + done +} diff --git a/docs/entries/brew.md b/functions/brew/README.md similarity index 100% rename from docs/entries/brew.md rename to functions/brew/README.md diff --git a/functions/brew/config.toml b/functions/brew/config.toml new file mode 100644 index 0000000..c884103 --- /dev/null +++ b/functions/brew/config.toml @@ -0,0 +1 @@ +install_function = "install_brew" diff --git a/functions/brew/install.sh b/functions/brew/install.sh new file mode 100755 index 0000000..325f279 --- /dev/null +++ b/functions/brew/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +install_brew() { + # Installs homebrew + NONINTERACTIVE=1 + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +} diff --git a/docs/entries/brew_cask_packages.md b/functions/brew_cask_packages/README.md similarity index 100% rename from docs/entries/brew_cask_packages.md rename to functions/brew_cask_packages/README.md diff --git a/functions/brew_cask_packages/config.toml b/functions/brew_cask_packages/config.toml new file mode 100644 index 0000000..dcb62bd --- /dev/null +++ b/functions/brew_cask_packages/config.toml @@ -0,0 +1 @@ +install_function = "brew_install_cask" diff --git a/functions/brew_cask_packages/install.sh b/functions/brew_cask_packages/install.sh new file mode 100755 index 0000000..782db91 --- /dev/null +++ b/functions/brew_cask_packages/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +brew_install_cask() { + # installs brew cask packages + for package in "$@" + do + brew install "$package" --cask + done +} diff --git a/docs/entries/brew_packages.md b/functions/brew_packages/README.md similarity index 100% rename from docs/entries/brew_packages.md rename to functions/brew_packages/README.md diff --git a/functions/brew_packages/config.toml b/functions/brew_packages/config.toml new file mode 100644 index 0000000..33abe0f --- /dev/null +++ b/functions/brew_packages/config.toml @@ -0,0 +1 @@ +install_function = "brew_install" diff --git a/functions/brew_packages/install.sh b/functions/brew_packages/install.sh new file mode 100755 index 0000000..c3102f2 --- /dev/null +++ b/functions/brew_packages/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +brew_install() { + # installs brew packages + for package in "$@" + do + brew install "$package" + done +} diff --git a/docs/entries/deb_package.md b/functions/deb_package/README.md similarity index 100% rename from docs/entries/deb_package.md rename to functions/deb_package/README.md diff --git a/functions/deb_package/config.toml b/functions/deb_package/config.toml new file mode 100644 index 0000000..0b15b3a --- /dev/null +++ b/functions/deb_package/config.toml @@ -0,0 +1,2 @@ +linux.install_function = "install_deb_package" +linux.sudo = true diff --git a/functions/deb_package/install.sh b/functions/deb_package/install.sh new file mode 100755 index 0000000..eea7fc7 --- /dev/null +++ b/functions/deb_package/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +install_deb_package() { + # installs a deb package + filepath="/tmp/file_to_install.deb" + wget -O "$filepath" "$@" + apt-get install -y "$filepath" + rm -f "$filepath" +} diff --git a/docs/entries/docker.md b/functions/docker/README.md similarity index 100% rename from docs/entries/docker.md rename to functions/docker/README.md diff --git a/functions/docker/config.toml b/functions/docker/config.toml new file mode 100644 index 0000000..37a1c83 --- /dev/null +++ b/functions/docker/config.toml @@ -0,0 +1,2 @@ +linux.install_function = "install_docker" +linux.sudo = true diff --git a/functions/docker/install.sh b/functions/docker/install.sh new file mode 100755 index 0000000..a12fd45 --- /dev/null +++ b/functions/docker/install.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +install_docker() { + # installs docker on linux + apt-get update + apt-get install -y --no-install-recommends ca-certificates curl gnupg lsb-release + mkdir -p /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update + apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io + + echo "Configuring docker to be run without calling sudo" + groupadd -f docker + gpasswd -a $ALFA_USER docker + echo "Please restart your computer to use docker without calling sudo" +} diff --git a/docs/entries/git_clone.md b/functions/git_clone/README.md similarity index 100% rename from docs/entries/git_clone.md rename to functions/git_clone/README.md diff --git a/functions/git_clone/config.toml b/functions/git_clone/config.toml new file mode 100644 index 0000000..4fd0417 --- /dev/null +++ b/functions/git_clone/config.toml @@ -0,0 +1 @@ +install_function = "git_clone_repo" diff --git a/functions/git_clone/install.sh b/functions/git_clone/install.sh new file mode 100755 index 0000000..7732a29 --- /dev/null +++ b/functions/git_clone/install.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +git_clone_repo() { + # clones any number of git repositories to a local folder while retaining the + # repo's project name. + # the first argument is the local directory and all arguments following + # are the urls + dir="$1" + shift + mkdir -p "$dir" + for repo in "$@" + do + git -C "$dir" clone "$repo" + done +} diff --git a/docs/entries/git_config.md b/functions/git_config/README.md similarity index 100% rename from docs/entries/git_config.md rename to functions/git_config/README.md diff --git a/functions/git_config/config.toml b/functions/git_config/config.toml new file mode 100644 index 0000000..a7df65e --- /dev/null +++ b/functions/git_config/config.toml @@ -0,0 +1 @@ +install_function = "create_git_config" diff --git a/functions/git_config/install.sh b/functions/git_config/install.sh new file mode 100755 index 0000000..2630355 --- /dev/null +++ b/functions/git_config/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +create_git_config() { + # sets up git config name and email + git config --global user.name "$1" + git config --global user.email "$2" + ssh-keygen -q -t rsa -C "$2" -N '' <<< ""$'\n'"y" 2>&1 >/dev/null +} diff --git a/docs/entries/install_ohmyzsh_plugins.md b/functions/install_ohmyzsh_plugins/README.md similarity index 100% rename from docs/entries/install_ohmyzsh_plugins.md rename to functions/install_ohmyzsh_plugins/README.md diff --git a/functions/install_ohmyzsh_plugins/config.toml b/functions/install_ohmyzsh_plugins/config.toml new file mode 100644 index 0000000..d80f1b1 --- /dev/null +++ b/functions/install_ohmyzsh_plugins/config.toml @@ -0,0 +1 @@ +install_function = "install_ohmyzsh_plugins" diff --git a/functions/install_ohmyzsh_plugins/install.sh b/functions/install_ohmyzsh_plugins/install.sh new file mode 100755 index 0000000..de43759 --- /dev/null +++ b/functions/install_ohmyzsh_plugins/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +install_ohmyzsh_plugins() { + # installs plugins for ohmyzsh + for repo in "$@" + do + git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins clone --depth=1 "$repo" + done +} diff --git a/docs/entries/jetbrains_toolbox.md b/functions/jetbrains_toolbox/README.md similarity index 100% rename from docs/entries/jetbrains_toolbox.md rename to functions/jetbrains_toolbox/README.md diff --git a/functions/jetbrains_toolbox/config.toml b/functions/jetbrains_toolbox/config.toml new file mode 100644 index 0000000..75ea1af --- /dev/null +++ b/functions/jetbrains_toolbox/config.toml @@ -0,0 +1 @@ +linux.install_function = "install_jetbrains_toolbox" diff --git a/functions/jetbrains_toolbox/install.sh b/functions/jetbrains_toolbox/install.sh new file mode 100755 index 0000000..46325de --- /dev/null +++ b/functions/jetbrains_toolbox/install.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +install_jetbrains_toolbox() { + # installs the jetbrains toolbox app (also should be run in non root mode) + filepath="/tmp/jetbrains-toolbox.tar.gz" + output_folder="/tmp/jetbrains-toolbox-tmp" + version="jetbrains-toolbox-1.25.12627" + mkdir -p "$output_folder" + wget -O "$filepath" "https://download.jetbrains.com/toolbox/${version}.tar.gz" + tar -xvf "$filepath" -C "$output_folder" + pushd "${output_folder}/${version}" + ./jetbrains-toolbox + popd + rm -rf "$filepath" "$output_folder" +} diff --git a/docs/entries/node_lts.md b/functions/node_lts/README.md similarity index 100% rename from docs/entries/node_lts.md rename to functions/node_lts/README.md diff --git a/functions/node_lts/config.toml b/functions/node_lts/config.toml new file mode 100644 index 0000000..4acbe7a --- /dev/null +++ b/functions/node_lts/config.toml @@ -0,0 +1 @@ +install_function = "install_node_lts" diff --git a/functions/node_lts/install.sh b/functions/node_lts/install.sh new file mode 100755 index 0000000..b61b2e6 --- /dev/null +++ b/functions/node_lts/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +install_node_lts() { + # installs the latest node lts version + NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + . $NVM_DIR/nvm.sh + nvm install --lts +} diff --git a/docs/entries/node_version.md b/functions/node_version/README.md similarity index 100% rename from docs/entries/node_version.md rename to functions/node_version/README.md diff --git a/functions/node_version/config.toml b/functions/node_version/config.toml new file mode 100644 index 0000000..9f53d90 --- /dev/null +++ b/functions/node_version/config.toml @@ -0,0 +1 @@ +install_function = "install_node" diff --git a/functions/node_version/install.sh b/functions/node_version/install.sh new file mode 100755 index 0000000..cb355e4 --- /dev/null +++ b/functions/node_version/install.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +install_node() { + # installs specfied version of node; otherwise, will install latest version + NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + . $NVM_DIR/nvm.sh + if [ -z "$1"]; + then + nvm install node + else + nvm install "$1" + fi +} diff --git a/docs/entries/nvm.md b/functions/nvm/README.md similarity index 100% rename from docs/entries/nvm.md rename to functions/nvm/README.md diff --git a/functions/nvm/config.toml b/functions/nvm/config.toml new file mode 100644 index 0000000..136fe6b --- /dev/null +++ b/functions/nvm/config.toml @@ -0,0 +1 @@ +install_function = "install_nvm" diff --git a/functions/nvm/install.sh b/functions/nvm/install.sh new file mode 100755 index 0000000..af00030 --- /dev/null +++ b/functions/nvm/install.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +install_nvm() { + # installs nvm + if [[ "$1" -eq 0 ]]; then + # nvm installer will not change your profile or rc file. + export PROFILE="/dev/null" + fi + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash +} diff --git a/docs/entries/ohmyzsh.md b/functions/ohmyzsh/README.md similarity index 100% rename from docs/entries/ohmyzsh.md rename to functions/ohmyzsh/README.md diff --git a/functions/ohmyzsh/config.toml b/functions/ohmyzsh/config.toml new file mode 100644 index 0000000..8a46ff9 --- /dev/null +++ b/functions/ohmyzsh/config.toml @@ -0,0 +1 @@ +install_function = "install_ohmyzsh" diff --git a/functions/ohmyzsh/install.sh b/functions/ohmyzsh/install.sh new file mode 100755 index 0000000..4b191db --- /dev/null +++ b/functions/ohmyzsh/install.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +install_ohmyzsh() { + # install ohmyzsh + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended +} diff --git a/docs/entries/p10k.md b/functions/p10k/README.md similarity index 100% rename from docs/entries/p10k.md rename to functions/p10k/README.md diff --git a/functions/p10k/config.toml b/functions/p10k/config.toml new file mode 100644 index 0000000..67876d8 --- /dev/null +++ b/functions/p10k/config.toml @@ -0,0 +1,2 @@ +macos.install_function = "prettify_terminal_macos" +linux.install_function = "prettify_terminal_linux" diff --git a/functions/p10k/install.sh b/functions/p10k/install.sh new file mode 100755 index 0000000..e2cc4db --- /dev/null +++ b/functions/p10k/install.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +prettify_terminal_macos() { + # clone Powerlevel10k repo and copy .p10k.zsh config file + echo "Cloning Powerlevel10k theme" + git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k + cp templates/.p10k.zsh ~/.p10k.zsh + + # edit the .zshrc + echo "Changing .zshrc file to Powerlevel10k theme" + cat ~/.zshrc | pbcopy && cat templates/p10k_init.zsh templates/zshrc_disable_flag.zsh > ~/.zshrc && pbpaste >> ~/.zshrc + echo "" >> ~/.zshrc + cat templates/p10k_config.zsh >> ~/.zshrc + + # replaces the default theme with the p10k theme + sed -i '.old' 's+ZSH_THEME="robbyrussell"+ZSH_THEME="powerlevel10k/powerlevel10k"+g' ~/.zshrc + rm ~/.zshrc.old +} + +prettify_terminal_linux() { + # clone Powerlevel10k repo and copy .p10k.zsh config file + echo "Cloning Powerlevel10k theme" + git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k + cp templates/.p10k.zsh ~/.p10k.zsh + + # edit the .zshrc + echo "Changing .zshrc file to Powerlevel10k theme" + sed -i '1 e cat templates/p10k_init.zsh && cat templates/zshrc_disable_flag.zsh' ~/.zshrc + echo "" >> ~/.zshrc + cat templates/p10k_config.zsh >> ~/.zshrc + + # replaces the default theme with the p10k theme + sed -i 's+ZSH_THEME="robbyrussell"+ZSH_THEME="powerlevel10k/powerlevel10k"+g' ~/.zshrc +} diff --git a/docs/entries/sdk_candidate.md b/functions/sdk_candidate/README.md similarity index 100% rename from docs/entries/sdk_candidate.md rename to functions/sdk_candidate/README.md diff --git a/functions/sdk_candidate/config.toml b/functions/sdk_candidate/config.toml new file mode 100644 index 0000000..964d678 --- /dev/null +++ b/functions/sdk_candidate/config.toml @@ -0,0 +1 @@ +install_function = "install_sdk_candidate" diff --git a/functions/sdk_candidate/install.sh b/functions/sdk_candidate/install.sh new file mode 100755 index 0000000..814fe48 --- /dev/null +++ b/functions/sdk_candidate/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +install_sdk_candidate() { + # installs an sdk candidate + set +eu + source "$HOME/.sdkman/bin/sdkman-init.sh" + sdk install "$@" + set -eu +} diff --git a/docs/entries/sdkman.md b/functions/sdkman/README.md similarity index 100% rename from docs/entries/sdkman.md rename to functions/sdkman/README.md diff --git a/functions/sdkman/config.toml b/functions/sdkman/config.toml new file mode 100644 index 0000000..b9ae7e6 --- /dev/null +++ b/functions/sdkman/config.toml @@ -0,0 +1 @@ +install_function = "install_sdkman" diff --git a/functions/sdkman/install.sh b/functions/sdkman/install.sh new file mode 100755 index 0000000..e6f6d82 --- /dev/null +++ b/functions/sdkman/install.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +install_sdkman() { + # installs sdkman + curl -s "https://get.sdkman.io?rcupdate=false" | bash + if [[ -f "$HOME/.bashrc" ]]; then + cat templates/sdkman.zsh >> ~/.bashrc + fi + + if [[ -f "$HOME/.zshrc" ]]; then + cat templates/sdkman.zsh >> ~/.zshrc + fi +} diff --git a/docs/entries/snap_package.md b/functions/snap_package/README.md similarity index 100% rename from docs/entries/snap_package.md rename to functions/snap_package/README.md diff --git a/functions/snap_package/config.toml b/functions/snap_package/config.toml new file mode 100644 index 0000000..2a6a86c --- /dev/null +++ b/functions/snap_package/config.toml @@ -0,0 +1,2 @@ +linux.install_function = "install_snap_package" +linux.sudo = true diff --git a/functions/snap_package/install.sh b/functions/snap_package/install.sh new file mode 100755 index 0000000..9b0773e --- /dev/null +++ b/functions/snap_package/install.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +install_snap_package() { + # installs a single snap package + snap install "$@" +} diff --git a/docs/entries/vimrc.md b/functions/vimrc/README.md similarity index 100% rename from docs/entries/vimrc.md rename to functions/vimrc/README.md diff --git a/functions/vimrc/config.toml b/functions/vimrc/config.toml new file mode 100644 index 0000000..83ead0b --- /dev/null +++ b/functions/vimrc/config.toml @@ -0,0 +1 @@ +install_function = "install_vimrc" diff --git a/functions/vimrc/install.sh b/functions/vimrc/install.sh new file mode 100755 index 0000000..27f2809 --- /dev/null +++ b/functions/vimrc/install.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +install_vimrc() { + # install ultimate vimrc + git clone --depth=1 https://github.com/nyoungstudios/vimrc.git ~/.vim_runtime + sh ~/.vim_runtime/install_awesome_vimrc.sh + git config --global core.editor "vim" +} diff --git a/docs/entries/vscode_extensions.md b/functions/vscode_extensions/README.md similarity index 100% rename from docs/entries/vscode_extensions.md rename to functions/vscode_extensions/README.md diff --git a/functions/vscode_extensions/config.toml b/functions/vscode_extensions/config.toml new file mode 100644 index 0000000..d34d222 --- /dev/null +++ b/functions/vscode_extensions/config.toml @@ -0,0 +1 @@ +install_function = "install_vscode_extensions" diff --git a/functions/vscode_extensions/install.sh b/functions/vscode_extensions/install.sh new file mode 100755 index 0000000..205183b --- /dev/null +++ b/functions/vscode_extensions/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +install_vscode_extensions() { + # installs vs code extensions (needs to be installed in non sudo mode) + for extension in "$@" + do + code --install-extension "$extension" + done +} diff --git a/docs/entries/zsh_successful_cmd_filter.md b/functions/zsh_successful_cmd_filter/README.md similarity index 100% rename from docs/entries/zsh_successful_cmd_filter.md rename to functions/zsh_successful_cmd_filter/README.md diff --git a/functions/zsh_successful_cmd_filter/config.toml b/functions/zsh_successful_cmd_filter/config.toml new file mode 100644 index 0000000..cd35535 --- /dev/null +++ b/functions/zsh_successful_cmd_filter/config.toml @@ -0,0 +1 @@ +install_function = "install_zsh_successful_cmd_filter" diff --git a/functions/zsh_successful_cmd_filter/install.sh b/functions/zsh_successful_cmd_filter/install.sh new file mode 100755 index 0000000..be5e841 --- /dev/null +++ b/functions/zsh_successful_cmd_filter/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +install_zsh_successful_cmd_filter() { + # appends zshaddhistory and precmd hooks + echo "" >> ~/.zshrc + cat templates/zshrc_successful_cmd_hist.zsh >> ~/.zshrc +} diff --git a/docs/entries/zshenv.md b/functions/zshenv/README.md similarity index 100% rename from docs/entries/zshenv.md rename to functions/zshenv/README.md diff --git a/functions/zshenv/config.toml b/functions/zshenv/config.toml new file mode 100644 index 0000000..39f84a4 --- /dev/null +++ b/functions/zshenv/config.toml @@ -0,0 +1 @@ +install_function = "append_to_zshenv" diff --git a/functions/zshenv/install.sh b/functions/zshenv/install.sh new file mode 100755 index 0000000..d2b7218 --- /dev/null +++ b/functions/zshenv/install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +append_to_zshenv() { + # appends a line to zshenv file + for line in "$@" + do + echo "$line" >> ~/.zshenv + done +} diff --git a/install.sh b/install.sh index 1dd1f8e..8652bc2 100755 --- a/install.sh +++ b/install.sh @@ -3,7 +3,7 @@ set -eu # checks if install.sh is run from the correct directory -if [[ ! -f "functions.sh" ]]; then +if [[ ! -f "Makefile" ]]; then echo "install.sh must be run from the root directory of the alfa repo" exit 1 fi @@ -30,6 +30,11 @@ if [[ ! -f "$alfaCommand" ]]; then version=`cat version.txt | grep -Ev '^((//|#)|[[:space:]]*$)' | head -n 1` fi + if [[ -f "functions.sh" && ( "$version" == "latest" || "$version" > "v1.1.0" ) ]]; then + echo "Get the lastest commit from origin/main or specify alfa version <= v1.1.0" + exit 1 + fi + if [[ -z "$version" || -z "$(echo $version | grep -E '^v[0-9]+.[0-9]+.[0-9]+$')" ]]; then version=`git tag -l --sort=-v:refname | grep -E '^v[0-9]+.[0-9]+.[0-9]+$' | head -n 1` fi diff --git a/tools/create_function.sh b/tools/create_function.sh new file mode 100755 index 0000000..b50999e --- /dev/null +++ b/tools/create_function.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +# Usage: ./tools/create_function.sh entry_name + +set -eu + +if [[ ! -f "install.sh" ]]; then + echo "create_function.sh must be run from the root directory of the alfa repo" + exit 1 +fi + +if [[ -z "$1" ]]; then + echo "must past the entry name as the first argument" + exit 1 +fi + +folder="functions/$1" + +if [[ -f "$folder/install.sh" || -f "$folder/config.toml" || -f "$folder/README.md" ]]; then + echo "an entry with the name \"$1\" already exists" + exit 1 +fi + +# create config.toml +mkdir -p "$folder" +echo "install_function = \"install_$1\"" > "$folder/config.toml" + +# create install.sh +SCRIPT=$(cat << EOF +#!/bin/bash + +install_$1() { + +} +EOF +) +echo "$SCRIPT" > "$folder/install.sh" +chmod +x "$folder/install.sh" + +# create README.md +README=$(cat << EOF +# $1 + +Configuration for a \`$1\` entry. + +## Description + +Installs $1. + +## Options + +Put what the arguments mean here + +## Example + +\`\`\`toml +[ $1 ] +options = [] +\`\`\` +EOF +) +echo "$README" > "$folder/README.md" + +echo "Created an entry with name $1 in $folder" diff --git a/tools/test.sh b/tools/test.sh index 4e6af24..c0ee3b8 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -1,6 +1,8 @@ #!/bin/bash -# Usage: ./tools/test.sh function_name fn_arg1 fn_arg2 fn_argN +# Usage: ./tools/test.sh entry_name function_name fn_arg1 fn_arg2 fn_argN # tests a single function -/bin/bash -euc "source functions.sh; $*" +name=$1 +shift +/bin/bash -euc "source functions/$name/install.sh; $*"