home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / sbin / chooselocale < prev    next >
Encoding:
Text File  |  2006-04-05  |  5.9 KB  |  184 lines

  1. #!/bin/sh
  2. #change locale
  3. #locale files are in /usr/lib/locale/ but Puppy won't have all of them.
  4. #they are from glibc package I think. So, will make them into an Unleashed pkg
  5. #and this script can download it, but not install it, just pick out the required
  6. #locale. ...god no, the directory in Vector is 43.8M. So will grab a selection.
  7.  
  8. CURRENTLOCALE="`cat /etc/profile | grep "LANG=" | cut -f 2 -d '=' | cut -f 1 -d ' ' | cut -f 1`"
  9.  
  10. INSTALLEDLOCALES="`ls -1 /usr/lib/locale`"
  11. INSTALLEDLOCSP="`echo -n "$INSTALLEDLOCALES" | tr "\n" " "`"
  12. if [ "$INSTALLEDLOCALES" ];then
  13.  xmessage -bg "#ffc0c0" -center -name "chooselocale" -title "chooselocale: Choose source" -buttons "LOCAL:10,DOWNLOAD:11,EXIT:12" "Welcome to the Puppy locale chooser!
  14. This will set the language and localisations for your region. Puppy is an
  15. English-only distro, however there are various internationalisation projects
  16. in progress, and this little locale switcher program is my contribution.
  17.  
  18. To save space Puppy has only these locales installed locally:
  19.  $INSTALLEDLOCSP
  20. And Puppy is currently set to this locale:
  21.  $CURRENTLOCALE
  22.  
  23. Click on LOCAL button if you want to choose from the above only...
  24. Click DOWNLOAD button if you want to download more locales to choose from..."
  25.  case $? in
  26.   10)
  27.    LOCSRC="local"
  28.    ;;
  29.   11)
  30.    LOCSRC="download"
  31.    ;;
  32.   *)
  33.    exit
  34.    ;;
  35.  esac
  36. fi
  37.  
  38. if [ "$LOCSRC" = "download" ];then
  39.  while [ 1 ];do
  40.   WWWSITE=""
  41.   PKGSRC="ftp://ibiblio.org/pub/Linux/distributions/puppylinux/pupget_packages-1"
  42.   ping -c 1 -q ibiblio.org
  43.   if [ ! $? -eq 0 ];then
  44.    ping -c 1 -q ftp.nluug.nl
  45.    if [ $? -eq 0 ];then
  46.     WWWSITE="ftp.nluug.nl"
  47.     PKGSRC="http://ftp.nluug.nl/ftp/pub/os/Linux/distr/puppylinux/pupget_packages-1"
  48.    fi
  49.   else
  50.    WWWSITE="ibiblio.org"
  51.   fi
  52.   if [ ! "$WWWSITE" ];then
  53.    xmessage -bg "#ff8080" -center -name "chooselocale" -title "chooselocale: NO INTERNET" -buttons "OKAY:10,EXIT:11" "Sorry, but there does not appear to be a connection to the Internet.
  54. This program needs to download locale files off the Internet.
  55.  
  56. Connect to the Internet then click the OKAY button..."
  57.    if [ ! $? -eq 10 ];then
  58.     exit
  59.    fi
  60.   else
  61.    break
  62.   fi
  63.  done
  64. fi
  65.  
  66. if [ "$LOCSRC" = "download" ];then
  67.  #get name of locales pkg...
  68.  #v2.0.0 unleashedpackages.txt no longer used, now use packages.txt here...
  69.  APKGNAME="`cat /root/.packages/packages.txt | grep '"glibc_locales-' | head -n 1 | cut -f 2 -d '"'`"
  70.  if [ ! "$APKGNAME" ];then
  71.   exit
  72.  fi
  73.  #download locales pkg...
  74.  xmessage -bg "orange" -center -name "chooselocale" -title "chooselocale: downloading locales" -buttons "" "Downloading locale files from $WWWSITE, please wait..." &
  75.  mkdir /root/tmp 2> /dev/null
  76.  cd /root/tmp
  77.  while [ 1 ];do
  78.   rxvt -name pupget -bg orange -geometry 80x10 -e wget $PKGSRC/${APKGNAME}.tar.gz
  79.   sync
  80.   tar -zxf $APKGNAME.tar.gz
  81.   if [ $? -eq 0 ];then
  82.    break 
  83.   fi
  84.   rm -f $APKGNAME.tar.gz 2> /dev/null
  85.  done
  86.  killall xmessage
  87. fi
  88.  
  89. #create list of locales in format for display in Xdialog radiolist...
  90. if [ "$LOCSRC" = "download" ];then
  91.  LOCALENAMES="`ls -1 /root/tmp/$APKGNAME/usr/lib/locale | tr "\n" " "`"
  92. else
  93.  LOCALENAMES="`ls -1 /usr/lib/locale | tr "\n" " "`"
  94. fi
  95. echo -n "" > /tmp/taglocales.txt
  96. for ONELOCALE in $LOCALENAMES
  97. do
  98.  if [ "$ONELOCALE" = "$CURRENTLOCALE" ];then
  99.   FSTATUS="on"
  100.  else
  101.   FSTATUS="off"
  102.  fi
  103.  echo " \"$ONELOCALE\" \"$ONELOCALE\" $FSTATUS \\" >> /tmp/taglocales.txt
  104. done
  105. sync
  106. TAGLOCALES="`cat /tmp/taglocales.txt`"
  107.  
  108. CURRENTWM="`cat /etc/windowmanager`"
  109.  
  110. rm -f /tmp/rettag.txt 2> /dev/null
  111. echo '#!/bin/sh' > /tmp/pkgdialog
  112. echo 'RETTAG="`Xdialog --title "chooselocale: Choose a locale" --left --stdout --no-tags --radiolist "Please choose a locale.\nX will be restarted after click OKAY button\n\nNote that the chosen locale files will be saved in /usr/lib/locale\nand the LANG environment variable will be set in /etc/profile" 0 0 10 \' >> /tmp/pkgdialog
  113. echo "$TAGLOCALES" >> /tmp/pkgdialog
  114. echo ' `"' >> /tmp/pkgdialog
  115. echo 'if [ ! $? -eq 0 ];then' >> /tmp/pkgdialog
  116. echo ' exit'  >> /tmp/pkgdialog
  117. echo 'fi' >> /tmp/pkgdialog
  118. echo 'echo -n "$RETTAG" > /tmp/rettag.txt' >> /tmp/pkgdialog
  119.  
  120. # ' #dummy tick to fix highlighting
  121. sync
  122. chmod 755 /tmp/pkgdialog
  123. /tmp/pkgdialog
  124.  
  125. if [ ! -f /tmp/rettag.txt ];then
  126.  exit
  127. fi
  128.  
  129. #copy chosen locale into Puppy...
  130. NEWLOCALE="`cat /tmp/rettag.txt`"
  131. if [ "$LOCSRC" = "download" ];then
  132.  #rm -rf /usr/lib/locale/$NEWLOCALE 2> /dev/null
  133.  cp -a --remove-destination /root/tmp/$APKGNAME/usr/lib/locale/$NEWLOCALE /usr/lib/locale/
  134.  sync
  135.  rm -rf /root/tmp/$APKGNAME
  136.  rm -f /root/tmp/$APKGNAME.*
  137. fi
  138.  
  139. if [ ! -d /usr/lib/locale/$NEWLOCALE ];then
  140.  xmessage "ERROR occurred. Quiting..."
  141.  exit
  142. fi
  143.  
  144. #warning before restart X...
  145. xmessage -bg "#c0ffc0" -center -name "chooselocale" -title "chooselocale: Success" -buttons "OKAY:10,EXIT:11" "It seems okay so far!
  146. Your chosen new locale is $NEWLOCALE.
  147. The new locale files are in place in /usr/lib/locale.
  148.  
  149. The LANG environment variable will be changed in /etc/profile
  150. when you click the OKAY button, then X will be restarted.
  151.  
  152. The X graphics server now has to be restarted for the change to
  153. take effect. This script will rudely terminate all X apps, so it
  154. would be wise to close any open windows and running applications
  155. yourself, right now, before clicking the OKAY button.
  156.  
  157. Note, if the new locale does not work, the files for the old
  158. locale ($CURRENTLOCALE) should still be in /usr/lib/locale,
  159. and you can manually edit the LANG variable in /etc/profile to
  160. change back.
  161.  
  162. NOTE:
  163. For those interested in exactly how this switching works, as well
  164. as restarting X the new LANG has to be enabled and this is done
  165. in /usr/X11R6/bin/xwin -- look near the bottom of the script.
  166.  
  167. Click OKAY button to restart X...
  168. Click EXIT button to quit without changing locale..."
  169.  
  170. if [ $? -eq 10 ];then
  171.  #Change locale and restart X...
  172.  OLDLANG="LANG=$CURRENTLOCALE"
  173.  NEWLANG="LANG=$NEWLOCALE"
  174.  cat /etc/profile | sed -e "s/${OLDLANG}/${NEWLANG}/" > /tmp/profile
  175.  sync
  176.  cp -f /tmp/profile /etc/profile
  177.  rm -rf /tmp/.X0-lock
  178.  #killall -9 X
  179.  sync
  180.  exec restartwm $CURRENTWM
  181. fi
  182.  
  183. ###END###
  184.