#!/bin/bash
failure_reboot()
{
    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>        Reboot          </big></b>\n\
\n\
You must have permission for rebooting.
Please edit/etc/sudores and give `whoami`\n\
the permission for rebooting. "
            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>        Reboot          </big></b>\n\
\n\
System will be rebooting. Thank you."
            ttl="Reboot"
	    ;;
    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 -r now || failure_reboot
}

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

CONFIG=~/.fluxbox/fb_conf
reboot_confirm=false

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

reboot_confirm=true    # リブート時に確認をとる
EOF
else
    if [ ! `grep reboot_confirm "$CONFIG"` ]; then
        cat >> "$CONFIG" <<EOF
reboot_confirm=true    # リブート時に確認をとる
EOF
    fi
fi

. "$CONFIG"

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