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