'polished up km and tz script'

This commit is contained in:
Tobias Powalowski 2008-12-17 12:09:15 +01:00
parent 556ccfae31
commit 552b74a820
2 changed files with 68 additions and 102 deletions

View file

@ -2,12 +2,12 @@
# written by Tobias Powalowski <tpowa@archlinux.org> # written by Tobias Powalowski <tpowa@archlinux.org>
ANSWER="/tmp/.km" ANSWER="/tmp/.km"
TITLE="Arch Linux Keymap And Font Setting" TITLE="Arch Linux Keymap And Console Font Setting"
BASEDIR="/usr/share/kbd" BASEDIR="/usr/share/kbd"
abort() abort()
{ {
dodialog yesno "Abort Keymap And Font Setting?" 6 40 || return 0 DIALOG --yesno "Abort Keymap And Console Font Setting?" 6 40 || return 0
[ -e /tmp/.km ] && rm -f /tmp/.km [ -e /tmp/.km ] && rm -f /tmp/.km
[ -e /tmp/.keymap ] && rm -f /tmp/.keymap [ -e /tmp/.keymap ] && rm -f /tmp/.keymap
[ -e /tmp/.font ] && rm -f /tmp/.font [ -e /tmp/.font ] && rm -f /tmp/.font
@ -16,41 +16,25 @@ abort()
exit 0 exit 0
} }
dodialog() # DIALOG()
{ # an el-cheapo dialog wrapper
# use this for msgbox, inputbox, yesno, infobox #
# # parameters: see dialog(1)
# dodialog <boxtype> <text> [height] [width] [other] # returns: whatever dialog did
# 26/3/06: added an option so that if [other] is default=no DIALOG() {
# the dialog will default to no dialog --backtitle "$TITLE" --aspect 15 "$@"
# the new dialog's auto-sizing is pretty dumb, we can't trust it return $?
height=12
width=65
if [ "$3" != "" ]; then
height=$3
fi
if [ "$4" != "" ]; then
width=$4
fi
if [ "$5" == "default=no" ]; then
dialog --defaultno --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width
else
dialog --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width $5
fi
} }
domenu() error_kmset()
{ {
menutype=$1 ; shift DIALOG --msgbox "An error occured, your current keymap was not changed." 0 0
text=$1 ; shift
height=$1 ; shift
width=$1 ; shift
mheight=$1 ; shift
dialog --cancel-label "Skip" --$menutype "$text" $height $width $mheight $*
} }
error_consoleset()
{
DIALOG --msgbox "An error occured, your current consolefont was not changed." 0 0
}
dokeymap() { dokeymap() {
echo "Scanning for keymaps..." echo "Scanning for keymaps..."
@ -58,14 +42,15 @@ dokeymap() {
for i in $(find $BASEDIR/keymaps -follow -name "*.gz" | sed 's|^.*/||g' | sort); do for i in $(find $BASEDIR/keymaps -follow -name "*.gz" | sed 's|^.*/||g' | sort); do
KEYMAPS="$KEYMAPS $i -" KEYMAPS="$KEYMAPS $i -"
done done
domenu menu "Select A Keymap" 22 60 16 $KEYMAPS 2>$ANSWER DIALOG --menu "Select A Keymap" 22 60 16 $KEYMAPS 2>$ANSWER || DIALOG --msgbox "Aborting, your current keymap was not changed." 0 0
keymap=$(cat $ANSWER) keymap=$(cat $ANSWER)
echo $keymap > /tmp/.keymap echo $keymap > /tmp/.keymap
if [ "$keymap" ]; then if [ "$keymap" ]; then
echo "Loading keymap: $keymap" echo "Loading keymap: $keymap"
#loadkeys -q $BASEDIR/keymaps/$keymap #loadkeys -q $BASEDIR/keymaps/$keymap
loadkeys -q $keymap loadkeys -q $keymap || error_kmset
fi fi
S_NEXTITEM=2
} }
doconsolefont() { doconsolefont() {
@ -75,7 +60,7 @@ doconsolefont() {
for i in $(find $BASEDIR/consolefonts -maxdepth 1 ! -name '*.cp.gz' -name "*.gz" | sed 's|^.*/||g' | sort); do for i in $(find $BASEDIR/consolefonts -maxdepth 1 ! -name '*.cp.gz' -name "*.gz" | sed 's|^.*/||g' | sort); do
FONTS="$FONTS $i -" FONTS="$FONTS $i -"
done done
domenu menu "Select A Console Font" 22 60 16 $FONTS 2>$ANSWER DIALOG --menu "Select A Console Font" 22 60 16 $FONTS 2>$ANSWER || DIALOG --msgbox "Aborting, your current consolefont was not changed." 0 0
font=$(cat $ANSWER) font=$(cat $ANSWER)
echo $font > /tmp/.font echo $font > /tmp/.font
if [ "$font" ]; then if [ "$font" ]; then
@ -88,7 +73,11 @@ doconsolefont() {
fi fi
done done
[ -e /dev/ttys0 ] && setfont $BASEDIR/consolefonts/$font -C /dev/ttyS0 [ -e /dev/ttys0 ] && setfont $BASEDIR/consolefonts/$font -C /dev/ttyS0
if [ $? -gt 0 ]; then
error_consoleset
fi
fi fi
S_NEXTITEM=3
} }
mainmenu() { mainmenu() {
@ -97,7 +86,7 @@ mainmenu() {
else else
DEFAULT="" DEFAULT=""
fi fi
dialog $DEFAULT --backtitle "$TITLE" --title " MAIN MENU " \ DIALOG $DEFAULT --backtitle "$TITLE" --title " MAIN MENU " \
--menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 15 55 8 \ --menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 15 55 8 \
"1" "Set Keymap" \ "1" "Set Keymap" \
"2" "Set Consolefont" \ "2" "Set Consolefont" \
@ -149,7 +138,7 @@ if [ -e /tmp/.km-running ]; then
fi fi
: >/tmp/.km-running : >/tmp/.km-running
while $(/bin/true); do while true; do
mainmenu mainmenu
done done

View file

@ -2,12 +2,12 @@
# written by Tobias Powalowski <tpowa@archlinux.org> # written by Tobias Powalowski <tpowa@archlinux.org>
ANSWER="/tmp/.tz" ANSWER="/tmp/.tz"
TITLE="Arch Linux Time Setting" TITLE="Arch Linux Time And Date Setting"
BASEDIR="/usr/share/zoneinfo" BASEDIR="/usr/share/zoneinfo"
abort() abort()
{ {
dodialog yesno "Abort Time Setting?" 6 40 || return 0 DIALOG --yesno "Abort Time And Date Setting?" 6 40 || return 0
[ -e /tmp/.timezone ] && rm -f /tmp/.timezone [ -e /tmp/.timezone ] && rm -f /tmp/.timezone
[ -e /tmp/.hardwareclock ] && rm -f /tmp/.hardwareclock [ -e /tmp/.hardwareclock ] && rm -f /tmp/.hardwareclock
[ -e /tmp/.tz ] && rm -f /tmp/.tz [ -e /tmp/.tz ] && rm -f /tmp/.tz
@ -18,39 +18,14 @@ abort()
exit 0 exit 0
} }
dodialog() # DIALOG()
{ # an el-cheapo dialog wrapper
# use this for msgbox, inputbox, yesno, infobox #
# # parameters: see dialog(1)
# dodialog <boxtype> <text> [height] [width] [other] # returns: whatever dialog did
# 26/3/06: added an option so that if [other] is default=no DIALOG() {
# the dialog will default to no dialog --backtitle "$TITLE" --aspect 15 "$@"
# the new dialog's auto-sizing is pretty dumb, we can't trust it return $?
height=12
width=65
if [ "$3" != "" ]; then
height=$3
fi
if [ "$4" != "" ]; then
width=$4
fi
if [ "$5" == "default=no" ]; then
dialog --defaultno --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width
else
dialog --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width $5
fi
}
domenu()
{
menutype=$1 ; shift
text=$1 ; shift
height=$1 ; shift
width=$1 ; shift
mheight=$1 ; shift
dialog --cancel-label "Skip" --$menutype "$text" $height $width $mheight $*
} }
dohwclock() { dohwclock() {
@ -76,72 +51,74 @@ SET_ZONE=""
for i in $(grep ^[A-Z] $BASEDIR/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do for i in $(grep ^[A-Z] $BASEDIR/zone.tab | cut -f 3 | sed -e 's#/.*##g'| sort -u); do
REGIONS="$REGIONS $i -" REGIONS="$REGIONS $i -"
done done
domenu menu "Please Select A Region:" 22 60 16 $REGIONS 2>$ANSWER && SET_REGION="1" DIALOG --menu "Please Select A Region:" 22 60 16 $REGIONS 2>$ANSWER && SET_REGION="1"
region=$(cat $ANSWER) region=$(cat $ANSWER)
if [ "${SET_REGION}" = "1" ]; then if [ "${SET_REGION}" = "1" ]; then
for i in $(grep ^[A-Z] $BASEDIR/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do for i in $(grep ^[A-Z] $BASEDIR/zone.tab | grep $region/ | cut -f 3 | sed -e "s#$region/##g"| sort -u); do
ZONES="$ZONES $i -" ZONES="$ZONES $i -"
done done
domenu menu "Please Select A Timezone:" 22 60 16 $ZONES 2>$ANSWER && SET_ZONE="1" DIALOG --menu "Please Select A Timezone:" 22 60 16 $ZONES 2>$ANSWER && SET_ZONE="1"
zone=$(cat $ANSWER) zone=$(cat $ANSWER)
if [ "${SET_ZONE}" = "1" ]; then if [ "${SET_ZONE}" = "1" ]; then
dodialog infobox "Setting Timezone to $region/$zone ..." DIALOG --infobox "Setting Timezone to $region/$zone ..." 0 0
echo $region/$zone > /tmp/.timezone echo $region/$zone > /tmp/.timezone
[ -e /etc/localtime ] && rm -f /etc/localtime [ -e /etc/localtime ] && rm -f /etc/localtime
cp $BASEDIR/$region/$zone /etc/localtime cp $BASEDIR/$region/$zone /etc/localtime
dohwclock dohwclock
else else
dodialog msgbox "Skipping Region and Timezone, else please select a Timezone!" DIALOG --msgbox "Skipping region and timezone, please select a timezone." 0 0
fi fi
else else
dodialog msgbox "Skipping Region and Timezone, else please select correct Region first!" DIALOG --msgbox "Skipping region and timezone, please select a region first." 0 0
fi fi
S_NEXTITEM="2" S_NEXTITEM="2"
} }
error_timeset()
{
DIALOG --msgbox "Aborting, your current time was not changed." 0 0
}
dotimeset() { dotimeset() {
SET_TIME="" SET_TIME=""
USE_NTPDATE="" USE_NTPDATE=""
HARDWARECLOCK="" HARDWARECLOCK=""
if [ ! -s /tmp/.timezone ]; then if [ ! -s /tmp/.timezone ]; then
dodialog msgbox "You have not selected a region and timezone,\nplease select one!" DIALOG --msgbox "You have to select a region and timezone." 0 0
S_NEXTITEM="1" S_NEXTITEM="1"
return 1 return 1
fi fi
dodialog yesno "Do you want to use UTC for your clock?\n\nIf you choose 'YES' UTC (recommended default) is used,\nwhich ensures daylightsaving is set automatically.\n\nIf you choose 'NO' Localtime is used,\nwhich means the system will not change the time.\nLocaltime is also prefered on dualboot machines,\nwhich also run Windows, because UTC confuses it." 15 65 && HARDWARECLOCK="UTC" DIALOG --yesno "Do you want to use UTC for your clock?\n\nIf you choose 'YES' UTC (recommended default) is used,\nwhich ensures daylightsaving is set automatically.\n\nIf you choose 'NO' Localtime is used, which means\nthe system will not change the time automatically.\nLocaltime is also prefered on dualboot machines,\nwhich also run Windows, because UTC confuses it." 15 65 && HARDWARECLOCK="UTC"
dodialog infobox "Syncing hardwareclock to systemclock ..." DIALOG --infobox "Syncing hardwareclock to systemclock ..." 0 0
HWCLOCK_PARAMS="--hctosys" HWCLOCK_PARAMS="--hctosys"
dohwclock dohwclock
dodialog yesno "Your current time is:\n$(date)\n\nDo you want to change it?" "" "" && SET_TIME="1" DIALOG --yesno "Your current time and date is:\n$(date)\n\nDo you want to change it?" 0 0 && SET_TIME="1"
if [ "${SET_TIME}" = "1" ]; then if [ "${SET_TIME}" = "1" ]; then
[ $(which ntpdate) ] && dodialog yesno "'ntpdate' was detected on your system.\n\nDo you want to use 'ntpdate' for syncing your clock,\nby using the internet clock pool?\n(You need a working internet connection for doing this!)" "" "" default=no && USE_NTPDATE="1" [ $(which ntpdate) ] && DIALOG --defaultno --yesno "'ntpdate' was detected on your system.\n\nDo you want to use 'ntpdate' for syncing your clock,\nby using the internet clock pool?\n(You need a working internet connection for doing this!)" 0 0 && USE_NTPDATE="1"
if [ "${USE_NTPDATE}" = "1" ]; then if [ "${USE_NTPDATE}" = "1" ]; then
if [ ! $(ntpdate pool.ntp.org) ]; then if [ ! $(ntpdate pool.ntp.org) ]; then
dodialog msgbox "An error has occured, time was not changed!" DIALOG --msgbox "An error has occured, time was not changed!" 0 0
S_NEXTITEM="2" S_NEXTITEM="2"
return 1 return 1
fi fi
dodialog msgbox "Synced clock with internet pool successfully.\n\nYour current time is now:\n$(date)" DIALOG --msgbox "Synced clock with internet pool successfully.\n\nYour current time is now:\n$(date)" 0 0
else else
dodialog inputbox "Your current time is:\n$(date)\n\nSyntax of your current time is:\n$(date +%m%d%H%M%y)\nMMDDhhmmYY\n\nPlease enter your correct time below,\naccording to the syntax.\n " 17 60 "" 2>$ANSWER || return 1 # display and ask to set date/time
if [ ! $(cat $ANSWER) = "" ]; then dialog --calendar "Set the date.\nUse <TAB> to navigate and arrow keys to change values." 0 0 0 0 0 2> $ANSWER || (error_timeset; return 1)
if [ ! $(date $(cat $ANSWER)) ]; then local _date="$(cat $ANSWER)"
dodialog msgbox "An error occured during time setting,\ncurrent time was not changed!" dialog --timebox "Set the time.\nUse <TAB> to navigate and up/down to change values." 0 0 2> $ANSWER || (error_timeset; return 1)
S_NEXTITEM="2" local _time="$(cat $ANSWER)"
return 1 # save the time
fi # DD/MM/YYYY hh:mm:ss -> YYYY-MM-DD hh:mm:ss
else local _datetime="$(echo "$_date" "$_time" | sed 's#\(..\)/\(..\)/\(....\) \(..\):\(..\):\(..\)#\3-\2-\1 \4:\5:\6#g')"
dodialog msgbox "You entered nothing, current time was not changed!" date -s "$_datetime"
S_NEXTITEM="2" DIALOG --infobox "Syncing systemclock to hardwareclock ..." 0 0
return 1
fi
dodialog infobox "Syncing systemclock to hardwareclock ..."
HWCLOCK_PARAMS="--systohc" HWCLOCK_PARAMS="--systohc"
dohwclock dohwclock
dodialog msgbox "Your current time is now:\n$(date)" DIALOG --msgbox "Your current time is now:\n$(date)" 0 0
fi fi
else else
dodialog msgbox "Current time was not changed!" DIALOG --msgbox "Current time was not changed!" 0 0
fi fi
S_NEXTITEM="3" S_NEXTITEM="3"
} }
@ -152,10 +129,10 @@ mainmenu() {
else else
DEFAULT="" DEFAULT=""
fi fi
dialog $DEFAULT --backtitle "$TITLE" --title " MAIN MENU " \ DIALOG $DEFAULT --backtitle "$TITLE" --title " MAIN MENU " \
--menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 15 55 8 \ --menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 15 55 8 \
"1" "Select Region and Timezone" \ "1" "Select Region and Timezone" \
"2" "Set Date and Time" \ "2" "Set Time and Date" \
"3" "Exit" 2>$ANSWER "3" "Exit" 2>$ANSWER
case $(cat $ANSWER) in case $(cat $ANSWER) in
"1") "1")
@ -200,7 +177,7 @@ if [ -e /tmp/.tz-running ]; then
fi fi
: >/tmp/.tz-running : >/tmp/.tz-running
while $(/bin/true); do while true; do
mainmenu mainmenu
done done