#!/bin/bash
failure_shutdown()
{
    case `echo $LANG | cut -d "." -f 1` in
	'ja_JP')
	    msg=\
"<b><big>       シャットダウン          </big></b>\n\
\n\
シャットダウン実行の権限が有りません。
/etc/sudores を適切に設定し、\n\
`whoami` にシャットダウン実行の権限を与えて下さい。"
            ttl="シャットダウン"
	    ;;
	*)
	    msg=\
"<b><big>        Shutdown          </big></b>\n\
\n\
You must have permission for 'Shutdown'.
Please edit/etc/sudores and give `whoami`\n\
the permission for 'Shutdown'. "
            ttl="Reboot"
	    ;;
    esac

    if [ "$LANG" == "ja_JP.eucJP" ]; then
        msg=`echo "$msg" | nkf -e`
        ttl=`echo "$ttl" | nkf -e`
    fi
    zenity --info --title="$ttl" --no-wrap \
        --text="$msg"
}

confirm()
{
    case `echo $LANG | cut -d "." -f 1` in
	'ja_JP')
	    msg=\
"<b>           <big>シャットダウン          </big></b>\n\
\n\
システムをシャットダウンします。お疲れ様でした。"
            ttl="シャットダウン"
	    ;;
	*)
	    msg=\
"<b><big>        Shutdown          </big></b>\n\
\n\
System will be Shutdown. Thank you."
            ttl="Shutdown"
	    ;;
    esac

    if [ "$LANG" == "ja_JP.eucJP" ]; then
        msg=`echo "$msg" | nkf -e`
        ttl=`echo "$ttl" | nkf -e`
    fi
    zenity --question --title="$ttl" --no-wrap \
        --text="$msg" || exit
    sudo shutdown -h now || failure_shutdown
}

# ------------------------------

CONFIG=~/.fluxbox/fb_conf
shutdown_confirm=false

if [ ! -f "$CONFIG" ]; then
    cat > "$CONFIG" <<EOF
# Fluxbox setting for Vine Linux
# 各値を true か false に設定して下さい。
# '=' の左右に空白は入れないで下さい。

shutdown_confirm=true  # シャットダウン時に確認を取る
EOF
else
    if [ ! `grep shutdown_confirm "$CONFIG"` ]; then
        cat >> "$CONFIG" <<EOF
shutdown_confirm=true  # シャットダウン時に確認を取る
EOF
    fi
fi

. "$CONFIG"

if [ "$shutdown_confirm" == true ]; then
    confirm
else
    sudo shutdown -h now
fi
