Skip to content

Commit

Permalink
feat: add new refactored install script
Browse files Browse the repository at this point in the history
Trying out a single install script instead of the separate scripts for
profiles and standalone in an attempt to simplify it and add some
additional functionality afterwards.
  • Loading branch information
laurigates committed May 19, 2024
1 parent 0e8ad98 commit 0c0d4ca
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env zsh

# Constants
BASE_CONFIG="base.yaml"
META_DIR="meta"
CONFIG_DIR="configs"
PROFILES_DIR="profiles"
DOTBOT_DIR="dotbot"
DOTBOT_BIN="bin/dotbot"

# Get the directory of the script
BASE_DIR="$(cd "$(dirname "${(%):-%N}")" && pwd)"
cd "${BASE_DIR}"

# Sync submodule URLs
git submodule sync --quiet --recursive

# Initialize and update submodules
git submodule update --init --recursive

# Fetch and pull the latest changes for submodules
git submodule foreach --recursive git fetch --quiet
git submodule foreach --recursive git pull --quiet origin main

# Function to combine base and specific config files and run Dotbot
run_dotbot() {
local config="$1"
echo -e "\nConfigure $config"
local base_config="${BASE_DIR}/${META_DIR}/${BASE_CONFIG}"
local config_file="${BASE_DIR}/${META_DIR}/${CONFIG_DIR}/${config}.yaml"
local combined_config

combined_config=$(mktemp)
cat "$base_config" "$config_file" > "$combined_config"
"${BASE_DIR}/${META_DIR}/${DOTBOT_DIR}/${DOTBOT_BIN}" -d "${BASE_DIR}" -c "$combined_config"
rm -f "$combined_config"
}

# Main logic
if [[ -f "${META_DIR}/${PROFILES_DIR}/$1" ]]; then
# Profile mode
PROFILE_FILE="${META_DIR}/${PROFILES_DIR}/$1"
shift
CONFIGS=("${(@f)$(<"$PROFILE_FILE")}")
for config in "${CONFIGS[@]}" "$@"; do
run_dotbot "$config"
done
else
# Standalone mode
for config in "$@"; do
run_dotbot "$config"
done
fi

# vim: ft=zsh

0 comments on commit 0c0d4ca

Please sign in to comment.