-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoPart
More file actions
executable file
·151 lines (127 loc) · 7.49 KB
/
autoPart
File metadata and controls
executable file
·151 lines (127 loc) · 7.49 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env sh
#########################################################################################################################################################################################
## A U T O L I N U X P A R T I T I O N I N G S C R I P T ##
#########################################################################################################################################################################################
# _ _ _ __ _ _ #
# /.\ _ _ FJ_ ____ FJ / J _ _ _ _ _ FJ LJ #
# //_\\ J | | LJ _| F __ J J | LFJ J ' \ J J | | L J \/ F #
# / ___ \ | | | || |-' | |--| | | | J L | |\\ | | | | | / \ #
# / L___J \ F L__J JF |__-.F L__J J F L_____ J L F L \ JJ F L__J J / /\ \ #
# J__L J__J\____,__\_____J\______/J________LJ__LJ__L \\J__LJ\____,__LJ__//\\__L #
# |__L J__|J____,__J_____FJ______F|________||__||__L J__| J____,__F|__/ \__| #
#########################################################################################################################################################################################
#########################################################################################################################################################################################
dsks=$(mktemp)
selDsk=$(mktemp)
selPar=$(mktemp)
selPart=$(mktemp)
selSwap=$(mktemp)
selBoot=$(mktemp)
selRootFS=$(mktemp)
selSwap=$(mktemp)
wholeDisk=$(mktemp)
confirm=$(mktemp)
partitions=$(mktemp)
lines(){ cat $1|wc -l; }
selectParts(){ selBoot ; selSwap ; selRootFS ; }
err(){ echo >&2 "$(tput bold; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)";exit 1; }
selDisk(){ \
dialog --stdout --colors --title "Partitioning" \
--menu " Which drive will be used for the AutoLinux installation?" 30 65 0 \
"${drives[@]}" > $selDsk
}
selBoot(){ \
dialog --stdout --no-cancel --colors --title "Partitioning" \
--menu " Which Partition will be used for the bootloader?" 30 65 0 \
"${parts[@]}" > $selBoot
}
selSwap(){ \
dialog --stdout --colors --title "Partitioning" \
--ok-label "Continue" \
--cancel-label "No Swap" \
--menu " Which Partition will be used for the swap?" 30 65 0 \
"${parts[@]}" > $selSwap
}
selRootFS(){ \
dialog --stdout --no-cancel --colors --title "Partitioning" \
--menu " Which Partition will be used for the root filesystem?" 30 65 0 \
"${parts[@]}" > $selRootFS
}
wholeDisk(){ \
dialog --stdout --colors --extra-button \
--title "Partitioning" \
--extra-label "WIPE DISK" \
--yes-label 'Select Partitions' \
--no-label 'Go Back' \
--yesno "Would you like to wipe the entire drive, or manually select partitions?" 6 80 ;
echo $? > $wholeDisk
}
allDisks(){ \
sudo fdisk -l|grep -B 1 "Disk model:"|sed 's/,.*sectors//g;s/://g;s/Disk\s*\///g;s/Disk model //g'|xargs|sed \
's/ -- /\n/g;s/dev/"\/dev/g;s/\n/"\n/g;s/^/drives=(\n/g;s/$/"\n)/g'|sed 's/ /" "/;s/iB /iB /' >$dsks ; source $dsks ; }
getDisk(){ \
eval $(sudo fdisk -lo Device,Size,Type|grep $(cat $selDsk) >$selPar ; n=1 ; echo "parts=(" >$selPart
cat $selPar|while read x; do echo "$(sudo head -n $n $selPar|tail -n1|cut -d' ' -f1|sed "s/^/'/;s/$/'/")\
$(echo $x|cut -d' ' -f2-|sed "s/^/\t\'/;s/$/\'/")"|sed '/Disk.*bytes,.*sectors/d'; ((n++)) ; done >>$selPart &&
echo -e ")" >>$selPart) ; source $selPart ; }
confirm(){ \
dialog --stdout --colors --title "Partitioning" \
--yes-label 'NO. Go Back' \
--no-label 'YES. Continue' \
--yesno "\\nAre you sure you want to completely wipe $(cat $selDsk)?\\n\\nThis action CANNOT be undone." 9 90 ;
WIPE=$? ; }
wipeDisk(){ \
PRTED="sudo parted -s $(cat $selDsk)"
sudo wipefs $(cat $selDsk)
dialog --colors --title "Partitioning" --infobox "Preparing $(cat $selDsk)1 - the legacy boot partition, Pease be patient..." 3 80 ;
$PRTED mklabel gpt >/dev/null 2>&1
$PRTED mkpart primary 1 3 >/dev/null 2>&1
$PRTED name 1 legacy >/dev/null 2>&1
$PRTED set 1 bios_grub on
dialog --colors --title "Partitioning" --infobox "Preparing $(cat $selDsk)2 - the uefi boot partition, Pease be patient..." 3 80 ;
$PRTED mkpart primary fat32 3MiB 256MiB >/dev/null 2>&1
$PRTED name 2 boot >/dev/null 2>&1
$PRTED set 2 boot on
yes|sudo mkfs.fat -F32 $(cat $selDsk)2 >/dev/null 2>&1
dialog --colors --title "Partitioning" --infobox "Preparing $(cat $selDsk)3 - the swap partition, Pease be patient..." 3 80 ;
$PRTED mkpart primary 256MiB 4352MiB >/dev/null 2>&1
$PRTED name 3 swap >/dev/null 2>&1
$PRTED set 3 swap on
yes|sudo mkswap $(cat $selDsk)3 >/dev/null 2>&1 ;
sudo swapon $(cat $selDsk)3 >/dev/null 2>&1
dialog --colors --title "Partitioning" --infobox "Preparing $(cat $selDsk)4 - the root filesystem, Pease be patient..." 3 80 ;
$PRTED mkpart primary ext4 4352MiB 100% >/dev/null 2>&1
$PRTED name 4 rootfs >/dev/null 2>&1
yes|sudo mkfs.ext4 $(cat $selDsk)4 >/dev/null 2>&1 ; }
definedPartitioning(){ \
dialog --colors --title "Partitioning" --infobox "Preparing the $(cat $selBoot) - the boot partition, Pease be patient..." 3 80 ;
yes|sudo mkfs.fat -F32 $(cat $selBoot) >/dev/null 2>&1
[ -n "$(cat $selSwap)" ] && dialog --colors --title "Partitioning" --infobox "Preparing the $(cat $selSwap) - the swap partition, Pease be patient..." 3 80 ;
[ -n "$(cat $selSwap)" ] && yes|sudo mkswap $(cat $selSwap) >/dev/null 2>&1
dialog --colors --title "Partitioning" --infobox "Preparing $(cat $selRootFS) - the root filesystem, Pease be patient..." 3 80 ;
yes|sudo mkfs.ext4 $(cat $selRootFS) >/dev/null 2>&1
[ -n "$(cat $selSwap)" ] && sudo swapon $(cat $selSwap) >/dev/null 2>&1
}
definedConfirm(){ \
dialog --colors --title "Partitioning" \
--yes-label "Im Sure" \
--no-label "Wait, Go Back" \
--yesno "\\nAre you happy with your selection?\\n\\n1. Boot Partition: $(cat $selBoot)\\n2. Swap Partition: $(cat $selSwap)\\n3. Root File System: $(cat $selRootFS)\\n\\nOnce you have confirmed, there in no going back." 14 80 ;
defConf=$? ; }
completion(){ dialog --colors --title " ~ AutoLinux ~ " \
--infobox "Partitioning Completed Successfully! Now continuing to install base system..." 5 85 ; }
begin(){ \
n=1 ; selDisk || err "User Exited."
getDisk || err "User Exited."
wholeDisk || err "User Exited."
case "$(cat $wholeDisk)" in
1) getDisk && begin ;;
0) selectParts && definedConfirm && definedPartitioning && wipeType='manual'
mount $selRootFS /mnt && completion || err "User Exited.";;
3) confirm && case "$(echo $WIPE)" in
'0') begin ;;
'1') wipeDisk && completion && sleep 2 && wipeType='automatic'; mount $(cat $selDsk)4 /mnt ;;
esac ;;
esac ; }
allDisks || err "Could not find any disks." ;
begin || err "User Exited."