feat: docs and script improvements
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -10,4 +10,4 @@ jobs:
|
|||||||
|
|
||||||
# Run the tests
|
# Run the tests
|
||||||
- name: 'Run tests'
|
- name: 'Run tests'
|
||||||
run: ./script/test
|
run: ./tools/test
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
# install artefacts
|
# install artefacts
|
||||||
**/tmp
|
tmp
|
||||||
|
temp
|
||||||
**/logs
|
**/logs
|
||||||
**/*.deb
|
**/*.deb
|
||||||
|
|
||||||
|
|||||||
29
README.md
29
README.md
@@ -2,28 +2,29 @@
|
|||||||
|
|
||||||
[](https://github.com/andrejusk/dotfiles/actions/workflows/ci.yml)
|
[](https://github.com/andrejusk/dotfiles/actions/workflows/ci.yml)
|
||||||
|
|
||||||
Collection of dotfiles and supporting install scripts
|
My collection of dotfiles and install scripts
|
||||||
to set up a reproducible development environment
|
to set up reproducible dev environments
|
||||||
|
|
||||||
## Installer
|
## Usage
|
||||||
|
|
||||||
Each push to master publishes the setup script, allowing the repo
|
A local repository can be installed by running:
|
||||||
to be installed by running:
|
|
||||||
|
|
||||||
# Dependencies if running on Debian
|
./script/install
|
||||||
sudo apt update && sudo apt install --no-install-recommends --yes \
|
|
||||||
software-properties-common \
|
### Automated install
|
||||||
wget
|
|
||||||
|
This repository can be installed without a local copy
|
||||||
|
by invoking the `setup` script directly via `curl`:
|
||||||
|
|
||||||
# Inspect source
|
# Inspect source
|
||||||
wget https://raw.githubusercontent.com/andrejusk/dotfiles/HEAD/script/setup -qO - | less
|
curl -s https://raw.githubusercontent.com/andrejusk/dotfiles/HEAD/script/setup | less
|
||||||
|
|
||||||
# One-liner install if running on Ubuntu
|
# Run
|
||||||
wget https://raw.githubusercontent.com/andrejusk/dotfiles/HEAD/script/setup -qO - | bash
|
curl -s https://raw.githubusercontent.com/andrejusk/dotfiles/HEAD/script/setup | bash
|
||||||
|
|
||||||
## The Stack
|
## Features
|
||||||
|
|
||||||
Tested and maintained against Debian bullseye
|
My dotfiles include configuration for the following tools:
|
||||||
|
|
||||||
### Shell
|
### Shell
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,28 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
#
|
# --------------------------------------------------------------------
|
||||||
# Script that installs system dependencies specified in a config,
|
# Script that installs system dependencies specified in a config,
|
||||||
# and runs all post-install scripts contained in a subdirectory.
|
# and runs all post-install scripts contained in a subdirectory.
|
||||||
#
|
#
|
||||||
|
|
||||||
TIME=${TIME:-$(date)}
|
uuid=${UUID:-$(cat /proc/sys/kernel/random/uuid)}
|
||||||
UUID=${UUID:-$(cat /proc/sys/kernel/random/uuid)}
|
dir=$(dirname "$0")
|
||||||
HOST=${HOST:-$(hostname)}
|
utils="${dir}/_utils.sh"
|
||||||
|
config="${dir}/install_config.json"
|
||||||
|
install_dir="${dir}/install.d"
|
||||||
|
log_dir="${dir}/logs"
|
||||||
|
|
||||||
NAME=$(basename "$0")
|
# Create log directory if it doesn't exist
|
||||||
REL_DIR=$(dirname "$0")
|
# and the log path hasn't been overridden
|
||||||
ABS_DIR=$(readlink -f $REL_DIR/../) # Scripts are nested inside of /script
|
if [[ -z "$LOG_TARGET" ]]; then
|
||||||
|
mkdir -p "$log_dir"
|
||||||
UTILS="${REL_DIR}/_utils.sh"
|
fi
|
||||||
CONFIG="${REL_DIR}/install_config.json"
|
log_target=${LOG_TARGET:-"${log_dir}/${uuid}.log"}
|
||||||
INSTALL_DIR="${REL_DIR}/install.d"
|
|
||||||
|
|
||||||
LOG_DIR="${ABS_DIR}/logs"
|
|
||||||
mkdir -p "$LOG_DIR"
|
|
||||||
LOG_TARGET=${LOG_TARGET:-"${LOG_DIR}/${UUID}.log"}
|
|
||||||
|
|
||||||
install() {
|
install() {
|
||||||
echo "Running $NAME at $TIME"
|
echo "Running \"$(basename "$0")\" at \"$(date)\""
|
||||||
echo "Running as $USER on $HOST"
|
echo "Running as \"$(whoami)\" on \"$(hostname)\""
|
||||||
|
|
||||||
# Prevent running as root
|
# Prevent running as root
|
||||||
if [[ $EUID -eq 0 ]]; then
|
if [[ $EUID -eq 0 ]]; then
|
||||||
@@ -33,40 +31,40 @@ install() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Load installer dependencies
|
# Load installer dependencies
|
||||||
source "$UTILS"
|
source "$utils"
|
||||||
update
|
update
|
||||||
install jq
|
install jq
|
||||||
for dep in $(jq -r ".apt_core_dependencies[]" "$CONFIG"); do
|
for dep in $(jq -r ".apt_core_dependencies[]" "$config"); do
|
||||||
install "$dep"
|
install "$dep"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Add apt repositories
|
# Add apt repositories
|
||||||
for i in $(jq ".apt_repositories | keys | .[]" "$CONFIG"); do
|
for i in $(jq ".apt_repositories | keys | .[]" "$config"); do
|
||||||
value=$(jq -r ".apt_repositories[$i]" "$CONFIG")
|
value=$(jq -r ".apt_repositories[$i]" "$config")
|
||||||
add_repository "$value"
|
add_repository "$value"
|
||||||
done
|
done
|
||||||
update
|
update
|
||||||
|
|
||||||
# Install apt dependencies
|
# Install apt dependencies
|
||||||
for dep in $(jq -r ".apt_dependencies[]" "$CONFIG"); do
|
for dep in $(jq -r ".apt_dependencies[]" "$config"); do
|
||||||
install "$dep"
|
install "$dep"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Install dotfiles on system and load them
|
# Install dotfiles on system and load them
|
||||||
figlet -c "Stowing..."
|
figlet -c "Stowing..."
|
||||||
for i in $(jq ".stow_packages | keys | .[]" "$CONFIG"); do
|
for i in $(jq ".stow_packages | keys | .[]" "$config"); do
|
||||||
value=$(jq -r ".stow_packages[$i]" "$CONFIG")
|
value=$(jq -r ".stow_packages[$i]" "$config")
|
||||||
stow_package "$value"
|
stow_package "$value"
|
||||||
done
|
done
|
||||||
source "$HOME/.profile"
|
source "$HOME/.profile"
|
||||||
|
|
||||||
# Run custom installer scripts
|
# Run custom installer scripts
|
||||||
figlet -c "Installing..."
|
figlet -c "Installing..."
|
||||||
for script in $INSTALL_DIR/*.sh; do
|
for script in $install_dir/*.sh; do
|
||||||
figlet -c "$(basename $script)"
|
figlet -c "$(basename $script)"
|
||||||
source $script
|
source $script
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "install: Logging to $LOG_TARGET"
|
echo "install: Logging to \"$log_target\""
|
||||||
install 2>&1 | tee "$LOG_TARGET"
|
install 2>&1 | tee "$log_target"
|
||||||
|
|||||||
84
script/setup
84
script/setup
@@ -1,34 +1,82 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# Summary: Script to checkout a compatible
|
||||||
|
# repository and run `script/install`
|
||||||
#
|
#
|
||||||
# Script that checks out a compatible dotfiles repository
|
# Optional arguments:
|
||||||
# and runs the installer to set up a new installation.
|
# GITHUB_AUTHOR: GitHub author of repository
|
||||||
|
# Defaults to "andrejusk"
|
||||||
|
# GITHUB_REPOSITORY: GitHub repository name
|
||||||
|
# Defaults to "dotfiles"
|
||||||
|
# GITHUB_BRANCH: GitHub branch name
|
||||||
|
# Defaults to "master"
|
||||||
|
# DOTFILES_DIR: Directory to install dotfiles to
|
||||||
|
# Defaults to "$HOME/.dotfiles"
|
||||||
|
# DOTFILES_SKIP_INSTALL: Skip running `script/install`
|
||||||
|
# Defaults to false
|
||||||
|
#
|
||||||
|
# Required binaries:
|
||||||
|
# curl
|
||||||
|
# tar
|
||||||
#
|
#
|
||||||
|
|
||||||
author=${GITHUB_AUTHOR:-andrejusk}
|
echo "============================================================"
|
||||||
repository=${GITHUB_REPOSITORY:-dotfiles}
|
echo "Running \"$(basename "$0")\" at \"$(date)\""
|
||||||
branch=${GITHUB_BRANCH:-master}
|
echo "Running as \"$(whoami)\" on \"$(hostname)\""
|
||||||
echo "Using repository $author/$repository at $branch"
|
echo "============================================================"
|
||||||
|
|
||||||
setup_dir=${DOTFILES_DIR:-$HOME/.dotfiles}
|
# Exit if wget is not installed
|
||||||
|
if ! command -v curl &> /dev/null; then
|
||||||
# Prevent overwriting existing installation
|
echo "Failed: curl is not installed"
|
||||||
mkdir -p $setup_dir
|
|
||||||
if [[ -z $(ls -A $setup_dir) ]]; then
|
|
||||||
echo "Setting up $setup_dir"
|
|
||||||
else
|
|
||||||
echo "Failed: Setup directory not empty $setup_dir"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download and untar repo
|
# Exit if tar is not installed
|
||||||
|
if ! command -v tar &> /dev/null; then
|
||||||
|
echo "Failed: tar is not installed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read and check if setup directory is empty
|
||||||
|
setup_dir=${DOTFILES_DIR:-$HOME/.dotfiles}
|
||||||
|
mkdir -p $setup_dir
|
||||||
|
if [[ -z $(ls -A $setup_dir) ]]; then
|
||||||
|
echo "Setting up in directory \"$setup_dir\""
|
||||||
|
else
|
||||||
|
echo "Failed: Setup directory not empty \"$setup_dir\""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read GitHub repository and branch from environment variables
|
||||||
|
author=${GITHUB_AUTHOR:-andrejusk}
|
||||||
|
repository=${GITHUB_REPOSITORY:-dotfiles}
|
||||||
|
branch=${GITHUB_BRANCH:-master}
|
||||||
|
|
||||||
|
# Check if repository and branch exists
|
||||||
|
if curl -s "https://api.github.com/repos/$author/$repository" | grep -q "Not Found"; then
|
||||||
|
echo "Failed: GitHub repository \"$author/$repository\" does not exist"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if curl -s "https://api.github.com/repos/$author/$repository/branches/$branch" | grep -q "not found"; then
|
||||||
|
echo "Failed: Branch \"$branch\" does not exist in GitHub repository \"$author/$repository\""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Using GitHub repository \"$author/$repository\" at \"$branch\""
|
||||||
|
|
||||||
|
# Download and extract repo
|
||||||
tmp_dir=$(mktemp -d)
|
tmp_dir=$(mktemp -d)
|
||||||
tmp_dest="$tmp_dir/dotfiles.tar.gz"
|
tmp_dest="$tmp_dir/dotfiles.tar.gz"
|
||||||
wget "https://github.com/$author/$repository/archive/$branch.tar.gz" -qO $tmp_dest
|
checkout_url="https://github.com/$author/$repository/archive/$branch.tar.gz"
|
||||||
|
curl -sL $checkout_url -o $tmp_dest
|
||||||
tar -C $tmp_dir -zxf $tmp_dest
|
tar -C $tmp_dir -zxf $tmp_dest
|
||||||
mv $tmp_dir/$repository-$branch/* $setup_dir
|
mv $tmp_dir/$repository-$branch/* $setup_dir
|
||||||
rm -rf $tmp_dir
|
rm -rf $tmp_dir
|
||||||
|
|
||||||
# Run installer
|
# Run installer unless DOTFILES_SKIP_INSTALL is set
|
||||||
$setup_dir/script/install
|
if [[ -z "$DOTFILES_SKIP_INSTALL" ]]; then
|
||||||
|
$setup_dir/script/install
|
||||||
|
else
|
||||||
|
echo "Skipping install"
|
||||||
|
fi
|
||||||
|
|||||||
44
script/setup-git
Executable file
44
script/setup-git
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# Script that sets up git in dotfiles directory.
|
||||||
|
#
|
||||||
|
# Optional arguments:
|
||||||
|
# GITHUB_AUTHOR: GitHub author of repository
|
||||||
|
# Defaults to "andrejusk"
|
||||||
|
# GITHUB_REPOSITORY: GitHub repository name
|
||||||
|
# Defaults to "dotfiles"
|
||||||
|
# GITHUB_BRANCH: GitHub branch name
|
||||||
|
# Defaults to "master"
|
||||||
|
# DOTFILES_DIR: Directory where dotfiles are installed
|
||||||
|
# Defaults to parent directory of this script
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "============================================================"
|
||||||
|
echo "Running \"$(basename "$0")\" at \"$(date)\""
|
||||||
|
echo "Running as \"$(whoami)\" on \"$(hostname)\""
|
||||||
|
echo "============================================================"
|
||||||
|
|
||||||
|
dir=${DOTFILES_DIR:-$(dirname "$0")}
|
||||||
|
dir=$(realpath "$dir/..")
|
||||||
|
|
||||||
|
author=${GITHUB_AUTHOR:-andrejusk}
|
||||||
|
repository=${GITHUB_REPOSITORY:-dotfiles}
|
||||||
|
branch=${GITHUB_BRANCH:-master}
|
||||||
|
|
||||||
|
echo "Using GitHub repository \"$author/$repository\" at \"$branch\""
|
||||||
|
echo "Using dotfiles directory \"$dir\""
|
||||||
|
echo "<<< git logs"
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
git -C $dir init
|
||||||
|
git -C $dir remote add origin "git@github.com:$author/$repository.git"
|
||||||
|
git -C $dir fetch origin $branch
|
||||||
|
git -C $dir reset --hard FETCH_HEAD
|
||||||
|
git -C $dir branch --set-upstream-to=origin/$branch $branch
|
||||||
|
git -C $dir pull --rebase
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
echo ">>> git logs"
|
||||||
|
echo "Done!"
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# This script is used to run the install script in a docker container.
|
||||||
|
#
|
||||||
|
|
||||||
tag=$(cat /proc/sys/kernel/random/uuid)
|
tag=$(cat /proc/sys/kernel/random/uuid)
|
||||||
docker build . \
|
docker build . \
|
||||||
--build-arg UUID=$tag \
|
--build-arg UUID=$tag \
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# This script is used to run the install script in a docker container
|
||||||
|
# and then run the test script.
|
||||||
|
#
|
||||||
|
|
||||||
IMAGE=${IMAGE:-"andrejusk/dotfiles"}
|
IMAGE=${IMAGE:-"andrejusk/dotfiles"}
|
||||||
tag=${TAG:-$(cat /proc/sys/kernel/random/uuid)}
|
tag=${TAG:-$(cat /proc/sys/kernel/random/uuid)}
|
||||||
|
|
||||||
Reference in New Issue
Block a user