build-freon 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. #!/bin/bash
  2. # Build linux system and generate ISO
  3. # Version: 0.5.0
  4. # (C) Chris Dorman, 2014-2020 - GPLv3+
  5. workdir=`pwd`
  6. freondir="/freon"
  7. corecount=25
  8. # Common mirror (now self hosted)
  9. mainmirror="https://mirror.freonlinux.com/source"
  10. # Download mirrors
  11. syslinuxmirror="https://www.kernel.org/pub/linux/utils/boot/syslinux"
  12. kernelmirror="https://cdn.kernel.org/pub/linux/kernel/v5.x"
  13. busyboxmirror="http://busybox.net/downloads"
  14. libcmirror="http://ftp.gnu.org/gnu/libc"
  15. grubmirror="http://alpha.gnu.org/gnu/grub"
  16. xzmirror="https://tukaani.org/xz"
  17. dropbearmirror="https://matt.ucc.asn.au/dropbear/releases"
  18. zlibmirror="https://zlib.net"
  19. # endtag used for iso filename, and some rootfs configs
  20. endtag=`date +"%Y%m%d-%H%M"`
  21. hostbuild="Debian 10"
  22. # Source code filenames
  23. kernel="linux-5.9.1.tar.xz"
  24. syslinux="syslinux-6.03.tar.gz"
  25. busybox="busybox-1.32.0.tar.bz2"
  26. libc="glibc-2.28.tar.xz"
  27. grub="grub-2.02~rc2.tar.xz"
  28. xz="xz-5.2.4.tar.xz"
  29. dropbear="dropbear-2019.78.tar.bz2"
  30. zlib="zlib-1.2.11.tar.xz"
  31. # Source directory names
  32. kerneldir=${kernel//.tar.xz}
  33. busyboxdir=${busybox//.tar.bz2}
  34. syslinuxdir=${syslinux//.tar.gz}
  35. libcdir=${libc//.tar.xz}
  36. grubdir=${grub//.tar.xz}
  37. xzdir=${xz//.tar.xz}
  38. dropbearsrcdir=${dropbear//.tar.bz2}
  39. zlibsrcdir=${zlib//.tar.xz}
  40. # Echo colors
  41. NORMAL="\e[0m"
  42. RED="\e[0;31m"
  43. GREEN="\e[0;32m"
  44. BLUE="\e[0;34m"
  45. YELLOW="\e[1;33m"
  46. MAGENTA="\e[0;35m"
  47. CYAN="\e[0;36m"
  48. # function to check if errors occurred
  49. status()
  50. {
  51. local CHECK=$?
  52. echo -en "\033[68G"
  53. if [ $CHECK = 0 ] ; then
  54. echo -e "[ \e[0;32mOK\e[0m ]"
  55. else
  56. echo -e "[ \e[0;31mFAILED\e[0m ]"
  57. exit 1
  58. fi
  59. }
  60. # same as above but doesn't output [ OK ]
  61. status_silent()
  62. {
  63. local CHECK=$?
  64. echo -en "\033[68G"
  65. if [ $CHECK != 0 ] ; then
  66. echo -e "[ \e[0;31mFAILED\e[0m ]"
  67. exit 1
  68. fi
  69. }
  70. if [ "$(id -u)" != "0" ]; then
  71. echo -e "[$RED Error $NORMAL] This script needs to be executed by root."
  72. exit 1
  73. fi
  74. if [ ! -d "src" ]; then
  75. echo -e "[$YELLOW Warning $NORMAL] No source directory!"
  76. echo -n "Creating source directory..."
  77. mkdir src > /dev/null 2>&1
  78. status
  79. fi
  80. # check to see if source dir exists, if not create
  81. if [ ! -d src ]; then
  82. mkdir src
  83. status_silent
  84. fi
  85. # if called, print everything instead of hiding. Debugging purposes
  86. case $2 in
  87. --verbose|-v) verbose=1;;
  88. *) verbose=0;
  89. esac
  90. # Download source code
  91. get_files()
  92. {
  93. cd $workdir/src
  94. if [ -d "rootfs" ]; then
  95. echo -e "[$YELLOW Warning $NORMAL] Rootfs tree still exists."
  96. echo -n "Cleaning build tree..."
  97. rm -r rootfs > /dev/null 2>&1
  98. status
  99. fi
  100. #echo " " # This is used to keep next echo from moving around
  101. echo -e "[$YELLOW Working $NORMAL] Downloading needed files..."
  102. if [ ! -f $kernel ]; then
  103. echo -n "$kernel..."
  104. wget $mainmirror/$kernel > /dev/null 2>&1
  105. status
  106. fi
  107. if [ ! -f $busybox ]; then
  108. echo -n "$busybox..."
  109. wget $mainmirror/$busybox > /dev/null 2>&1
  110. status
  111. fi
  112. if [ ! -f $syslinux ]; then
  113. echo -n "$syslinux..."
  114. wget $mainmirror/$syslinux > /dev/null 2>&1
  115. status
  116. fi
  117. if [ ! -f $xz ]; then
  118. echo -n "$xz..."
  119. wget $mainmirror/$xz > /dev/null 2>&1
  120. status
  121. fi
  122. if [ ! -f $libc ]; then
  123. echo -n "$libc..."
  124. wget $mainmirror/$libc > /dev/null 2>&1
  125. status
  126. fi
  127. if [ ! -f $grub ]; then
  128. echo -n "$grub..."
  129. wget $mainmirror/$grub > /dev/null 2>&1
  130. status
  131. fi
  132. }
  133. # Build linux kernel
  134. do_kernel()
  135. {
  136. cd $workdir/src
  137. echo -e "[$YELLOW Working $NORMAL] Configuring & building Linux kernel"
  138. if [ ! -d $kerneldir ]; then
  139. echo -n "Unpacking..."
  140. tar xf $kernel > /dev/null 2>&1
  141. status
  142. fi
  143. echo -n "Configuring..."
  144. cd $kerneldir
  145. cp ../../files/$kerneldir.conf .config
  146. status
  147. echo -n "Building kernel base..."
  148. if [ "$verbose" == "1" ]; then
  149. make bzImage -j$corecount
  150. status
  151. else
  152. make bzImage -j$corecount > /dev/null 2>&1
  153. status
  154. fi
  155. #echo -n "Building kernel modules..."
  156. #if [ "$verbose" == "1" ]; then
  157. # make modules -j20
  158. # status
  159. #else
  160. # make modules -j20 > /dev/null 2>&1
  161. # status
  162. #fi
  163. #echo -n "Installing kernel modules..."
  164. #make INSTALL_MOD_PATH=`pwd`/_pkg modules_install > /dev/null 2>&1
  165. #status
  166. echo -n "Installing kernel headers..."
  167. make INSTALL_HDR_PATH=`pwd`/_hdr headers_install > /dev/null 2>&1
  168. status
  169. cd ..
  170. }
  171. # Build busybox
  172. do_base()
  173. {
  174. echo -e "[$YELLOW Working $NORMAL] Configuring & building system utilities"
  175. cd $workdir/src
  176. if [ ! -d $busyboxdir ]; then
  177. echo -n "Unpacking..."
  178. tar xf $busybox > /dev/null 2>&1
  179. status
  180. fi
  181. echo -n "Configuring..."
  182. cd $busyboxdir
  183. cp ../../files/$busyboxdir.conf .config
  184. status_silent
  185. make oldconfig > /dev/null 2>&1
  186. status
  187. echo -n "Building..."
  188. if [ "$verbose" == "1" ]; then
  189. make -j$corecount
  190. status
  191. else
  192. make -j$corecount > /dev/null 2>&1
  193. status
  194. fi
  195. if [ "$verbose" == "1" ]; then
  196. make install
  197. status
  198. else
  199. make install > /dev/null 2>&1
  200. status
  201. fi
  202. echo -n "Finishing up..."
  203. chmod 4755 _install/bin/busybox
  204. cp -a _install/* /freon
  205. status
  206. cd $workdir
  207. cd system/ii
  208. make -j$corecount; make install
  209. status_silent
  210. cd ../chttpd
  211. cp inc/chttpd ../../rootfs/etc/init.d/chttpd
  212. make -j$corecount; make install
  213. status_silent
  214. cd ../sic
  215. make -j$corecount; make install
  216. status_silent
  217. cd $workdir
  218. }
  219. # Build system wide dependencies
  220. do_libc()
  221. {
  222. echo -e "[$YELLOW Working $NORMAL] Configuring & building libc"
  223. cd $workdir/src
  224. if [ ! -d $libcdir ]; then
  225. echo "Unpacking..."
  226. tar xf $libc > /dev/null 2>&1
  227. status
  228. fi
  229. if [ ! -d rootfs ]; then
  230. mkdir rootfs
  231. cd rootfs/
  232. echo -n "Laying out filesystem tree..."
  233. mkdir -p dev root etc home proc media mnt sys tmp var
  234. mkdir -p usr/{lib,local,share,games} \
  235. var/{cache,lib,lock,log,games,run,spool,www} \
  236. media/{cdrom,flash,usbdisk} \
  237. etc/{init.d,conf.d}
  238. cd ..
  239. fi
  240. if [ ! -d $libcdir-build ]; then
  241. mkdir $libcdir-build
  242. fi
  243. if [ ! -d /freon/lib ]; then
  244. mkdir /freon/lib
  245. fi
  246. cd $libcdir-build
  247. echo -n "Configuring..."
  248. if [ "$verbose" == "1" ]; then
  249. `pwd`/../$libcdir/configure \
  250. --prefix=$freondir \
  251. --build=$MACHTYPE \
  252. --host=x86_64-linux \
  253. --target=x86_64-linux
  254. --with-headers=_hdr/include
  255. status
  256. else
  257. `pwd`/../$libcdir/configure \
  258. --prefix=/freon \
  259. --build=$MACHTYPE \
  260. --host=x86_64-linux \
  261. --target=x86_64-linux > /dev/null 2>&1
  262. --with-headers=_hdr/include > /dev/null 2>&1
  263. status
  264. fi
  265. echo -n "Building..."
  266. if [ "$verbose" == "1" ]; then
  267. make install-bootstrap-headers=yes install-headers
  268. status
  269. make -j$corecount csu/subdir_lib
  270. status
  271. install csu/crt1.o csu/crti.o csu/crtn.o /freon/lib
  272. status
  273. gcc \
  274. -nostdlib \
  275. -nostartfiles -shared -x c /dev/null -o $freondir/lib/libc.so
  276. status
  277. make -j$corecount
  278. status
  279. else
  280. make install-bootstrap-headers=yes install-headers > /dev/null 2>&1
  281. status_silent
  282. make -j$corecount csu/subdir_lib > /dev/null 2>&1
  283. status_silent
  284. install csu/crt1.o csu/crti.o csu/crtn.o $freondir/lib > /dev/null 2>&1
  285. status_silent
  286. gcc \
  287. -nostdlib \
  288. -nostartfiles -shared -x c /dev/null -o $freondir/lib/libc.so 2>&1
  289. status_silent
  290. make -j$corecount > /dev/null 2>&1
  291. status
  292. fi
  293. echo -n "Copying to rootfs..."
  294. if [ "$verbose" == "1" ]; then
  295. make install
  296. status
  297. else
  298. make install > /dev/null 2>&1
  299. status
  300. fi
  301. echo -n "Cleaning files..."
  302. #strip -v lib/* > /dev/null 2>&1
  303. mkdir $workdir/src/rootfs/lib64
  304. cd $workdir/src/rootfs/lib64
  305. ln -s $freondir/lib/ld-2.28.so ld-linux-x86-64.so.2
  306. status
  307. cd $freondir
  308. if [ ! -d "lib64" ]; then
  309. mkdir lib64
  310. fi
  311. cd lib64
  312. ln -s $freondir/lib/ld-2.28.so ld-linux-x86-64.so.2
  313. cd $workdir
  314. }
  315. # Build grub legacy bootloader and install
  316. do_grub()
  317. {
  318. echo -e "[$YELLOW Working $NORMAL] Configuring & building bootloader"
  319. cd $workdir/src
  320. echo -n "Extracting..."
  321. if [ ! -d "$xzdir" ]; then
  322. tar xf $xz > /dev/null 2>&1
  323. status_silent
  324. fi
  325. if [ ! -d "$grubdir" ]; then
  326. tar xf $grub > /dev/null 2>&1
  327. status
  328. fi
  329. cd $grubdir
  330. echo -n "Configuring..."
  331. ./configure --prefix=`pwd`/../rootfs \
  332. --disable-efiemu \
  333. --disable-werror > /dev/null 2>&1
  334. status_silent
  335. cd ../$xzdir
  336. ./configure --prefix=`pwd`/../rootfs \
  337. --disable-static > /dev/null 2>&1
  338. status
  339. cd ../$grubdir
  340. echo -n "Compiling..."
  341. make -j$corecount > /dev/null 2>&1
  342. status_silent
  343. cd ../$xzdir
  344. make -j$corecount > /dev/null 2>&1
  345. status
  346. cd ../$grubdir
  347. echo -n "Copying to rootfs..."
  348. make install > /dev/null 2>&1
  349. status_silent
  350. cd ../$xzdir
  351. make install > /dev/null 2>&1
  352. status
  353. cd ../$grubdir
  354. echo -n "Installing patched grub-mkconfig..."
  355. rm ../rootfs/sbin/grub-mkconfig > /dev/null 2>&1
  356. status_silent
  357. cp ../../files/sbin/grub-mkconfig ../rootfs/sbin > /dev/null 2>&1
  358. status
  359. cd ../rootfs
  360. #echo -n "Stripping grub..."
  361. #strip -s rootfs/bin/grub-* > /dev/null 2>&1
  362. #strip -s rootfs/sbin/grub-* > /dev/null 2>&1
  363. cd ..
  364. #status
  365. }
  366. # Install Freon utilities
  367. do_utilities() {
  368. echo -e "[$YELLOW Working $NORMAL] Installing Freon utilities"
  369. echo -n "Copying files..."
  370. cd $workdir/src
  371. cp -a ../files/bin/* rootfs/bin
  372. status
  373. }
  374. # Configure rootfs for live boot
  375. configure_system()
  376. {
  377. echo -e "[$YELLOW Working $NORMAL] Configuring root filesystem"
  378. echo -n "Linking init..."
  379. cd $workdir/src/rootfs
  380. if [ -f linuxrc ]; then
  381. rm linuxrc
  382. fi
  383. if [ ! -f init ]; then
  384. ln -s $freondir/bin/busybox init
  385. fi
  386. status
  387. echo -n "Filling /dev..."
  388. cp ../../files/bin/mkdevs $freondir/bin/mkdevs
  389. $freondir/bin/mkdevs dev > /dev/null 2>&1
  390. status
  391. echo -n "Configuring networking..."
  392. echo "127.0.0.1 localhost" > etc/hosts
  393. echo "localhost 127.0.0.1" > etc/networks
  394. echo "linux" > etc/hostname
  395. echo "order hosts,bind" > etc/host.conf
  396. echo "multi on" >> etc/host.conf
  397. mkdir etc/network
  398. mkdir etc/network/if-up.d
  399. mkdir etc/network/if-down.d
  400. mkdir etc/network/if-pre-up.d
  401. mkdir etc/network/if-post-down.d
  402. echo "# loopback
  403. auto lo
  404. iface lo inet loopback
  405. # Ethernet // this is default and can be changed for per system
  406. auto eth0
  407. iface eth0 inet dhcp
  408. " > etc/network/interfaces
  409. echo "
  410. # /etc/nsswitch.conf: GNU Name Service Switch config.
  411. #
  412. passwd: files
  413. group: files
  414. shadow: files
  415. hosts: files dns
  416. networks: files
  417. " > etc/nsswitch.conf
  418. status
  419. echo -n "Setting up default users and groups..."
  420. echo "root:x:0:0:root:/root:/bin/sh" > etc/passwd
  421. echo "root::13525:0:99999:7:::" > etc/shadow
  422. echo "root:x:0:" > etc/group
  423. echo "root:*::" > etc/gshadow
  424. chmod 640 etc/shadow
  425. chmod 640 etc/gshadow
  426. status
  427. #echo -n "Copying kernel modules..."
  428. #cp -a ../$kerneldir/_pkg/* .
  429. #status
  430. #echo -n "Copying kernel headers..."
  431. #cp -a ../$kerneldir/_hdr/* .
  432. #status
  433. echo -n "Compiling termtypes for core terminfo...."
  434. tic -o ./usr/share/terminfo ../../files/terminfo/termtypes > /dev/null 2>&1
  435. status
  436. echo -n "Finishing up..."
  437. echo "# /etc/securetty: List of terminals on which root is allowed to login.
  438. #
  439. console
  440. # For people with serial port consoles
  441. ttyS0
  442. # Standard consoles
  443. tty1
  444. tty2
  445. tty3
  446. tty4
  447. tty5
  448. tty6
  449. tty7" > etc/securetty
  450. echo "/bin/sh" > etc/shells
  451. echo "/bin/ash" >> etc/shells
  452. echo "Freon Linux $endtag \r \l" > etc/issue
  453. echo "" >> etc/issue
  454. echo "Welcome to
  455. _________
  456. ___ ____/________________________
  457. __ /_ __ ___/ _ \\ __ \\_ __ \\
  458. _ __/ _ / / __/ /_/ / / / /
  459. /_/ /_/ \\___/\\____//_/ /_/
  460. Compiled $endtag using $hostbuild" > etc/motd
  461. echo "[SUID]
  462. # Allow command to be run by anyone.
  463. su = ssx root.root
  464. passwd = ssx root.root
  465. loadkmap = ssx root.root
  466. mount = ssx root.root
  467. reboot = ssx root.root
  468. halt = ssx root.root" > etc/busybox.conf
  469. chmod 600 etc/busybox.conf
  470. echo "::sysinit:/etc/init.d/rc.init
  471. ::respawn:-/bin/sh
  472. tty2::askfirst:-/bin/sh
  473. ::ctrlaltdel:/bin/umount -a -r
  474. ::ctrlaltdel:/sbin/reboot" > etc/inittab
  475. echo "# /etc/profile: system-wide .profile file for the Bourne shells
  476. PATH=\"/freon/bin:/freon/sbin:/freon/usr/bin:/freon/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin\"
  477. LD_LIBRARY_PATH=\"/freon/lib:/freon/lib64:/freon/usr/lib:/lib64:/usr/lib:/lib:/usr/local/lib\"
  478. TERM=\"xterm\"
  479. TERMINFO=\"/share/terminfo\"
  480. NORMAL=\"\\[\\e[0m\\]\"
  481. RED=\"\\[\\e[0;31m\\]\"
  482. GREEN=\"\\[\\e[0;32m\\]\"
  483. BLUE=\"\\[\\e[0;34m\\]\"
  484. YELLOW=\"\\[\\e[1;33m\\]\"
  485. MAGENTA=\"\\[\\e[0;35m\\]\"
  486. CYAN=\"\\[\\e[0;36m\\]\"
  487. if [ \"\`id -u\`\" -eq 0 ]; then
  488. PS1=\"$RED\\u$GREEN@$BLUE\\h [ $MAGENTA\\w$BLUE ]# \$NORMAL\"
  489. else
  490. PS1=\"$RED\\u$GREEN@$BLUE\\h [ $MAGENTA\\w$BLUE ]\\\$ \$NORMAL\"
  491. fi
  492. export PATH LD_LIBRARY_PATH PS1 DISPLAY ignoreeof
  493. umask 022
  494. export G_FILENAME_ENCODING=iso8859-1
  495. " > etc/profile
  496. echo "proc /proc proc defaults 0 0
  497. sysfs /sys sysfs defaults 0 0
  498. devpts /dev/pts devpts defaults 0 0
  499. tmpfs /dev/shm tmpfs defaults 0 0" > etc/fstab
  500. cp -a $workdir/files/etc/* etc
  501. cd share
  502. mkdir kmap
  503. cp -a $workdir/files/share/* .
  504. status_silent
  505. chmod +x udhcpc/default.script
  506. status_silent
  507. cd ../usr/share
  508. ln -s /share/udhcpc udhcpc
  509. cd ../..
  510. # mkdir x86_64-linux-gnu
  511. # cd x86_64-linux-gnu
  512. # ln -s ../libm-2.22.so libm.so.6
  513. # ln -s ../libc-2.22.so libc.so.6
  514. status
  515. cd $workdir
  516. }
  517. # generate initramfs for live boot.
  518. gen_rootfs()
  519. {
  520. echo -e "[$YELLOW Working $NORMAL] Generating filesystem..."
  521. cd $workdir/src/rootfs
  522. cp -a $freondir .
  523. cd bin
  524. for f in /freon/bin/*; do
  525. ln -s $f .
  526. done
  527. cd ../sbin
  528. for f in /freon/sbin/*; do
  529. ln -s $f .
  530. done
  531. cd ../lib
  532. for l in /freon/lib/*.so; do
  533. ln -nsf $l .
  534. done
  535. for l in /freon/lib/*.so*; do
  536. ln -nsf $l .
  537. done
  538. for l in /freon/lib/*.o; do
  539. ln -nsf $l .
  540. done
  541. cd ..
  542. echo -n "Stripping build..."
  543. strip -s freon/lib/*.so > /dev/null 2>&1
  544. strip -s freon/lib/*.so* > /dev/null 2>&1
  545. strip -s freon/bin/busybox > /dev/null 2>&1
  546. strip -s freon/sbin/chttpd > /dev/null 2>&1
  547. rm freon/lib/*.a
  548. rm lib/*.a # In base-dev package
  549. rm usr/lib/*.a
  550. echo "#!/bin/sh
  551. exec /freon/bin/sh \$*" > bin/bash
  552. chmod +x bin/bash
  553. echo -n "Compressing filesystem..."
  554. find . -print | cpio -o -H newc | gzip -9 > ../rootfs.gz 2>&1
  555. status
  556. cd $workdir
  557. }
  558. regen_rootfs_bare()
  559. {
  560. echo -e "[$YELLOW Working $NORMAL] Generating filesystem..."
  561. cd $workdir/src/rootfs
  562. cp -a $freondir .
  563. echo -n "Compressing filesystem..."
  564. find . -print | cpio -o -H newc | gzip -9 > ../rootfs.gz 2>&1
  565. status
  566. cd $workdir
  567. }
  568. # setup bootloader for iso
  569. do_isolinux()
  570. {
  571. echo -e "[$YELLOW Working $NORMAL] Setting up bootloader."
  572. cd $workdir/src/
  573. if [ ! -d $syslinuxdir ]; then
  574. echo -n "Unpacking $syslinuxdir..."
  575. tar -xzf $syslinux > /dev/null 2>&1
  576. status
  577. fi
  578. if [ ! -d cdroot ]; then
  579. mkdir cdroot
  580. mkdir cdroot/boot
  581. fi
  582. cd $syslinuxdir
  583. echo -n "Copying isolinux files to iso..."
  584. cp bios/core/isolinux.bin ../cdroot
  585. cp bios/com32/elflink/ldlinux/ldlinux.c32 ../cdroot
  586. status
  587. echo -n "Generating isolinux config..."
  588. echo "Freon Linux $endtag
  589. Press <enter> to boot" > ../cdroot/display.txt
  590. echo "display display.txt
  591. default Freon
  592. label Freon
  593. kernel /boot/bzImage
  594. append initrd=/boot/rootfs.gz rw root=/dev/null vga=788
  595. implicit 0
  596. prompt 1
  597. timeout 5" > ../cdroot/isolinux.cfg
  598. status
  599. cd $workdir
  600. }
  601. # generate complete iso ready for boot
  602. gen_iso()
  603. {
  604. echo -e -n "[$YELLOW Working $NORMAL] Generating bootable ISO image."
  605. cd $workdir/src
  606. cp rootfs.gz cdroot/boot
  607. cp $kerneldir/arch/x86/boot/bzImage cdroot/boot/bzImage
  608. genisoimage -R -o ../freon-$endtag.iso -b isolinux.bin \
  609. -c boot.cat -no-emul-boot -boot-load-size 4 \
  610. -V "Freon Linux" -input-charset iso8859-1 -boot-info-table cdroot > /dev/null 2>&1
  611. status
  612. }
  613. do_refer()
  614. {
  615. echo -e "[$YELLOW Working $NORMAL] Reconfiguring root filesystem"
  616. cd $workdir/src/rootfs
  617. rm etc/init.d/*
  618. rm etc/conf.d/*
  619. cp -av ../../files/etc/* etc/ # Copy files/etc to filesystem (init scripts)
  620. cp -av ../../files/bin/* bin/ # Copy installer and package manager
  621. cp -av ../../files/share/* share/ # Stuffs
  622. cd $workdir
  623. }
  624. do_dropbear()
  625. {
  626. cd $workdir/src
  627. # Downloading dropbear source
  628. if [ ! -f "$dropbear" ]; then
  629. echo "Downloading Dropbear sources..."
  630. wget $dropbearmirror/$dropbear
  631. tar -xf $dropbear
  632. fi
  633. # Configure dropbear
  634. cd $dropbearsrcdir
  635. cp -v options.h options.h.backup
  636. sed -e "s@/dev/random@/dev/urandom@" options.h.backup > options.h
  637. ./configure --prefix=$workdir/src/rootfs
  638. # Compile
  639. make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1
  640. make MULTI=1 PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
  641. mkdir -pv $workdir/src/rootfs/etc/dropbear
  642. rm $workdir/src/rootfs/sbin/dropbear
  643. rm $workdir/src/rootfs/bin/{dropbearconvert,dropbearkey,scp,dbclient}
  644. cd $workdir/src/rootfs/bin
  645. ln -svf dropbearmulti dropbear
  646. ln -svf dropbearmulti dbclient
  647. ln -svf dropbearmulti dropbearkey
  648. ln -svf dropbearmulti dropbearconvert
  649. ln -svf dropbearmulti scp
  650. cd $workdir
  651. }
  652. do_zlib()
  653. {
  654. cd $workdir/src
  655. # Downloading zlib source
  656. if [ ! -f "$zlib" ]; then
  657. echo "Downloading zlib sources..."
  658. wget $zlibmirror/$zlib
  659. tar -xf $zlib
  660. fi
  661. # Confingure
  662. cd $zlibsrcdir
  663. ./configure --prefix=$freondir
  664. # Compile
  665. make -j$corecount
  666. make install
  667. # mv -v ../../src/rootfs/usr/lib/libz.so.* ../../src/rootfs/lib
  668. # ln -sfv ../../src/rootfs/lib/libz.so ../../src/rootfs/usr/lib/libz.so
  669. cd $workdir
  670. }
  671. case $1 in
  672. rootfs) get_files; do_libc; do_base; do_grub; do_zlib; do_dropbear; do_kernel; configure_system; do_utilities;;
  673. refer) do_refer; regen_rootfs_bare; do_isolinux; gen_iso;;
  674. full) get_files; do_libc; do_base; do_grub; do_zlib; do_dropbear; do_kernel; configure_system; do_utilities; gen_rootfs; do_isolinux; gen_iso;;
  675. *) echo "Unknown argument: ./build-freon [full|refer|rootfs]";;
  676. esac