#!/bin/bash ############# # Constants # ############# RETRIES_MAIN=3 WIKI_ADDRESS='http://wiki.zenwalk.org/index.php?title=Compiz_Fusion' COMPIZ_START_CMD="fusion-icon" COMPIZ_CHECK="compiz-check" DIALOG_TEXT="You are about to start Compiz maybe even for the first time.\n\ Please ensure that you have X set up properly. If you are unsure visit \ the Zenwalk Wiki." DIALOG_CMD='eval eval Xdialog --no-tags --default-item abort --wrap \ --left --icon compiz --title "\"Compiz Launcher\"" --menubox "\"$DIALOG_TEXT\"" 17 70 0 $choices 2>&1' # Dialog Choices CHOICE_COUNT=4 CHOICE_TAG[0]="start" CHOICE_TEXT[0]="Start Compiz" CHOICE_ACTION[0]="$COMPIZ_START_CMD 2>/dev/null 1>/dev/null &" CHOICE_TAG[1]="abort" CHOICE_TEXT[1]="Do not start Compiz" CHOICE_ACTION[1]="echo -n" CHOICE_TAG[2]="wiki" CHOICE_TEXT[2]="Help me! Display the Zenwalk Wiki entry." CHOICE_ACTION[2]="exo-open $WIKI_ADDRESS & displayMainDialog" CHOICE_TAG[3]="compiz-check" CHOICE_TEXT[3]="Check if Compiz will probably work." CHOICE_ACTION[3]="xterm -e \"$COMPIZ_CHECK ; read -n 1 -sp 'Press any key to exit…'\" & displayMainDialog" ########################### # Variable Initialisation # ########################### for ((i = 0; i < CHOICE_COUNT; i++)); do choices+='"${CHOICE_TAG[${i}]}" "${CHOICE_TEXT[$((i++))]}" ' done ############# # Functions # ############# # handler if Xdialog exits abnormally errorHandler() { echo $1; if [[ $retriesMain > 0 ]]; then echo "Retrying! Retries left: $((retriesMain--))" display${2}Dialog fi return } # function to display the chooser dialog displayMainDialog() { i=0 choice=$($DIALOG_CMD) case $? in 0) evaluateChoice ;; 1) return ;; 255) errorHandler "ERROR: Xdialog exited with an error or was closed abnormally" "Main" ;; esac return } # Check which action should be performed after Xdialog exits with 0 evaluateChoice() { echo "Your choice: $choice" #case $choice in #"start") #;; #"abort") #;; #"wiki") #;; #"compiz-check") #;; #*) #errorHandler "ERROR: Unexpected choice: '$choice' This might be due to a bug in the script." "Main" #esac #return for ((i = 0; i < CHOICE_COUNT; i++)); do if [ "$choice" == "${CHOICE_TAG[${i}]}" ]; then eval ${CHOICE_ACTION[${i}]} break fi done } ######## # Main # ######## displayMainDialog exit