#!/bin/bash
failure_shutdown()
{
    msg=\
"<b><big>       シャットダウン          </big></b>\n\
\n\
シャットダウン実行の権限が有りません。
/etc/sudores を適切に設定し、\n\
`whoami` にシャットダウン実行の権限を与えて下さい。"
    ttl="シャットダウン"
    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()
{
    msg=\
"<b>           <big>シャットダウン          </big></b>\n\
\n\
システムをシャットダウンします。お疲れ様でした。"
    ttl="シャットダウン"
    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=~/.config/fbpanel/fbpanel_conf
shutdown_confirm=false

if [ ! -f "$CONFIG" ]; then
    cat > "$CONFIG" <<EOF
# Fbpanel 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
