blob: ecbe0182d0024aa0949b75cdfbc755ffbbd3f6da (
plain) (
blame)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
#!/bin/sh
DEV=/dev
SETUP_TARGET="print"
CHROOT="/mnt"
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT=$(readlink -f "$0")
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH=$(dirname "$SCRIPT")
DIR=$(dirname "$SCRIPTPATH");
DIR_LOCAL="$(dirname $(dirname ${DIR}))/local";
ISO_FILE="${DIR_LOCAL}/crux-3.4.iso"
##read BLK_EFI
BLK_EFI="${DEV}2"
##read BLK_BOOT
BLK_BOOT="${DEV}3"
##read BLK_ROOT
BLK_ROOT="${DEV}4"
##read BLK_VAR
BLK_VAR="${DEV}5"
##read BLK_USR
BLK_USR="${DEV}6"
##read BLK_SWP
BLK_SWP="${DEV}7"
##read BLK_HOME
BLK_HOME="${DEV}8"
# First we define the function
ConfirmOrExit ()
{
while true
do
echo -n "Please confirm (y or n) :"
read CONFIRM
case $CONFIRM in
y|Y|YES|yes|Yes) break ;;
n|N|no|NO|No)
echo "Aborting - you entered $CONFIRM"
exit
;;
*) echo "Please enter only y or n"
esac
done
echo "You entered $CONFIRM. Continuing ..."
}
partition_target () {
parted --script $DEV \
mklabel gpt \
unit mib \
mkpart primary 1 3 \
name 1 grub \
set 1 bios_grub on \
mkpart ESP fat32 3 125 \
name 2 efi \
set 2 boot on \
mkpart primary ext4 125 1128 \
name 3 boot \
mkpart primary ext4 1128 5128 \
name 4 root \
mkpart primary ext4 5128 6128 \
name 5 var \
mkpart primary ext4 6128 14128 \
name 6 usr \
mkpart primary linux-swap 14128 18128 \
name 7 swap \
mkpart primary ext4 18128 100% \
name 8 home
}
mount_target () {
echo "1.1.2 Creating File System on $BLK_EFI with fat32:"
mkfs.fat -F 32 $BLK_EFI
echo "1.1.2 Creating File System on $BLK_BOOT with ext4:"
mkfs.ext4 $BLK_BOOT
echo "1.1.2 Creating File System on $BLK_ROOT with ext4:"
mkfs.ext4 $BLK_ROOT
echo "1.1.2 Creating File System on $BLK_VAR with ext4:"
mkfs.ext4 $BLK_VAR
echo "1.1.2 Creating File System on $BLK_USR with ext4:"
mkfs.ext4 $BLK_USR
echo "1.1.2 Creating Swap File System on $BLK_SWP:"
mkswap $BLK_SWP
echo "1.1.2 Creating File System on $BLK_HOME with ext4:"
mkfs.ext4 $BLK_HOME
echo "1.1.3 mount point to chroot (/mnt):\n"
mount $BLK_ROOT $CHROOT
mkdir -p $CHROOT/boot
mount $BLK_BOOT $CHROOT/boot
mkdir -p $CHROOT/boot/efi
mount $BLK_EFI $CHROOT/boot/efi
mkdir -p $CHROOT/var
mount $BLK_VAR $CHROOT/var
mkdir -p $CHROOT/usr
mount $BLK_USR $CHROOT/usr
mkdir -p $CHROOT/home
mount $BLK_HOME $CHROOT/home
mkdir -p $CHROOT/var/lib/pkg
mkdir -p $CHROOT/usr/ports
mkdir -p $CHROOT/media
mkdir -p $CHROOT/dev
mkdir -p $CHROOT/tmp
mkdir -p $CHROOT/proc
mkdir -p $CHROOT/sys
}
directory_target () {
mkdir -p $CHROOT/home
mkdir -p $CHROOT/boot/efi
mkdir -p $CHROOT/var/lib/pkg
mkdir -p $CHROOT/usr/ports
mkdir -p $CHROOT/media
mkdir -p $CHROOT/dev
mkdir -p $CHROOT/tmp
mkdir -p $CHROOT/proc
mkdir -p $CHROOT/sys
}
enable_target () {
mount --bind /dev $CHROOT/dev
mount -vt devpts devpts $CHROOT/dev/pts
mount -vt tmpfs shm $CHROOT/dev/shm
mount -vt proc proc $CHROOT/proc
mount -vt sysfs sysfs $CHROOT/sys
}
print_target() {
echo "Device: $DEV"
echo "CHROOT: $CHROOT"
echo "ISO_FILE: $ISO_FILE"
echo "Option Selected: $SETUP_TARGET\n"
echo "1.1.2 EFI block; ($BLK_EFI)"
echo "1.1.2 boot block; ($BLK_BOOT)"
echo "1.1.2 root block; ($BLK_ROOT)"
echo "1.1.2 var block; ($BLK_VAR)"
echo "1.1.2 usr block; ($BLK_USR)"
echo "1.1.2 swap block; ($BLK_SWP)"
echo "1.1.2 home block; ($BLK_HOME)\n"
}
print_help() {
echo "usage: setup_target [options]"
echo "options:"
echo " -p, --partition create partitions and file systems"
echo " -m, --mount mount partitions on chroot"
echo " -d, --directory keep temporary working directory"
echo " -e, --enable enable chroot (proc,dev, sys...)"
echo " -v, --view view environment vars and exit"
echo " -h, --help print help and exit"
}
while [ "$1" ]; do
case $1 in
-p|--partition)
SETUP_TARGET="partition"
print_target
ConfirmOrExit
partition_target
exit 0 ;;
-m|--mount)
SETUP_TARGET="mount"
print_target
ConfirmOrExit
mount_target
exit 0 ;;
-d|--directory)
SETUP_TARGET="directory"
print_target
ConfirmOrExit
directory_target
exit 0 ;;
-e|--enable)
SETUP_TARGET="enable"
print_target
ConfirmOrExit
enable_target
exit 0 ;;
-v|--view)
SETUP_TARGET="view"
print_target
exit 0 ;;
-h|--help)
print_help
exit 0 ;;
*)
echo "setup-target: invalid option $1"
exit 1 ;;
esac
shift
done
|