diff --git a/ conf.xcworkspace/contents.xcworkspacedata b/ conf.xcworkspace/contents.xcworkspacedata index 0c0b8509..8a9d944f 100644 --- a/ conf.xcworkspace/contents.xcworkspacedata +++ b/ conf.xcworkspace/contents.xcworkspacedata @@ -4,19 +4,9 @@ - - - - - - - - + + diff --git a/install b/install deleted file mode 100755 index db5f75df..00000000 --- a/install +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/zsh -e -setopt pipefail - -cd "$(dirname "$0")" - -# We export PATH in case the variable is not exported yet -export PATH - -# We add our own bins to the path, but agree to use the system or user-defined -# ones if they are already there -path+="$(pwd)/.cache/bin" - -# Create cache dir -mkdir -p .cache -chmod 700 .cache - -# Install ccrypt if needed -command -v ccdecrypt >/dev/null 2>&1 || { - echo "*** Downloading and compiling ccrypt in the .cache folder..." - pushd .cache - readonly CCRYPT_SHASUM="6d20a4db9ef7caeea6ce432f3cffadf10172e420" - readonly CCRYPT_VERSION="1.11" - readonly CCRYPT_BASENAME="ccrypt-$CCRYPT_VERSION" - readonly CCRYPT_TAR_NAME="$CCRYPT_BASENAME.tar.gz" - readonly CCRYPT_URL="http://ccrypt.sourceforge.net/download/$CCRYPT_VERSION/$CCRYPT_TAR_NAME" - test -e "$CCRYPT_TAR_NAME" || curl "$CCRYPT_URL" >"$CCRYPT_TAR_NAME" - test "$(shasum "$CCRYPT_TAR_NAME" | cut -d' ' -f1)" = "$CCRYPT_SHASUM" || { - echo "***** ERROR: ccrypt sha does not match expected sha. Bailing out." - exit 1 - } - tar xf "$CCRYPT_TAR_NAME" - pushd "$CCRYPT_BASENAME" - ./configure --prefix "$(pwd)/.." - make install - popd - rm -fr "$CCRYPT_BASENAME" - popd -} diff --git a/install b/install new file mode 120000 index 00000000..b2e90174 --- /dev/null +++ b/install @@ -0,0 +1 @@ +src/main.zsh \ No newline at end of file diff --git a/run-ansible b/run-ansible deleted file mode 100644 index b1180bb7..00000000 --- a/run-ansible +++ /dev/null @@ -1,196 +0,0 @@ -#!/bin/bash -# vim: ts=3 sw=3 noet -# Adapted from https://github.com/wincent/wincent (when it was using Ansible) - -set -euo pipefail -shopt -s nullglob -cd "$(dirname "$0")" - - -### Paths ### - -readonly ANSIBLE_SETUP_PATH="ansible-setup" - -readonly HOMEBREW_TARGET_DIR="$(pwd)/.cache/homebrew" -readonly HOMEBREW_BIN="${HOMEBREW_TARGET_DIR}/bin/brew" -readonly PYTHON_BIN="${HOMEBREW_TARGET_DIR}/bin/python3" -readonly ANSIBLE_BIN="${HOMEBREW_TARGET_DIR}/bin/ansible" -readonly INSTALL_BREW_SCRIPT="$ANSIBLE_SETUP_PATH/roles/bin/files/bash/install-brew.sh" - -# Relative to ANSIBLE_SETUP_PATH -readonly VAULT_ID_PATH="../.cache/.vault-id" - - -### Hardware Constants ### - -#readonly ARCH="$(uname -m)" -readonly HOST_OS="$(uname -s)" - - -### PATH ### - -# We set our local Homebrew’s bin path first -PATH="${HOMEBREW_TARGET_DIR}/bin:${PATH}" - - - -usage() { - echo "usage: run-ansible [options] [roles...]" - echo - echo "Supported options:" - echo " -h/--help show the help and exit" - echo " -v/--verbose (repeat up to four times for more verbosity)" - echo - echo "Choosing the Ansible module to run:" - echo " -m/--module ansible_module which Ansible module to run (default \"playbook\")" - echo " This is useful to encrypt a string for instance:" - echo " ./run-ansible -m vault encrypt_string \"secret\"" - echo - echo "Other options (passed through to Ansible):" - echo " --check" - echo " --step" - echo " --start-at-task='role | task'" - echo - echo "The script will:" - echo " 1. Install a local Homebrew instance (in .cache)" - echo " 2. Install Python3 and Ansible in this Homebrew instance" - echo " 3. Hand off to Ansible to complete the actual installation of dotfiles etc." - echo - echo "Supported roles:" - pushd "$ANSIBLE_SETUP_PATH/roles" >/dev/null 2>&1 - for role in *; do - echo " $role: $(cat "$role/description" 2>/dev/null || echo "")" - done - popd >/dev/null 2>&1 -} - - -ROLES= -VERBOSE=0 -EXTRA_ARGS=() -ANSIBLE_MODULE="playbook" -while [ $# -gt 0 ]; do - case "$1" in - --verbose | -v) VERBOSE=$((VERBOSE + 1));; - -vv) VERBOSE=$((VERBOSE + 2));; - -vvv) VERBOSE=$((VERBOSE + 3));; - -vvvv) VERBOSE=$((VERBOSE + 4));; - --help | -h | help) - usage - exit 0 - ;; - --module | -m) - shift - ANSIBLE_MODULE="$1" - if [ -z "$ANSIBLE_MODULE" ]; then - echo "Got invalid empty Ansible module" >/dev/stderr - echo >/dev/stderr - usage >/dev/stderr - exit 1 - fi - ;; - "") - echo "Got invalid empty arg" >/dev/stderr - echo >/dev/stderr - usage >/dev/stderr - exit 1 - ;; - *) - if [ -d "$ANSIBLE_SETUP_PATH/roles/$1" ]; then - if [ -z "$ROLES" ]; then - ROLES="--tags $1" - else - ROLES="$ROLES,$1" - fi - else - EXTRA_ARGS+=("$1") - fi - ;; - esac - shift -done - -DEV_NULL=/dev/null -if [[ "$VERBOSE" != 0 ]]; then - DEV_NULL=/dev/stdout - if [ "$VERBOSE" -ge 4 ]; then - echo "Enabling extremely verbose output" - set -x - fi -else - trap 'echo "Exiting: run with -v/--verbose for more info"' EXIT - - # VERBOSE must be unset because of how we use it later to create the verbose - # options for Ansible… - unset VERBOSE -fi - - -# Checking dependencies are installed -if [ ! -x "$INSTALL_BREW_SCRIPT" ]; then - echo "The install-brew script is mandatory! Expected to find it in \"$INSTALL_BREW_SCRIPT\"" >/dev/stderr - exit 1 -fi - -case "$HOST_OS" in - Darwin) - xcode-select -p >/dev/null 2>&1 || { echo "The Xcode Command Line Tools (or Xcode) is required for this script to work. Run 'xcode-select --install' to get the CLT." >/dev/stderr; exit 1; } - ;; - Linux) - # For Debian; see https://docs.brew.sh/Homebrew-on-Linux#requirements - readonly DEPS="gcc make curl file git" - for dep in $DEPS; do - command -v "$dep" >/dev/null 2>&1 || { echo "The following binaries are required dependencies for Homebrew, and thus for this script: $DEPS. Please them with 'apt-get install -y --no-install-recommends build-essential curl file git'"; exit 1; } - done - ;; - *) - echo "Unknown host OS: $HOST_OS" >/dev/stderr - exit 1 - ;; -esac - -# Install a local Homebrew instance -"$INSTALL_BREW_SCRIPT" "$HOMEBREW_TARGET_DIR" -HOMEBREW_NO_ANALYTICS=1 HOMEBREW_NO_AUTO_UPDATE=0 HOMEBREW_AUTO_UPDATE_SECS=259200 "${HOMEBREW_BIN}" upgrade - -test -x "$PYTHON_BIN" || HOMEBREW_NO_ANALYTICS=1 HOMEBREW_NO_AUTO_UPDATE=1 "${HOMEBREW_BIN}" install python3 -test -x "$ANSIBLE_BIN" || HOMEBREW_NO_ANALYTICS=1 HOMEBREW_NO_AUTO_UPDATE=1 "${HOMEBREW_BIN}" install ansible - -# Pre-run the inventory script to update the ansible group cache and avoid -# having a user input required during the Ansible run (Ansible catches the -# output of the script). -pushd "$ANSIBLE_SETUP_PATH" >/dev/null 2>&1 -"$PYTHON_BIN" "./inventory.py" --update-cache-only >"$DEV_NULL" - -# Ask for the vault id if needed. -if [ ! -f "$VAULT_ID_PATH" ]; then - if [ -e "$VAULT_ID_PATH" ]; then - echo "Something exists at path \"$VAULT_ID_PATH\" but it’s not a regular file. Aborting Ansible run." >/dev/stderr - exit 1 - fi - read -rsp "Please input the Ansible Vault password: " vault_id - echo - echo -n "$vault_id" >"$VAULT_ID_PATH" -fi -popd >/dev/null 2>&1 - -readonly ANSIBLE_VERBOSE_OPTION="${VERBOSE+-$(printf 'v%.0s' $(seq $VERBOSE))}" - -if [ "$ANSIBLE_MODULE" = "playbook" ]; then - case "$HOST_OS" in - Darwin) EXTRA_ARGS+=("playbooks/darwin.yml");; - Linux) EXTRA_ARGS+=("playbooks/linux.yml");; - *) echo "Unknown host OS: $HOST_OS" >/dev/stderr; exit 1;; - esac -fi - -pushd "$ANSIBLE_SETUP_PATH" >/dev/null 2>&1 -# Note: If we need sudo in a playbook: pass "--ask-become-pass" to -# ansible-playbook. (The option can be added to EXTRA_ARGS.) -# shellcheck disable=SC2086 -"$ANSIBLE_BIN-$ANSIBLE_MODULE" --vault-id="$VAULT_ID_PATH" $ANSIBLE_VERBOSE_OPTION ${ROLES} "${EXTRA_ARGS[@]}" -# To list the facts on the machine -#ansible -m setup localhost -popd >/dev/null 2>&1 - -trap - EXIT diff --git a/src/lib/ccrypt.zsh b/src/lib/ccrypt.zsh new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/logger.zsh b/src/lib/logger.zsh new file mode 100644 index 00000000..8298e5d7 --- /dev/null +++ b/src/lib/logger.zsh @@ -0,0 +1,3 @@ +func hello() { + echo hello +} diff --git a/src/main.zsh b/src/main.zsh new file mode 100755 index 00000000..e4e071ae --- /dev/null +++ b/src/main.zsh @@ -0,0 +1,60 @@ +#!/bin/zsh -euopipefail + + +################################ +# Paths Setup and Verification # +################################ + +test "$(basename "$0")" = "install" || { + echo "This script must be run from the install alias." >/dev/stderr + exit 1 +} +cd "$(dirname "$0")" + +# We export PATH in case the variable is not exported yet +export PATH + +# We add our own bins to the path, but agree to use the system or user-defined +# ones if they are already there +path+="$(pwd)/.cache/bin" + +# Let’s define the different paths we will need +readonly CACHE_FOLDER="$(pwd)/.cache" +readonly SRC_FOLDER="$(pwd)/src" +readonly LIB_FOLDER="$SRC_FOLDER/lib" +readonly COMPONENTS_FOLDER="$SRC_FOLDER/components" + +# Create the cache folder if needed +mkdir -p "$CACHE_FOLDER" && chmod 700 "$CACHE_FOLDER" + + +############### +# Import libs # +############### + +source "$LIB_FOLDER/logger.zsh" +source "$LIB_FOLDER/ccrypt.zsh" + + +# Install ccrypt if needed +command -v ccdecrypt >/dev/null 2>&1 || { + echo "*** Downloading and compiling ccrypt in the .cache folder..." + pushd .cache + readonly CCRYPT_SHASUM="6d20a4db9ef7caeea6ce432f3cffadf10172e420" + readonly CCRYPT_VERSION="1.11" + readonly CCRYPT_BASENAME="ccrypt-$CCRYPT_VERSION" + readonly CCRYPT_TAR_NAME="$CCRYPT_BASENAME.tar.gz" + readonly CCRYPT_URL="http://ccrypt.sourceforge.net/download/$CCRYPT_VERSION/$CCRYPT_TAR_NAME" + test -e "$CCRYPT_TAR_NAME" || curl "$CCRYPT_URL" >"$CCRYPT_TAR_NAME" + test "$(shasum "$CCRYPT_TAR_NAME" | cut -d' ' -f1)" = "$CCRYPT_SHASUM" || { + echo "***** ERROR: ccrypt sha does not match expected sha. Bailing out." + exit 1 + } + tar xf "$CCRYPT_TAR_NAME" + pushd "$CCRYPT_BASENAME" + ./configure --prefix "$(pwd)/.." + make install + popd + rm -fr "$CCRYPT_BASENAME" + popd +} diff --git a/src/vars.zsh b/src/vars.zsh new file mode 100644 index 00000000..9ee0d614 --- /dev/null +++ b/src/vars.zsh @@ -0,0 +1 @@ +#!/bin/zsh -e