Menu

[r5]: / trunk / misc / setupfreenas.sh  Maximize  Restore  History

Download this file

499 lines (436 with data), 12.4 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/usr/bin/env bash
# This is a script designed to automate the assembly of
# a FreeNAS box.
# Created: 2/12/2006 by Scott Zahn
# Global Variables:
FREENAS_VERSION=0.67
FREENAS_PLATFORM_CD="generic-pc-cdrom"
FREENAS_PLATFORM="generic-pc"
WORKINGDIR="/usr/local/freenas"
FREENAS="/usr/local/freenas/rootfs"
BOOTDIR="/usr/local/freenas/bootloader"
# Functions:
create_fs() {
if [ -d $FREENAS ]; then
echo
echo "$FREENAS already exists. Remove the directory"
echo "before running this script."
echo
echo "Exiting..."
echo
exit
fi
mkdir $FREENAS
cd $FREENAS
mkdir boot ;
mkdir boot/kernel ;
mkdir bin ;
mkdir cf ;
mkdir ftmp ;
mkdir conf.default ;
mkdir dev ;
mkdir etc ;
mkdir etc/defaults ;
mkdir etc/inc ;
mkdir etc/pam.d ;
mkdir etc/ssh ;
mkdir lib ;
mkdir libexec ;
mkdir -m 0777 mnt ;
mkdir -m 0700 root ;
mkdir sbin ;
mkdir usr ;
mkdir usr/bin ;
mkdir usr/lib ;
mkdir usr/lib/aout ;
mkdir usr/libexec ;
mkdir usr/local ;
mkdir usr/local/bin;
mkdir usr/local/lib ;
mkdir usr/local/sbin ;
mkdir usr/local/www ;
mkdir usr/sbin ;
mkdir usr/share ;
mkdir tmp ;
# share/empty mandatory for VSFTPD
mkdir usr/share/empty ;
mkdir var ;
# Creating symbolic links
#ln -s var/tmp tmp
ln -s cf/conf conf
ln -s /var/run/htpasswd usr/local/www/.htpasswd
ln -s /var/etc/resolv.conf etc/resolv.conf
ln -s /var/etc/master.passwd etc/master.passwd
ln -s /var/etc/passwd etc/passwd
ln -s /var/etc/group etc/group
ln -s /var/etc/pwd.db etc/pwd.db
ln -s /var/etc/spwd.db etc/spwd.db
ln -s /var/etc/crontab etc/crontab
ln -s /var/etc/ssh/sshd_config etc/ssh/sshd_config
ln -s /var/etc/ssh/ssh_host_dsa_key etc/ssh/ssh_host_dsa_key
ln -s /var/etc/pam.d/ftp etc/pam.d/ftp
ln -s /var/etc/pam.d/sshd etc/pam.d/sshd
ln -s /var/etc/pam.d/login etc/pam.d/login
ln -s /var/etc/nsswitch.conf etc/nsswitch.conf
ln -s /libexec/ld-elf.so.1 usr/libexec/ld-elf.so.1
return 0
}
copy_bins() {
[ -f freenas.files ] && rm -f freenas.files
fetch http://www.freenas.org/downloads/freenas.files
# Add custom binaries
if [ -f freenas.custfiles ]; then
cat freenas.custfiles >> freenas.files
fi
for i in $(cat freenas.files | grep -v "^#"); do
file=$(echo "$i" | cut -d ":" -f 1)
cp -p /$file $FREENAS/$(echo $file | rev | cut -d "/" -f 2- | rev)
# deal with links
if [ $(echo "$i" | grep -c ":") -gt 0 ]; then
for j in $(echo $i | cut -d ":" -f 2- | sed "s/:/ /g"); do
ln $FREENAS/$file $FREENAS/$j
done
fi
done
return 0
}
prep_etc() {
[ -f freenas-etc.tgz ] && rm -f freenas-etc.tgz
fetch http://www.freenas.org/downloads/freenas-etc.tgz
tar -xzf freenas-etc.tgz -C $FREENAS/
#chmod 755 $FREENAS/etc/rc.*
pwd_mkdb -p -d $FREENAS/etc $FREENAS/etc/master.passwd
echo $FREENAS_VERSION > $FREENAS/etc/version
date > $FREENAS/etc/version.buildtime
echo $FREENAS_PLATFORM > $FREENAS/etc/platform
cd $FREENAS/conf.default/
fetch http://www.freenas.org/downloads/config.xml
cd $FREENAS/usr/share/
fetch http://www.freenas.org/downloads/zoneinfo.tgz
return 0
}
build_kernel() {
cd /sys/i386/conf
if [ -f FREENAS ]; then
rm -f FREENAS
fi
fetch http://freenas.org/downloads/FREENAS
config /sys/i386/conf/FREENAS
cd /sys/i386/compile/FREENAS
make clean
make depend && make
gzip -9 kernel
cp -p modules/usr/src/sys/modules/geom/geom_vinum/geom_vinum.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/geom/geom_stripe/geom_stripe.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/geom/geom_concat/geom_concat.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/geom/geom_mirror/geom_mirror.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/geom/geom_gpt/geom_gpt.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/ntfs/ntfs.ko $FREENAS/boot/kernel
cp -p modules/usr/src/sys/modules/ext2fs/ext2fs.ko $FREENAS/boot/kernel/
cp -p /boot/mbr $FREENAS/boot/
return 0
}
build_php() {
php_tarball=$(ls php*.tar.gz | tail -n1)
if [ -z "$php_tarball" ]; then
echo "PHP tarball not found. Download PHP (tar.gz) and run step again."
return 1
else
tar -zxf $php_tarball
cd $(basename $php_tarball .tar.gz)
./configure --without-mysql --without-pear --with-openssl --enable-discard-path
make
install -s sapi/cgi/php $FREENAS/usr/local/bin
echo 'magic_quotes_gpc = off
magic_quotes_runtime = off
max_execution_time = 0
max_input_time = 180
register_argc_argv = off
file_uploads = on
upload_tmp_dir = /ftmp
upload_max_filesize = 32M
post_max_size = 48M
html_errors = off
include_path = ".:/etc/inc:/usr/local/www"' > $FREENAS/usr/local/lib/php.ini
fi
return 0
}
build_httpd() {
httpd_tarball=$(ls mini_httpd*.tar.gz | tail -n1)
if [ ! -z "$http_tarball" ]; then
rm -f $http_tarball
fi
fetch http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz
if [ -f mini_httpd.c.patch ]; then
rm -f mini_httpd.c.patch
fi
fetch http://www.freenas.org/downloads/patchs/mini_httpd.c.patch
tar -xzf $httpd_tarball
patch < mini_httpd.c.patch
cd $(basename $httpd_tarball .tar.gz)
make
install -s mini_httpd $FREENAS/usr/local/sbin
return 0
}
build_msntp() {
cd /usr/ports/net/msntp
make
install -s work/msntp*/msntp $FREENAS/usr/local/bin
echo '#!/bin/sh
# write our PID to file
echo $$ > $1
# execute msntp in endless loop; restart if it
# exits (wait 1 second to avoid restarting too fast in case
# the network is not yet setup)
while true; do
/usr/local/bin/msntp -r -P no -l $2 -x $3 $4
sleep 1
done' > $FREENAS/usr/local/bin/runmsntp.sh
chmod +x $FREENAS/usr/local/bin/runmsntp.sh
return 0
}
build_ataidle() {
cd /usr/ports/sysutils/ataidle
make
install -s work/ataidle*/ataidle $FREENAS/usr/local/sbin
return 0
}
build_vsftp() {
vsftp_tarball=$(ls vsftpd*.tar.gz | tail -n1)
if [ -z "$vsftp_tarball" ]; then
fetch ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.0.4.tar.gz
else
tar -zxf $vsftp_tarball
cd $(basename $vsftp_tarball .tar.gz)
make
install -s vsftpd $FREENAS/usr/local/sbin/
fi
return 0
}
build_samba() {
if [ ! -f samba-latest.tar.gz ]; then
fetch http://us2.samba.org/samba/ftp/samba-latest.tar.gz
fi
tar -zxf samba-latest.tar.gz
samba_dir=$(ls -d samba-3* | tail -n1)
cd $samba_dir/source
./configure --with-ldap --with-ads --with-pam --with-ldapsam --without-utmp --without-winbind --disable-cups --with-acl-support --with-logfilebase=/var/log/samba --with-piddir=/var/run --with-privatedir=/var/etc/private --with-configdir=/var/etc --with-lockdir=/var/run
make
install -s bin/smbd $FREENAS/usr/local/sbin/
install -s bin/nmbd $FREENAS/usr/local/sbin/
install -s bin/smbstatus $FREENAS/usr/bin/
install -s bin/smbcontrol $FREENAS/usr/bin/
install -s bin/smbtree $FREENAS/usr/bin/
mkdir -p $FREENAS/usr/local/lib/samba/vfs
mkdir $FREENAS/usr/local/lib/samba/charset
mkdir $FREENAS/usr/local/lib/samba/rpc
mkdir $FREENAS/usr/local/lib/samba/pdb
cp bin/*.so $FREENAS/usr/local/lib/samba/vfs
mv $FREENAS/usr/local/lib/samba/vfs/CP*.so $FREENAS/usr/local/lib/samba/charset
cp codepages/*.dat $FREENAS/usr/local/lib/samba
cp po/*.* $FREENAS/usr/local/lib/samba
return 0
}
install_nfs() {
cp -p /usr/sbin/nfsd $FREENAS/usr/sbin
cp -p /usr/sbin/mountd $FREENAS/usr/sbin
cp -p /usr/sbin/rpcbind $FREENAS/usr/sbin
return 0
}
build_netatalk() {
cd /usr/ports/net/netatalk
echo "This isn't implemented yet." && sleep 2
#make
# TODO: FINISH THIS
return 0
}
build_rsync() {
cd /usr/ports/net/rsync
make
install -s work/rsync-*/rsync $FREENAS/usr/local/bin
return 0
}
build_smarttools() {
cd /usr/ports/sysutils/smartmontools
make
install -s work/smartmontools-*/smartctl $FREENAS/usr/local/sbin
install -s work/smartmontools-*/smartd $FREENAS/usr/local/sbin
return 0
}
build_beep() {
cd /usr/ports/audio/beep
make
install -s work/beep/beep $FREENAS/usr/local/bin
return 0
}
build_bootldr() {
mkdir -p $BOOTDIR/defaults
mkdir $BOOTDIR/kernel
cp -p /boot/defaults/loader.conf $BOOTDIR/defaults
cp -p /boot/loader $BOOTDIR
cp -p /boot/boot $BOOTDIR
cp -p /boot/mbr $BOOTDIR
cp -p /boot/cdboot $BOOTDIR
cp -p /boot/loader.rc $BOOTDIR
cp -p /boot/loader.4th $BOOTDIR
cp -p /boot/support.4th $BOOTDIR
cp -p /boot/device.hints $BOOTDIR
cp -p /sys/i386/compile/FREENAS/kernel.gz $BOOTDIR/kernel
echo 'mfsroot_load="YES"
mfsroot_type="mfs_root"
mfsroot_name="/mfsroot"
autoboot_delay="0"' > $BOOTDIR/loader.conf
return 0
}
add_libs() {
[ -f /tmp/lib.list ] && rm -f /tmp/lib.list
dirs=($FREENAS/bin $FREENAS/sbin $FREENAS/usr/bin $FREENAS/usr/sbin $FREENAS/usr/local/bin $FREENAS/usr/local/sbin)
for i in ${dirs[@]}; do
for file in $(ls $i); do
ldd -f "%p\n" $i/$file 2> /dev/null >> /tmp/lib.list
done
done
for i in $(sort -u /tmp/lib.list); do
cp -vp $i ${FREENAS}$(echo $i | rev | cut -d '/' -f 2- | rev)
done
rm -f /tmp/lib.list
return 0
}
add_web_gui(){
if [ ! -f "freenas-gui.tgz" ]; then
fetch http://www.freenas.org/downloads/freenas-gui.tgz
if [ ! $? ]; then
echo "Failed to fetch freenas-gui.tgz"
return 1
fi
fi
tar -xzf freenas-gui.tgz -C $FREENAS/usr/local
if [ $? ]; then
echo "Untarred GUI files successfully."
sleep 1
fi
return 0
}
create_mfsroot() {
cd /usr/local/freenas
[ -f mfsroot.gz ] && rm -f mfsroot.gz
# Setting Version type and date
date > $FREENAS/etc/version.buildtime
# Make mfsroot to be 32M
dd if=/dev/zero of=mfsroot bs=1M count=32
# Configure this file as a virtual disk
mdconfig -a -t vnode -f mfsroot -u 0
# Create Label on this disk
bsdlabel -w md0 auto
# format it as UFS
newfs -b 8192 -f 1024 -o space -m 0 /dev/md0c
mount /dev/md0c /mnt
cd /mnt
tar -cf - -C $FREENAS ./ | tar -xvpf -
cd $WORKINGDIR
umount /mnt
mdconfig -d -u 0
gzip -9 mfsroot
return 0
}
create_image() {
[ -f image.bin ] && rm -f image.bin
echo "Generating MFSROOT"
set FREENAS_PLATFORM="generic-pc"
create_mfsroot;;
echo "Creating a 16M disk image"
dd if=/dev/zero of=image.bin bs=1M count=16
mdconfig -a -t vnode -f image.bin -u 0
bsdlabel -w md0
# fdisk -BI -b $BOOTDIR/mbr md0 # apparently, this doesn't work
bsdlabel -w -B -b $BOOTDIR/mbr md0 auto
bsdlabel md0 > /tmp/label.freenas
bsdlabel md0 | grep -E "unused" | sed -e "s/c:/a:/" -e "s/unused/4.2BSD/" >> /tmp/label.freenas
bsdlabel -R -B md0 /tmp/label.freenas
rm /tmp/label.freenas
echo "Creating filesystem"
newfs -b 8192 -f 1024 -o space -m 0 /dev/md0a
mount /dev/md0a /mnt
mkdir -p /mnt/boot/kernel
mkdir /mnt/boot/defaults
echo "Copying boot and mfsroot files"
cp -p $BOOTDIR/kernel/kernel.gz /mnt/boot/kernel
cp mfsroot.gz /mnt
cp -p $BOOTDIR/boot /mnt/boot
cp -p $BOOTDIR/loader /mnt/boot
cp -p $BOOTDIR/loader.conf /mnt/boot
cp -p $BOOTDIR/loader.rc /mnt/boot
cp -p $BOOTDIR/device.hints /mnt/boot/
cp -p $BOOTDIR/support.4th /mnt/boot/
cp -p $BOOTDIR/loader.4th /mnt/boot/
cp -p $BOOTDIR/defaults/loader.conf /mnt/boot/defaults/
echo "Copying default config file"
mkdir /mnt/conf
cp -p $FREENAS/conf.default/config.xml /mnt/conf
umount /mnt
mdconfig -d -u 0
# gzip -9 image.bin
return 0
}
main() {
# Ensure we are in $WORKINGDIR
[ ! -d "$WORKINGDIR" ] && mkdir $WORKINGDIR
cd $WORKINGDIR
echo -n '
Menu:
1 - Create FreeNAS directory structure
2 - Copy FreeBSD binaries to FreeNAS filesystem
3 - Prepare FreeNAS /etc
4 - Build FreeNAS kernel
10 - Build and install PHP
11 - Build and install mini_httpd
12 - Build and install msntp
13 - Build and install ataidle
14 - Build and install vsftp
15 - Build and install samba
16 - Install NFS
17 - Build and install Netatalk
18 - Build and install Rsync
19 - Build and install SMART tools
20 - Build and install beep
30 - Build bootloader
31 - Add necessary libraries
32 - Add web GUI
41 - Create disk image
42 - Create ISO file
43 - Create light ISO (without disk image)
* - Quit
> '
read choice
case $choice in
1) create_fs;;
2) copy_bins;;
3) prep_etc;;
4) build_kernel;;
10) build_php;;
11) build_httpd;;
12) build_msntp;;
13) build_ataidle;;
14) build_vsftp;;
15) build_samba;;
16) install_nfs;;
17) build_netatalk;;
18) build_rsync;;
19) build_smarttools;;
20) build_beep;;
30) build_bootldr;;
31) add_libs;;
32) add_web_gui;;
41) create_image;;
42) Create ISO file;;
43) Create light ISO (without disk image);;
*) exit 0;;
esac
[ $? ] && echo "Success" || echo "Failure"
sleep 1
return 0
}
while true; do
main
done
exit 0
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.