3 #########################################################
4 ## Allow manual partitioning when installing instantOS ##
5 ## Supports editing partitions and using existing ones ##
6 #########################################################
8 # todo: warning and confirmation messages
10 source /root/instantARCH/askutils.sh
12 # first displayed menu
14 STARTCHOICE="$(echo 'edit partitions
15 choose partitions' | imenu -l)"
17 case "$STARTCHOICE" in
27 # cfdisk wrapper to modify partition table during installation
29 echo 'instantOS requires the following paritions:
30 - a root partition, all data on it will be erased
31 - an optional home partition.
32 If not specified, the same partition as root will be used.
33 Gives you the option to keep existing data on the partition
34 - an optional swap partition.
35 If not specified a swap file will be used.
36 The Bootloader requires
38 - an EFI partition on uefi systems
39 - a disk to install it to on legacy-bios systems
42 EDITDISK="$(fdisk -l | grep -i '^Disk /.*:' | imenu -l 'choose disk to edit> ' | grep -o '/dev/[^:]*')"
43 echo "editing disk $EDITDISK"
45 if command -v st; then
46 st -e bash -c "cfdisk $EDITDISK"
47 elif command -v st; then
48 st -e bash -c "cfdisk $EDITDISK"
50 xterm -e bash -c "cfdisk $EDITDISK"
56 iroot disk "$EDITDISK"
60 # choose all partitions
68 # menu that allows choosing a partition and put it in stdout
71 while [ -z "$RETURNPART" ]; do
72 fdisk -l | grep '^/dev' | sed 's/\*/ b /g' | imenu -l "$1" | grep -o '^[^ ]*' >/tmp/diskchoice
73 RETURNPART="$(cat /tmp/diskchoice)"
74 if ! [ -e "$RETURNPART" ]; then
75 imenu -m "$RETURNPART does not exist" &>/dev/null
79 for i in /root/instantARCH/config/part*; do
80 if grep "^$RETURNPART$" "$i"; then
81 echo "partition $RETURNPART already taken"
82 imenu -m "partition $RETURNPART is already selected for $i"
83 CANCELOPTION="$(echo '> alternative options
84 select another partition
85 cancel partition selection' | imenu -l ' ')"
86 if grep -q 'cancel' <<<"$CANCELOPTION"; then
87 touch /tmp/loopaskdisk
89 iroot r manualpartitioning
100 # choose home partition, allow using existing content or reformatting
102 if ! imenu -c "do you want to use a seperate home partition?"; then
106 HOMEPART="$(choosepart 'choose home partition >')"
107 case "$(echo 'keep current home data
108 erase partition to start fresh' | imenu -l)" in
117 iroot parthome "$HOMEPART"
118 echo "$HOMEPART" >/root/instantARCH/config/parthome
122 # choose swap partition or swap file
124 case "$(echo 'use a swap file
125 use a swap partition' | imenu -l)" in
128 echo "using a swap file"
131 echo "using a swap partition"
132 while [ -z "$SWAPCONFIRM" ]; do
133 PARTSWAP="$(choosepart 'choose swap partition> ')"
134 if imenu -c "This will erase all data on that partition. It should also be on a fast drive. Continue?"; then
136 echo "$PARTSWAP will be used as swap"
137 echo "$PARTSWAP" | iroot i partswap
145 # choose root partition for programs etc
147 while [ -z "$ROOTCONFIRM" ]; do
148 PARTROOT="$(choosepart 'choose root partition (required) ')"
149 if imenu -c "This will erase all data on that partition. Continue?"; then
151 echo "instantOS will be installed on $PARTROOT"
153 echo "$PARTROOT" | iroot i partroot
157 # choose wether to install grub and where to install it
160 while [ -z "$BOOTLOADERCONFIRM" ]; do
161 if ! imenu -c "install bootloader (grub) ? (recommended)"; then
162 if imenu -c "are you sure? This could make the system unbootable. "; then
167 BOOTLOADERCONFIRM="true"
173 while [ -z "$EFICONFIRM" ]; do
174 choosepart 'select efi partition' | iroot i partefi
175 if imenu -c "this will erase all data on $(iroot partefi). Existing operating systems will be detected and added back into the bootloader"; then
178 rm /root/instantARCH/config/partefi
183 GRUBDISK=$(fdisk -l | grep -i '^Disk /.*:' | imenu -l "select disk for grub " | grep -o '/dev/[^:]*')
185 iroot grubdisk "$GRUBDISK"
190 iroot manualpartitioning 1