archive: dragora-installer/parts: added swap maker
[dragora.git] / archive / dragora-installer / parts / MakeSwap
blob88fc178f856a310fcf63016a91977a27417801e8
1 # This file is part of the 'dragora-installer'.
3 # Check for at least one swap partition
5 if ! fdisk -l 2> /dev/null | grep -q -m 1 swap
6 then
7     dialog --colors \
8      --backtitle "\ZbPartitions: Swap" \
9      --title "SWAP PARTITION NOT DETECTED" \
10      --yesno \
11 "No swap partitions detected.  This could be important\n\
12 to reduce the use of RAM memory...\n\n\
13 Would you like to proceed without a swap partition?.\n" 9 58 || \
14     {
15         printf "%s\n" "" \
16          "Please, try to create a swap partition using fdisk(8) or cfdisk(8)." \
17          "Then re-run the installer to give the proper format (if needed)."
18         exit 99;
19     }
20 else # Offer format possibility
22     list="$(fdisk -l 2> /dev/null | grep -m 1 swap)"
23     device="${list%% *}"
24     size="$(echo $list | awk '{ print $5 }')"
25     unset list
27     dialog --colors \
28      --backtitle "\ZbPartitions: Swap format" \
29      --title "SWAP PARTITION DETECTED" \
30      --ok-label "Format" \
31      --cancel-label "Ignore" \
32      --checklist \
33 "A swap partition has been detected.\n\n\
34 We offer the possibility to format it properly,\n\
35 as well as you can simply ignore this part and\n\
36 continue if you previously formatted it:\n\n\
37 Device name: $device [${size}]" 14 52 1 \
38 "$device"    "Check for bad blocks (slow)" off \
39     2> ${SUBTMPDIR}/return-MakeSwap || \
40     {
41         unset device size
42         return 0
43     }
44     unset size  # Next, we're not using it.
46     # Give format and activate swap partition
48     if test -s "${SUBTMPDIR}/return-MakeSwap"
49     then
50         dialog --colors \
51          --backtitle "\ZbPartitions: Formatting and checking swap partition ${device}" \
52          --title "SWAP PARTITION $device" \
53          --prgbox "mkswap -c $device" 30 72
54     else
55         dialog --colors \
56          --backtitle "\ZbPartitions: Formatting swap partition ${device}" \
57          --title "SWAP PARTITION $device" \
58          --prgbox "mkswap $device" 30 72
59     fi
61     dialog --colors \
62      --backtitle "\ZbPartitions: Swap partition activation" \
63      --title "SWAP PARTITION $device" \
64      --prgbox "Activating swap partition..." "swapon -f $device" 30 72
66     # Produce fstab entry for physical swap partition
68     printf "%-15s %-15s %-11s %-16s %-5s %s\n" \
69      "$device" "swap" "swap" "defaults" "0" "0" > ${SUBTMPDIR}/fstab
71     unset device