feat: install, logging improvements

This commit is contained in:
2025-06-02 22:24:32 +01:00
parent c942a8b9ff
commit 9b23394145
11 changed files with 35 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
alias bench='ZSH_BENCH=1 exec zsh' alias bench='ZSH_BENCH=1 exec zsh'
alias dots='$DOTFILES/install' alias dots='cd $DOTFILES'
alias j='z' alias j='z'
alias reload='source ~/.zshrc' alias reload='source ~/.zshrc'
alias zen='curl -s https://api.github.com/zen && echo' alias zen='curl -s https://api.github.com/zen && echo'

View File

@@ -34,21 +34,6 @@ _dots_load_nvm() {
} }
_dots_load_nvm _dots_load_nvm
_dots_install_node() {
node_alias="$NVM_DIR/alias/lts/jod"
if [ -f "$node_alias" ]; then
VERSION=`cat $node_alias`
if [ -x `command -v nvm` ]; then
nvm install "$VERSION" > /dev/null 2>&1 & disown
fi
node_bin_path="$NVM_DIR/versions/node/$VERSION/bin"
if [[ ":$PATH:" != *":$node_bin_path:"* ]]; then
export PATH="$node_bin_path:$PATH"
fi
fi
}
_dots_install_node
# Initialise and load pyenv # Initialise and load pyenv
# ----------------------------------------------------------------- # -----------------------------------------------------------------
export PYENV_ROOT=${PYENV_ROOT:-"$HOME/.pyenv"} export PYENV_ROOT=${PYENV_ROOT:-"$HOME/.pyenv"}

View File

@@ -6,6 +6,8 @@ set -eo pipefail
# #
if [[ -t 1 && -n "$TERM" && "$TERM" != "dumb" ]]; then if [[ -t 1 && -n "$TERM" && "$TERM" != "dumb" ]]; then
CYAN="\033[0;36m"
CYAN_BOLD="\033[1;36m"
RED="\033[1;31m" RED="\033[1;31m"
GREEN="\033[1;32m" GREEN="\033[1;32m"
YELLOW="\033[1;33m" YELLOW="\033[1;33m"
@@ -19,7 +21,7 @@ else
NC="" NC=""
fi fi
printf "\n\t${GREEN} <<< dots >>> ${NC}\n" printf "\n\t${CYAN} <<< ${CYAN_BOLD}dots${CYAN} >>> ${NC}\n"
printf "\t${GREY}==============${NC}\n\n" printf "\t${GREY}==============${NC}\n\n"
# Prevent running as root # Prevent running as root
@@ -30,7 +32,7 @@ fi
# Ensure sudo credentials are cached # Ensure sudo credentials are cached
if [[ -z "$SKIP_SUDO_CHECK" ]]; then if [[ -z "$SKIP_SUDO_CHECK" ]]; then
echo -e "${GREY}Checking sudo credentials...${NC}" echo -e "${YELLOW}Checking sudo credentials...${NC}"
sudo -v sudo -v
fi fi
@@ -69,12 +71,12 @@ targets=($@)
# Run install scripts # Run install scripts
run() { run() {
echo -e "${GREY}Running \"$(basename "$0")\" at \"$(date)\"${NC}" echo -e "Running \"$(basename "$0")\" at \"$(date)\""
echo -e "${GREY}Running as \"$(whoami)\" on \"$(hostname)\"${NC}" echo -e "Running as \"$(whoami)\" on \"$(hostname)\""
if [[ -n "$targets" ]]; then if [[ -n "$targets" ]]; then
echo -e "${GREY}Running ${#targets[@]} install target(s): ${targets[@]}${NC}" echo -e "Running ${YELLOW}${#targets[@]}${NC} install target(s): ${YELLOW}${targets[@]}${NC}"
else else
echo -e "${GREY}Running all install targets${NC}" echo -e "Running all install targets"
fi fi
for script in $install_dir/*.sh; do for script in $install_dir/*.sh; do
@@ -88,7 +90,7 @@ run() {
local script_name=$(basename $script) local script_name=$(basename $script)
printf "\n\n${GREY}<<< $script_name:${NC}\n" printf "\n\n${CYAN}<<< ${CYAN_BOLD}$script_name:${NC}\n"
local start_time=$(date +%s.%N) local start_time=$(date +%s.%N)
source $script source $script
local end_time=$(date +%s.%N) local end_time=$(date +%s.%N)
@@ -96,19 +98,23 @@ run() {
local execution_ms=$(echo "$execution_time * 1000" | bc | awk '{printf "%.0f", $0}') local execution_ms=$(echo "$execution_time * 1000" | bc | awk '{printf "%.0f", $0}')
local execution_ms_formatted=$(printf "%'.0f" "$execution_ms") local execution_ms_formatted=$(printf "%'.0f" "$execution_ms")
local time_color="$GREY" local time_color="$GREY"
if (( execution_ms > 1000 )); then if (( execution_ms < 2000 )); then
time_color="$GREEN"
elif (( execution_ms < 5000 )); then
time_color="$YELLOW"
else
time_color="$RED" time_color="$RED"
fi fi
printf "\n${GREY}>>> $script_name, " printf "\n${CYAN}>>> ${CYAN_BOLD}${script_name}, ${NC}"
printf "completed in ${time_color}${execution_ms_formatted}ms${NC}\n" printf "completed in ${time_color}${execution_ms_formatted}ms${NC}\n"
done done
} }
echo -e "\n${GREY}install: Logging to \"$log_abs_target\"${NC}" echo -e "\ninstall: Logging to \"$log_abs_target\""
start_time=$(date +%s.%N) start_time=$(date +%s.%N)
run 2>&1 | tee "$log_abs_target" run 2>&1 | tee "$log_abs_target"
end_time=$(date +%s.%N) end_time=$(date +%s.%N)
total_time_raw=$(echo "$end_time - $start_time" | bc) total_time_raw=$(echo "$end_time - $start_time" | bc)
total_time=$(echo "$total_time_raw" | awk '{printf "%.3g", $1}') total_time=$(echo "$total_time_raw" | awk '{printf "%.3g", $1}')
echo -e "\n${GREY}Thank you!${NC}" echo -e "\nThank you!"
echo -e "${GREY}Total time: ${GREEN}${total_time}s${NC}\n" echo -e "Total time: ${GREEN}${total_time}s${NC}\n"

View File

@@ -7,7 +7,7 @@
# skip if CODESPACES is set # skip if CODESPACES is set
if [ -n "$CODESPACES" ]; then if [ -n "$CODESPACES" ]; then
echo -e "${GREY}Running in a GitHub Codespace${NC}" echo -e "${YELLOW}Running in a GitHub Codespace${NC}"
export SKIP_SSH_CONFIG=1 export SKIP_SSH_CONFIG=1
fi fi

View File

@@ -9,7 +9,7 @@ export PYENV_ROOT="$HOME/.pyenv"
if ! echo $PATH | grep -q "$PYENV_ROOT"; then if ! echo $PATH | grep -q "$PYENV_ROOT"; then
export PATH="$PYENV_ROOT/bin:$PATH" export PATH="$PYENV_ROOT/bin:$PATH"
fi fi
if ! command -v "pyenv" &>/dev/null; then if ! command -v pyenv &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment # https://github.com/pyenv/pyenv/wiki#suggested-build-environment
sudo apt-get install -qq build-essential libssl-dev zlib1g-dev \ sudo apt-get install -qq build-essential libssl-dev zlib1g-dev \

View File

@@ -7,7 +7,7 @@
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
if ! command -v "python" &>/dev/null; then if ! command -v python &>/dev/null; then
pyenv install 3.12.1 pyenv install 3.12.1
pyenv global 3.12.1 pyenv global 3.12.1
fi fi
@@ -38,7 +38,7 @@ fi
mkdir -p ~/.local/bin mkdir -p ~/.local/bin
unset local_bin_path unset local_bin_path
if ! command -v "pipx" &>/dev/null; then if ! command -v pipx &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq pipx sudo apt-get install -qq pipx
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then
@@ -48,7 +48,7 @@ fi
echo "pipx $(pipx --version)" echo "pipx $(pipx --version)"
if ! command -v "poetry" &>/dev/null; then if ! command -v poetry &>/dev/null; then
pipx install poetry pipx install poetry
fi fi

View File

@@ -8,8 +8,8 @@
NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
nvm_version="0.39.7" nvm_version="0.40.3"
if ! command -v "nvm" &>/dev/null; then if ! command -v nvm &>/dev/null; then
bash -c "$(curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v${nvm_version}/install.sh)" bash -c "$(curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v${nvm_version}/install.sh)"
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
fi fi
@@ -25,9 +25,9 @@ echo "npm $(npm --version)"
npm_dependencies=( npm_dependencies=(
"firebase-tools" "firebase-tools"
"neovim" # "neovim"
"typescript-language-server" # "typescript-language-server"
"typescript" # "typescript"
) )
npm_dependencies=($(comm -13 <(printf "%s\n" "${npm_dependencies[@]}" | sort) <(npm list -g --depth=0 --parseable | awk -F'/' '{print $NF}' | sort))) npm_dependencies=($(comm -13 <(printf "%s\n" "${npm_dependencies[@]}" | sort) <(npm list -g --depth=0 --parseable | awk -F'/' '{print $NF}' | sort)))

View File

@@ -8,19 +8,19 @@
# skip if in WSL # skip if in WSL
if [[ -n "$WSL_DISTRO_NAME" ]]; then if [[ -n "$WSL_DISTRO_NAME" ]]; then
echo -e "${GREY}Running in WSL${NC}" echo -e "${YELLOW}Running in WSL${NC}"
export SKIP_DOCKER_CONFIG=1 export SKIP_DOCKER_CONFIG=1
fi fi
# skip if in CODESPACES # skip if in CODESPACES
if [[ -n "$CODESPACES" ]]; then if [[ -n "$CODESPACES" ]]; then
echo -e "${GREY}Running in GitHub Codespaces${NC}" echo -e "${YELLOW}Running in GitHub Codespaces${NC}"
export SKIP_DOCKER_CONFIG=1 export SKIP_DOCKER_CONFIG=1
fi fi
# skip on mac # skip on mac
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${GREY}Running on macOS${NC}" echo -e "${YELLOW}Running on macOS${NC}"
export SKIP_DOCKER_CONFIG=1 export SKIP_DOCKER_CONFIG=1
fi fi

View File

@@ -5,7 +5,7 @@
# Install terraform. # Install terraform.
# #
if ! command -v "terraform" &>/dev/null; then if ! command -v terraform &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
terraform_keyring_path="/usr/share/keyrings/hashicorp-archive-keyring.gpg" terraform_keyring_path="/usr/share/keyrings/hashicorp-archive-keyring.gpg"
if [[ ! -f "$terraform_keyring_path" ]]; then if [[ ! -f "$terraform_keyring_path" ]]; then

View File

@@ -5,7 +5,7 @@
# Install neofetch. # Install neofetch.
# #
if ! command -v "neofetch" &>/dev/null; then if ! command -v neofetch &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq neofetch &>/dev/null sudo apt-get install -qq neofetch &>/dev/null
elif [[ "$OSTYPE" == "darwin"* ]]; then elif [[ "$OSTYPE" == "darwin"* ]]; then

View File

@@ -7,7 +7,7 @@
# skip if in CODESPACES # skip if in CODESPACES
if [[ -n "$CODESPACES" ]]; then if [[ -n "$CODESPACES" ]]; then
echo -e "${GREY}Running in GitHub Codespaces${NC}" echo -e "${YELLOW}Running in GitHub Codespaces${NC}"
export SKIP_CMATRIX_CONFIG=1 export SKIP_CMATRIX_CONFIG=1
fi fi