feat: install, logging improvements
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user