2 # REQUIREMENTS: Must have only 1 free, unformatted partition on /dev/sda, that also happens to be at least 30 GB in size.
5 if [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -le 14 ]]; then
6 echo "ERROR - no unformatted partitions to use"
7 echo "[ERROR] No unformatted partitions to use" >>/tmp/cnchi.log
9 elif [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -ge 16 ]]; then
10 echo "ERROR - too many unformatted partition to use (must be only 1)"
11 echo "[ERROR] Too many unformatted partitions to use (must only be 1)" >>/tmp/cnchi.log
14 echo "[SUCCESS] An unformatted partition exists. Continuing to auto-partition it for you..." >>/tmp/cnchi.log
15 echo $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $3}' | tr -d B) | awk '{print $2}' >/partition.txt
16 echo $(sed '2q;d' /partition.txt)
17 export SIZE=$(sed '2q;d' /partition.txt)
21 if [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -le 4 ]]; then
22 echo "Confirmed - no unformatted partitions to use"
23 echo "[ERROR] No unformatted partitions to use" >>/tmp/cnchi.log
25 elif [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -ge 6 ]]; then
26 echo "Confirmed - too many unformatted partition to use (must be only 1)"
27 echo "[ERROR] Too many unformatted partitions to use (must only be 1)" >>/tmp/cnchi.log
30 echo "SUCCESS - never mind! Found an unformatted partition to use."
31 echo "[SUCCESS] An unformatted partition exists. Continuing to auto-partition it for you..." >>/tmp/cnchi.log
32 echo $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $3}' | tr -d B) | awk '{print $2}' >/partition.txt
33 echo $(sed '1q;d' /partition.txt)
34 export SIZE=$(sed '1q;d' /partition.txt)
40 if [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -eq 15 ]]; then
41 export SIZE=$(sed '2q;d' /partition.txt)
43 if [[ $(parted /dev/sda unit B print free | grep 'Free Space' | awk '{print $4}' | wc -c) -eq 5 ]]; then
44 export SIZE=$(sed '1q;d' /partition.txt)
46 if [ "$SIZE" -ge 30000000000 ]; then
47 echo "[SUCCESS] Partition is large enough to continue" >>/tmp/cnchi.log
50 echo "[ERROR] Partition is too small to continue" >>/tmp/cnchi.log
55 if [ -f "/sys/firmware/efi" ]; then
56 echo "[INFO] UEFI system detected" >>/tmp/cnchi.log
59 echo "[INFO] BIOS system detected" >>/tmp/cnchi.log
65 export SIZE=$(sed '1q;d' /partition.txt)
67 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.35)}') >>/tmp/rooting.txt
68 export ROOT=$(sed '1q;d' /tmp/rooting.txt)
69 echo "[INFO] Root partition will be $ROOT bytes large" >>/tmp/cnchi.log
71 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.63)}') >>/tmp/homing.txt
72 export HOME=$(sed '1q;d' /tmp/homing.txt)
73 echo "[INFO] Home partition will be $HOME bytes large" >>/tmp/cnchi.log
75 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.01)}') >>/tmp/swapping.txt
76 export SWAP=$(sed '1q;d' /tmp/swapping.txt)
77 echo "[INFO] Swap partition will be $SWAP bytes large" >>/tmp/cnchi.log
79 #echo "[INFO] SWAP file $SWAP large will be created" >>/tmp/cnchi.log
81 echo $(df -h --output=source,fstype,size,used,avail,pcent,target -x tmpfs -x devtmpfs | grep "/dev/sd" | grep "/boot/efi") >/partitioning.txt
82 export BOOT=echo $(sed '1q;d' /partitioning.txt) | awk '{print $1}'
83 echo "[INFO] Boot partition to be used is $BOOT" >>/tmp/cnchi.log
88 export SIZE=$(sed '1q;d' /partition.txt)
90 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.35)}') >>/tmp/rooting.txt
91 export ROOT=$(sed '1q;d' /tmp/rooting.txt)
92 echo "[INFO] Root partition will be $ROOT bytes large" >>/tmp/cnchi.log
94 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.63)}') >>/tmp/homing.txt
95 export HOME=$(sed '1q;d' /tmp/homing.txt)
96 echo "[INFO] Home partition will be $HOME bytes large" >>/tmp/cnchi.log
98 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.01)}') >>/tmp/swapping.txt
99 export SWAP=$(sed '1q;d' /tmp/swapping.txt)
100 echo "[INFO] Swap partition will be $SWAP bytes large" >>/tmp/cnchi.log
102 echo $(awk -vn=$SIZE 'BEGIN{print(n*0.01)}') >>/tmp/booting.txt
103 export SWAP=$(sed '1q;d' /tmp/booting.txt)
104 echo "[INFO] Boot partition will be $BOOT bytes large" >>/tmp/cnchi.log
106 #echo "[INFO] SWAP file $SWAP large will be created" >>/tmp/cnchi.log
111 export ROOT=$(sed '1q;d' /tmp/rooting.txt)
112 echo "[INFO] Root partition is being created..." >>/tmp/cnchi.log
113 export ROOT_START=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $6}'
114 export ROOT_END=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $7}'
115 export ROOT_SIZE=$((ROOT_START+ROOT))
116 unit B mkpartfs primary ext4 $ROOT_START $ROOT_SIZE
117 # Determine what partition was just created
118 echo $(fdisk -l --bytes | grep $ROOT_SIZE) | awk '{print $1}' >/root.txt
119 export ROOT_PARTITION=$(sed '1q;d' /root.txt)
120 e2label $ROOT_PARTITION "ROOT"
121 echo "$ROOT_PARTITION / ext4 defaults,relatime,data=ordered 0 1" >>/etc/fstab
122 echo "[SUCCESS] Root partition has been created as $ROOT_PARTITION" >>/tmp/cnchi.log
127 export HOME=$(sed '1q;d' /tmp/homing.txt)
128 echo "[INFO] Home partition is being created..." >>/tmp/cnchi.log
129 export HOME_START=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $6}'
130 export HOME_END=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $7}'
131 export HOME_SIZE=$((HOME_START+HOME))
132 unit B mkpartfs primary ext4 $HOME_START $HOME_SIZE
133 # Determine what partition was just created
134 echo $(fdisk -l --bytes | grep $HOME_SIZE) | awk '{print $1}' >/home.txt
135 export HOME_PARTITION=$(sed '1q;d' /home.txt)
136 e2label $HOME_PARTITION "HOME"
137 echo "$HOME_PARTITION /home ext4 defaults,relatime,data=ordered 0 0" >>/etc/fstab
138 echo "[SUCCESS] Home partition has been created as $HOME_PARTITION" >>/tmp/cnchi.log
143 export SWAP=$(sed '1q;d' /tmp/swapping.txt)
144 echo "[INFO] Swap partition is being created..." >>/tmp/cnchi.log
145 export SWAP_START=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $6}'
146 export SWAP_END=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $7}'
147 export SWAP_SIZE=$((SWAP_START+SWAP))
148 unit B mkpartfs primary swap $SWAP_START $SWAP_SIZE
149 # Determine what partition was just created
150 echo $(fdisk -l --bytes | grep $SWAP_SIZE) | awk '{print $1}' >/swap.txt
151 export SWAP_PARTITION=$(sed '1q;d' /swap.txt)
152 e2label $SWAP_PARTITION "swap"
153 echo "$SWAP_PARTITION swap swap defaults 0 0" >>/etc/fstab
154 echo "[SUCCESS] Swap partition has been created as $HOME_PARTITION" >>/tmp/cnchi.log
155 swapon $SWAP_PARTITION
159 PARTITION_UEFI_BIOS(){
160 if [ -f "/sys/firmware/efi" ]; then
161 echo $(fdisk -l --bytes | grep EFI) | awk '{print $1}' >/esp.txt
162 export ESP_PARTITION=$(sed '1q;d' /esp.txt)
163 echo "$ESP_PARTITION /boot/efi vfat defaults,relatime 0 0" >>/etc/fstab
164 echo "[SUCCESS] Boot (EFI) partition has been created as $ESP_PARTITION" >>/tmp/cnchi.log
166 echo "[INFO] Boot partition is being created..." >>/tmp/cnchi.log
167 export BOOT=$(sed '1q;d' /tmp/booting.txt)
168 export BOOT_START=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $6}'
169 export BOOT_END=echo $(parted /dev/sda unit B print free | grep 'Free Space' | tr -d B) | awk '{print $7}'
170 export BOOT_SIZE=$((HOME_START+HOME))
171 unit B mkpartfs primary ext4 $BOOT_START $BOOT_SIZE
172 # Determine what partition was just created
173 echo $(fdisk -l --bytes | grep $BOOT_SIZE) | awk '{print $1}' >/boot.txt
174 export HOME_PARTITION=$(sed '1q;d' /boot.txt)
175 e2label $BOOT_PARTITION "BOOT"
176 echo "$BOOT_PARTITION /boot ext4 defaults,relatime,data=ordered 0 0" >>/etc/fstab
177 echo "[SUCCESS] Boot partition has been created as $BOOT_PARTITION" >>/tmp/cnchi.log
184 rm -f /partitioning.txt
188 rm -f /tmp/rooting.txt
189 rm -f /tmp/homing.txt
190 rm -f /tmp/swapping.txt
191 if [ -f "/sys/firmware/efi" ]; then
195 rm -f /tmp/booting.txt
198 export -f START TEST FIRMWARE SIZES_BIOS SIZES_UEFI PARTITION_ROOT PARTITION_HOME PARTITION_SWAP PARTITION_UEFI_BIOS CLEAN