Update gitsync.sh

This commit is contained in:
2025-12-03 22:13:12 +01:00
parent f56ffbd936
commit 06d27a003d

View File

@@ -39,12 +39,13 @@ CMDS=(
rollback(){
echo -e "\n\033[31m✘ Deployment failed. Rolling back...\033[0m"
git reset --hard HEAD@{1} >> "$LOG_FILE" 2>&1
git reset --hard HEAD@{1} >> "$LOG_FILE" 2>&1 || true
php artisan up || true
exit 1
}
trap rollback ERR
# Draw a progress bar with centered text
draw_bar() {
local percent=$1
local width=$2
@@ -84,7 +85,8 @@ run_deployment() {
step_percent_start=$(( i * 100 / total_steps ))
step_percent_end=$(( (i+1) * 100 / total_steps ))
bash -c "$cmd" > >(tee -a "$LOG_FILE") 2> >(tee -a "$LOG_FILE" >&2) &
# Run the command: stdout/stderr go to log file only
bash -c "$cmd" > >(tee -a "$LOG_FILE" >/dev/null) 2> >(tee -a "$LOG_FILE" >/dev/null) &
pid=$!
percent=$step_percent_start
@@ -95,6 +97,7 @@ run_deployment() {
done
wait "$pid"
# Fill bar to end of step
echo -ne "\r$(draw_bar $step_percent_end $BAR_WIDTH "$step_name")$CLEAR_LINE"
done
@@ -102,13 +105,11 @@ run_deployment() {
final_text="Deployment Complete"
final_bar=$(draw_bar 100 $BAR_WIDTH "$final_text")
# Find start index of text inside brackets (exclude leading '[')
# Center green text inside the bar
text_len=${#final_text}
bar_only=${final_bar:1:BAR_WIDTH} # strip leading '['
start=$(( (BAR_WIDTH - text_len) / 2 ))
end=$(( start + text_len ))
# Reconstruct bar with green text in place
green_bar="${final_bar:0:start+1}${GREEN}${final_text}${RESET}${final_bar:end+1}"
echo -e "\r$green_bar$CLEAR_LINE"