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

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

View File

@@ -7,7 +7,7 @@
# skip if CODESPACES is set
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
fi

View File

@@ -9,7 +9,7 @@ export PYENV_ROOT="$HOME/.pyenv"
if ! echo $PATH | grep -q "$PYENV_ROOT"; then
export PATH="$PYENV_ROOT/bin:$PATH"
fi
if ! command -v "pyenv" &>/dev/null; then
if ! command -v pyenv &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# https://github.com/pyenv/pyenv/wiki#suggested-build-environment
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
if ! command -v "python" &>/dev/null; then
if ! command -v python &>/dev/null; then
pyenv install 3.12.1
pyenv global 3.12.1
fi
@@ -38,7 +38,7 @@ fi
mkdir -p ~/.local/bin
unset local_bin_path
if ! command -v "pipx" &>/dev/null; then
if ! command -v pipx &>/dev/null; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo apt-get install -qq pipx
elif [[ "$OSTYPE" == "darwin"* ]]; then
@@ -48,7 +48,7 @@ fi
echo "pipx $(pipx --version)"
if ! command -v "poetry" &>/dev/null; then
if ! command -v poetry &>/dev/null; then
pipx install poetry
fi

View File

@@ -8,8 +8,8 @@
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"
nvm_version="0.39.7"
if ! command -v "nvm" &>/dev/null; then
nvm_version="0.40.3"
if ! command -v nvm &>/dev/null; then
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"
fi
@@ -25,9 +25,9 @@ echo "npm $(npm --version)"
npm_dependencies=(
"firebase-tools"
"neovim"
"typescript-language-server"
"typescript"
# "neovim"
# "typescript-language-server"
# "typescript"
)
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
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
fi
# skip if in CODESPACES
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
fi
# skip on mac
if [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${GREY}Running on macOS${NC}"
echo -e "${YELLOW}Running on macOS${NC}"
export SKIP_DOCKER_CONFIG=1
fi

View File

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

View File

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

View File

@@ -7,7 +7,7 @@
# skip if in CODESPACES
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
fi