#!/bin/sh
crunch() {
 read STRING;
 echo $STRING;
}
rm -f /tmp/SeTswap
SWAPLIST="`probe -l | grep "Linux swap" 2> /dev/null`"
if [ "$SWAPLIST" = "" ]; then
 dialog --title "åΰ褬ޤ" --yesno "Linuxfdiskǥåץѡƥ\n\
Ƥޤ󡣥åץեʤ\n\
Τޤޥ󥹥ȡʤޤ" 8 60
 if [ "$?" = "1" ]; then
  dialog --title "󥹥ȡ" --msgbox "Linuxfdiskǥåץѡƥ\n\
٥󥹥ȡ뤷Ƥ" \
6 60
  exit
 fi
else
 echo > /tmp/swapmsg 
 if [ "`echo "$SWAPLIST" | sed -n '2 p'`" = "" ]; then
  echo "åפȤѤǤѡƥ󤬸Ĥޤ" >> /tmp/swapmsg
  echo >> /tmp/swapmsg
  echo "   Device Boot   Begin    Start      End   Blocks   Id  System" >> /tmp/swapmsg
  echo "`echo "$SWAPLIST" | sed -n '1 p'`" >> /tmp/swapmsg
  echo >> /tmp/swapmsg
  echo "򥹥åץѡƥȤƥ󥹥ȡ뤷ޤ" >> /tmp/swapmsg
  dialog --title "åΰ褬Ĥޤ" --yesno "`cat /tmp/swapmsg`" 12 70
  REPLY=$?
 else
  echo "ʲΥåץѡƥ󤬸Ĥޤ" >> /tmp/swapmsg
  echo >> /tmp/swapmsg
  echo "   Device Boot   Begin    Start      End   Blocks   Id  System" >> /tmp/swapmsg
  echo "$SWAPLIST" >> /tmp/swapmsg
  echo >> /tmp/swapmsg
  echo "򥹥åץѡƥȤƥ󥹥ȡ뤷ޤ" >> /tmp/swapmsg
  dialog --title "åΰ褬Ĥޤ" --yesno "`cat /tmp/swapmsg`" 15 70
  REPLY=$?
 fi
 rm -f /tmp/swapmsg
 if [ $REPLY = 0 ]; then # yes
   dialog --title "MKSWAPȤޤ" --yesno \
"mkswap Ȥäƥåץѡƥޤ \n\
ƤΥåץѡƥȤȤYesǤ \n\
¸ΥåץѡƥήѤݤNoǤ⹽ޤ" \
  10 74
  USE_SWAP=$?
  CURRENT_SWAP="1" 
  while [ ! "`echo "$SWAPLIST" | sed -n "$CURRENT_SWAP p"`" = "" ]; do 
   SWAP_SIZE=`probe -l | grep "Linux swap" | sed -n "$CURRENT_SWAP p" | crunch | cut -f 4 -d ' '`
   SWAP_PART=`probe -l | grep "Linux swap" | sed -n "$CURRENT_SWAP p" | crunch | cut -f 1 -d ' '`
   if [ $USE_SWAP = 0 ]; then 
    mkswap -c $SWAP_PART 1> /dev/null 2> /dev/null
    dialog --msgbox "åץѡƥνλޤ" 5 70
   fi
   swapon $SWAP_PART
   SWAP_IN_USE="`echo "$SWAP_PART       swap        swap        defaults   0   0"`"
   echo "$SWAP_IN_USE" >> /tmp/SeTswap
   CURRENT_SWAP="`expr $CURRENT_SWAP + 1`"
  done
  echo "åΰ褬ꤵޤξ" > /tmp/swapmsg
  echo "/etc/fstabɲäޤ" >> /tmp/swapmsg
  echo >> /tmp/swapmsg
  echo "$SWAP_IN_USE" >> /tmp/swapmsg 
  dialog --title "åΰ괰λ" --msgbox "`cat /tmp/swapmsg`" 13 72
  rm /tmp/swapmsg
 fi
fi  
