summaryrefslogtreecommitdiff
path: root/source/installer/sources/initrd/usr/lib/setup/SeTswap
blob: f9eb52fc8abb9a9d599b547d43677b1a001abddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh

TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
  mkdir -p $TMP
fi
REDIR=/dev/tty4
NDIR=/dev/null

crunch() {
 read STRING;
 echo $STRING;
}

# get_part_size( dev ) - Return the size in K, M, G, T, or P of the named partition.
get_part_size() {
  numfmt --to=iec $(blockdev --getsize64 $1)
}

rm -f $TMP/SeTswap $TMP/SeTswapskip $TMP/SeTuseswap $TMP/tmpscript

SWAPLIST="`probe -l 2> /dev/null | grep "Linux swap" | cut -f 1 -d ' ' | sort 2> $NDIR`" 

if [ "$SWAPLIST" = "" ]; then
 dialog --title "NO SWAP SPACE DETECTED" --yesno "You have not created \
a swap partition with Linux fdisk. \
Do you want to continue installing without one? " 6 60
 if [ "$?" = "1" ]; then
  dialog --title "ABORTING INSTALLATION" --msgbox "Create a swap partition with Linux fdisk, and then try this again." \
6 40
 else
  touch $TMP/SeTswapskip
 fi
 exit
else # there is at least one swap partition:
 # Build the swap partition selection menu:
 cat << EOF > $TMP/tmpscript
dialog --backtitle "Setting up swap partitions." \\
--title "SWAP SPACE DETECTED" --checklist \\
"Slackware Setup has detected one or more swap partitions \\
on your system. These partitions have been \\
preselected to be set up as swap space. If there are any \\
swap partitions that you \\
do not wish to use with this installation, please unselect \\
them with the up and down arrows and spacebar. If you wish \\
to use all of them (this is recommended), simply hit \\
the ENTER key." \\
0 0 0 \\
EOF
 for swappartition in $SWAPLIST ; do
  PARTSIZE=$(get_part_size $swappartition)
  cat << EOF >> $TMP/tmpscript
"$swappartition" "Linux swap partition, ${PARTSIZE}" on \\
EOF
 done
 cat << EOF >> $TMP/tmpscript
 2> $TMP/SeTuseswap
EOF
 . $TMP/tmpscript
 if [ ! $? = 0 ]; then
  rm -f $TMP/tmpscript $TMP/SeTswap $TMP/SeTuseswap
  touch $TMP/SeTswapskip
 fi

 if [ -r $TMP/SeTuseswap ]; then
  # Remove extra quotes from SeTuseswap, if any:
  cat $TMP/SeTuseswap | tr -d \" > $TMP/SeTfoo
  mv $TMP/SeTfoo $TMP/SeTuseswap

  # Were any swap partitions asked for?
  if [ "$(cat $TMP/SeTuseswap)" = "" -a ! -r $TMP/SeTswapskip ]; then
   rm -f $TMP/tmpscript $TMP/SeTswap $TMP/SeTuseswap
   touch $TMP/SeTswapskip
  fi
 fi

 if [ ! -r $TMP/SeTswapskip ]; then
  dialog --backtitle "Setting up swap partitions." \
 --title "CHECK SWAP PARTITIONS FOR BAD BLOCKS?" --defaultno --yesno \
"Slackware Setup will now prepare your system's swap space. \
When formatting swap partitions with mkswap you may also check \
them for bad blocks. This is not the default since nearly all \
modern hard drives check themselves for bad blocks anyway. \
Would you like to check for bad blocks while running mkswap?" \
10 60
  if [ $? = 0 ]; then
   CHECKBAD=yes
  else
   CHECKBAD=no
  fi

  # Run mkswap on swap partitions, unless they are already in use:
  for swappartition in $(cat $TMP/SeTuseswap) ; do
   if ! grep -w $swappartition /proc/swaps 1> $REDIR 2> $REDIR ; then
    if [ "$CHECKBAD" = "no" ]; then
     mkswap -v1 $swappartition 1> $REDIR 2> $REDIR
    else
     mkswap -c -v1 $swappartition 1> $REDIR 2> $REDIR
    fi
    echo "Activating swap partition ${swappartition}:"
    echo "swapon ${swappartition}"
    swapon $swappartition 1> $REDIR 2> $REDIR
   fi
  done

  # This is so people don't ask what that output was that flashed
  # by on the screen.  ;-)
  sleep 1

  # Add the swap partitions to the file that will go into /etc/fstab:
  for swappartition in $(cat $TMP/SeTuseswap) ; do
   printf "%-16s %-16s %-11s %-16s %-3s %s\n" "$swappartition" "swap" "swap" "defaults" "0" "0" >> $TMP/SeTswap
  done

  echo "Your swapspace has been configured. This information will" > $TMP/swapmsg
  echo "be added to your /etc/fstab:" >> $TMP/swapmsg
  echo >> $TMP/swapmsg
  cat $TMP/SeTswap >> $TMP/swapmsg
  dialog --title "SWAP SPACE CONFIGURED" --exit-label OK --textbox $TMP/swapmsg 10 72
  rm $TMP/swapmsg
 fi  
fi