feat: docs and script improvements
This commit is contained in:
@@ -1,30 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
# Script that installs system dependencies specified in a config,
|
||||
# and runs all post-install scripts contained in a subdirectory.
|
||||
#
|
||||
|
||||
TIME=${TIME:-$(date)}
|
||||
UUID=${UUID:-$(cat /proc/sys/kernel/random/uuid)}
|
||||
HOST=${HOST:-$(hostname)}
|
||||
uuid=${UUID:-$(cat /proc/sys/kernel/random/uuid)}
|
||||
dir=$(dirname "$0")
|
||||
utils="${dir}/_utils.sh"
|
||||
config="${dir}/install_config.json"
|
||||
install_dir="${dir}/install.d"
|
||||
log_dir="${dir}/logs"
|
||||
|
||||
NAME=$(basename "$0")
|
||||
REL_DIR=$(dirname "$0")
|
||||
ABS_DIR=$(readlink -f $REL_DIR/../) # Scripts are nested inside of /script
|
||||
|
||||
UTILS="${REL_DIR}/_utils.sh"
|
||||
CONFIG="${REL_DIR}/install_config.json"
|
||||
INSTALL_DIR="${REL_DIR}/install.d"
|
||||
|
||||
LOG_DIR="${ABS_DIR}/logs"
|
||||
mkdir -p "$LOG_DIR"
|
||||
LOG_TARGET=${LOG_TARGET:-"${LOG_DIR}/${UUID}.log"}
|
||||
# Create log directory if it doesn't exist
|
||||
# and the log path hasn't been overridden
|
||||
if [[ -z "$LOG_TARGET" ]]; then
|
||||
mkdir -p "$log_dir"
|
||||
fi
|
||||
log_target=${LOG_TARGET:-"${log_dir}/${uuid}.log"}
|
||||
|
||||
install() {
|
||||
echo "Running $NAME at $TIME"
|
||||
echo "Running as $USER on $HOST"
|
||||
echo "Running \"$(basename "$0")\" at \"$(date)\""
|
||||
echo "Running as \"$(whoami)\" on \"$(hostname)\""
|
||||
|
||||
# Prevent running as root
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
@@ -33,40 +31,40 @@ install() {
|
||||
fi
|
||||
|
||||
# Load installer dependencies
|
||||
source "$UTILS"
|
||||
source "$utils"
|
||||
update
|
||||
install jq
|
||||
for dep in $(jq -r ".apt_core_dependencies[]" "$CONFIG"); do
|
||||
for dep in $(jq -r ".apt_core_dependencies[]" "$config"); do
|
||||
install "$dep"
|
||||
done
|
||||
|
||||
# Add apt repositories
|
||||
for i in $(jq ".apt_repositories | keys | .[]" "$CONFIG"); do
|
||||
value=$(jq -r ".apt_repositories[$i]" "$CONFIG")
|
||||
for i in $(jq ".apt_repositories | keys | .[]" "$config"); do
|
||||
value=$(jq -r ".apt_repositories[$i]" "$config")
|
||||
add_repository "$value"
|
||||
done
|
||||
update
|
||||
|
||||
# Install apt dependencies
|
||||
for dep in $(jq -r ".apt_dependencies[]" "$CONFIG"); do
|
||||
for dep in $(jq -r ".apt_dependencies[]" "$config"); do
|
||||
install "$dep"
|
||||
done
|
||||
|
||||
# Install dotfiles on system and load them
|
||||
figlet -c "Stowing..."
|
||||
for i in $(jq ".stow_packages | keys | .[]" "$CONFIG"); do
|
||||
value=$(jq -r ".stow_packages[$i]" "$CONFIG")
|
||||
for i in $(jq ".stow_packages | keys | .[]" "$config"); do
|
||||
value=$(jq -r ".stow_packages[$i]" "$config")
|
||||
stow_package "$value"
|
||||
done
|
||||
source "$HOME/.profile"
|
||||
|
||||
# Run custom installer scripts
|
||||
figlet -c "Installing..."
|
||||
for script in $INSTALL_DIR/*.sh; do
|
||||
for script in $install_dir/*.sh; do
|
||||
figlet -c "$(basename $script)"
|
||||
source $script
|
||||
done
|
||||
}
|
||||
|
||||
echo "install: Logging to $LOG_TARGET"
|
||||
install 2>&1 | tee "$LOG_TARGET"
|
||||
echo "install: Logging to \"$log_target\""
|
||||
install 2>&1 | tee "$log_target"
|
||||
|
||||
13
script/run
13
script/run
@@ -1,13 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
tag=$(cat /proc/sys/kernel/random/uuid)
|
||||
docker build . \
|
||||
--build-arg UUID=$tag \
|
||||
--tag dotfiles:$tag \
|
||||
--target install
|
||||
|
||||
docker run \
|
||||
-v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \
|
||||
dotfiles:$tag \
|
||||
/bin/bash
|
||||
84
script/setup
84
script/setup
@@ -1,34 +1,82 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Summary: Script to checkout a compatible
|
||||
# repository and run `script/install`
|
||||
#
|
||||
# Script that checks out a compatible dotfiles repository
|
||||
# and runs the installer to set up a new installation.
|
||||
# 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 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}
|
||||
repository=${GITHUB_REPOSITORY:-dotfiles}
|
||||
branch=${GITHUB_BRANCH:-master}
|
||||
echo "Using repository $author/$repository at $branch"
|
||||
echo "============================================================"
|
||||
echo "Running \"$(basename "$0")\" at \"$(date)\""
|
||||
echo "Running as \"$(whoami)\" on \"$(hostname)\""
|
||||
echo "============================================================"
|
||||
|
||||
setup_dir=${DOTFILES_DIR:-$HOME/.dotfiles}
|
||||
|
||||
# Prevent overwriting existing installation
|
||||
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 if wget is not installed
|
||||
if ! command -v curl &> /dev/null; then
|
||||
echo "Failed: curl is not installed"
|
||||
exit 1
|
||||
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_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
|
||||
mv $tmp_dir/$repository-$branch/* $setup_dir
|
||||
rm -rf $tmp_dir
|
||||
|
||||
# Run installer
|
||||
$setup_dir/script/install
|
||||
# Run installer unless DOTFILES_SKIP_INSTALL is set
|
||||
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!"
|
||||
15
script/test
15
script/test
@@ -1,15 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE=${IMAGE:-"andrejusk/dotfiles"}
|
||||
tag=${TAG:-$(cat /proc/sys/kernel/random/uuid)}
|
||||
|
||||
docker build . \
|
||||
--build-arg UUID=$tag \
|
||||
--cache-from $IMAGE \
|
||||
--tag $IMAGE:$tag \
|
||||
--target test
|
||||
|
||||
docker run \
|
||||
-v "$(pwd)"/logs:/home/test-user/.dotfiles/logs \
|
||||
$IMAGE:$tag
|
||||
Reference in New Issue
Block a user