build-planck 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. #!/bin/bash
  2. # Build planck linux system and generate ISO
  3. # Version: 0.0.1
  4. # (C) Chris Dorman, 2020-2021 - GPLv3+
  5. workdir=`pwd`
  6. rootdir="/planck"
  7. corecount=25
  8. # endtag used for iso filename, and some rootfs configs
  9. endtag=`date +"%Y%m%d-%H%M"`
  10. # Echo colors
  11. NORMAL="\e[0m"
  12. RED="\e[0;31m"
  13. GREEN="\e[0;32m"
  14. BLUE="\e[0;34m"
  15. YELLOW="\e[1;33m"
  16. MAGENTA="\e[0;35m"
  17. CYAN="\e[0;36m"
  18. # function to check if errors occurred
  19. status()
  20. {
  21. local CHECK=$?
  22. echo -en "\033[68G"
  23. if [ $CHECK = 0 ] ; then
  24. echo -e "[ \e[0;32mOK\e[0m ]"
  25. else
  26. echo -e "[ \e[0;31mFAILED\e[0m ]"
  27. exit 1
  28. fi
  29. }
  30. # same as above but doesn't output [ OK ]
  31. status_silent()
  32. {
  33. local CHECK=$?
  34. echo -en "\033[68G"
  35. if [ $CHECK != 0 ] ; then
  36. echo -e "[ \e[0;31mFAILED\e[0m ]"
  37. exit 1
  38. fi
  39. }
  40. if [ "$(id -u)" != "0" ]; then
  41. echo -e "[$RED Error $NORMAL] This script needs to be executed by root."
  42. exit 1
  43. fi
  44. if [ -d $rootdir ]; then
  45. rm -r $rootdir
  46. fi
  47. if [ -d $workdir/src/rootfs ]; then
  48. rm -r $workdir/src/rootfs
  49. fi
  50. # if called, print everything instead of hiding. Debugging purposes
  51. case $2 in
  52. --verbose|-v) verbose=1;;
  53. *) verbose=0;
  54. esac
  55. # Build linux kernel
  56. do_kernel()
  57. {
  58. echo -e "[$YELLOW Working $NORMAL] Configuring & building Linux kernel"
  59. cd $workdir/src/linux-*
  60. status
  61. echo -n "Configuring..."
  62. cp ../../cfg/linux-*.conf .config
  63. status
  64. echo -n "Building kernel base..."
  65. if [ "$verbose" == "1" ]; then
  66. make bzImage -j$corecount
  67. status
  68. else
  69. make bzImage -j$corecount > /dev/null 2>&1
  70. status
  71. fi
  72. #echo -n "Building kernel modules..."
  73. #if [ "$verbose" == "1" ]; then
  74. # make modules -j20
  75. # status
  76. #else
  77. # make modules -j20 > /dev/null 2>&1
  78. # status
  79. #fi
  80. #echo -n "Installing kernel modules..."
  81. #make INSTALL_MOD_PATH=`pwd`/_pkg modules_install > /dev/null 2>&1
  82. #status
  83. echo -n "Installing kernel headers..."
  84. make INSTALL_HDR_PATH=$rootdir headers_install > /dev/null 2>&1
  85. status
  86. cd ..
  87. }
  88. # Build musl-libc for compiler wrapping and OS dependencies
  89. do_musl()
  90. {
  91. #Building musl for planck linux
  92. echo -e "[$YELLOW Working $NORMAL] Configuring & building musl-libc"
  93. cd $workdir/src
  94. cd musl
  95. echo -n "Building musl..."
  96. if [ "$verbose" == "1" ]; then
  97. ./configure --prefix=$rootdir
  98. silent_status
  99. make -j$corecount
  100. status_silent
  101. make install
  102. status
  103. else
  104. ./configure --prefix=$rootdir > /dev/null 2>&1
  105. status_silent
  106. make -j$corecount > /dev/null 2>&1
  107. status_silent
  108. make install > /dev/null 2>&1
  109. status
  110. fi
  111. cd ../..
  112. #cp -a linux-headers/include $rootdir/.
  113. export PATH=$PATH:$rootdir/bin
  114. }
  115. # Build base system
  116. do_base()
  117. {
  118. echo -e "[$YELLOW Working $NORMAL] Configuring & building system utilities"
  119. cd $workdir/src
  120. #BUILD PACKAGE: sbase
  121. cd sbase
  122. echo -n "Building sbase..."
  123. if [ "$verbose" == "1" ]; then
  124. make -j$corecount
  125. status_silent
  126. make install
  127. status
  128. else
  129. make -j$corecount > /dev/null 2>&1
  130. status_silent
  131. make install > /dev/null 2>&1
  132. status
  133. fi
  134. cd ..
  135. cd ubase
  136. echo -n "Building ubase..."
  137. if [ "$verbose" == "1" ]; then
  138. make -j$corecount
  139. status_silent
  140. make install
  141. status
  142. else
  143. make -j$corecount > /dev/null 2>&1
  144. status_silent
  145. make install > /dev/null 2>&1
  146. status
  147. fi
  148. cd ..
  149. cd sinit
  150. echo -n "Building sinit..."
  151. if [ "$verbose" == "1" ]; then
  152. make -j$corecount
  153. status_silent
  154. make install
  155. status
  156. else
  157. make -j$corecount > /dev/null 2>&1
  158. status_silent
  159. make install > /dev/null 2>&1
  160. status
  161. fi
  162. cd ..
  163. cd sdhcp
  164. echo -n "Building sdhcp..."
  165. if [ "$verbose" == "1" ]; then
  166. make -j$corecount
  167. status_silent
  168. make install
  169. status
  170. else
  171. make -j$corecount > /dev/null 2>&1
  172. status_silent
  173. make install > /dev/null 2>&1
  174. status
  175. fi
  176. cd ..
  177. cd smdev
  178. echo -n "Building smdev..."
  179. if [ "$verbose" == "1" ]; then
  180. make -j$corecount
  181. status_silent
  182. make install
  183. status
  184. else
  185. make -j$corecount > /dev/null 2>&1
  186. status_silent
  187. make install > /dev/null 2>&1
  188. status
  189. fi
  190. cd ..
  191. cd dish
  192. echo -n "Building dash..."
  193. if [ "$verbose" == "1" ]; then
  194. make -j$corecount
  195. status_silent
  196. make install
  197. status
  198. else
  199. make -j$corecount > /dev/null 2>&1
  200. status_silent
  201. make install > /dev/null 2>&1
  202. status
  203. fi
  204. cd $workdir/src
  205. cd tcc
  206. echo -n "Building tcc..."
  207. if [ "$verbose" == "1" ]; then
  208. ./configure --prefix=$rootdir --crtprefix=$rootdir/lib --cc=musl-gcc --elfinterp=$rootdir/lib/libc.so --sysincludepaths=$rootdir/include --libpaths=$rootdir/lib --config-bcheck=no --config-musl=yes
  209. status_silent
  210. make -j$corecount
  211. status_silent
  212. make install
  213. status
  214. else
  215. ./configure --prefix=$rootdir --crtprefix=$rootdir/lib --cc=musl-gcc --elfinterp=$rootdir/lib/libc.so --sysincludepaths=$rootdir/include --libpaths=$rootdir/lib --config-bcheck=no --config-musl=yes> /dev/null 2>&1
  216. status_silent
  217. make -j$corecount > /dev/null 2>&1
  218. status_silent
  219. make install > /dev/null 2>&1
  220. status
  221. fi
  222. cd ..
  223. cd texor
  224. echo -n "Building texor..."
  225. if [ "$verbose" == "1" ]; then
  226. make -j$corecount
  227. status_silent
  228. cp texor $rootdir/bin/.
  229. status
  230. else
  231. make -j$corecount > /dev/null 2>&1
  232. status_silent
  233. cp texor $rootdir/bin/. > /dev/null 2>&1
  234. status
  235. fi
  236. cd ..
  237. cd wgetlite
  238. echo -n "Building wgetlite..."
  239. if [ "$verbose" == "1" ]; then
  240. CC=musl-gcc
  241. make -j$corecount
  242. status_silent
  243. cp wgetlite $rootdir/bin/wget
  244. status
  245. else
  246. CC=musl-gcc
  247. make -j$corecount > /dev/null 2>&1
  248. status_silent
  249. cp wgetlite $rootdir/bin/wget > /dev/null 2>&1
  250. status
  251. fi
  252. cd ..
  253. # END PACKAGE BUILD
  254. # Link libc.so musl linker
  255. cd $rootdir
  256. cd lib
  257. ln -s libc.so ld-musl-x86_64.so.1
  258. cd $workdir/src
  259. }
  260. # Configure rootfs for live boot
  261. configure_system()
  262. {
  263. echo -e "[$YELLOW Working $NORMAL] Configuring root filesystem"
  264. if [ ! -d $workdir/src/rootfs ]; then
  265. mkdir $workdir/src/rootfs
  266. fi
  267. if [ ! -d $rootdir/dev ]; then
  268. mkdir $rootdir/dev
  269. fi
  270. cd $workdir/src/rootfs
  271. echo -n "Filling /dev..."
  272. cp ../../cfg/mkdevs $rootdir/bin/mkdevs
  273. $rootdir/bin/mkdevs $rootdir/dev > /dev/null 2>&1
  274. cp -a $rootdir .
  275. status_silent
  276. ln -s planck/dev dev
  277. status
  278. cd planck
  279. if [ ! -d etc ]; then
  280. mkdir etc
  281. fi
  282. echo -n "Configuring networking..."
  283. echo "127.0.0.1 localhost" > etc/hosts
  284. echo "localhost 127.0.0.1" > etc/networks
  285. echo "linux" > etc/hostname
  286. echo "order hosts,bind" > etc/host.conf
  287. echo "multi on" >> etc/host.conf
  288. status
  289. echo -n "Setting up default users and groups..."
  290. echo "root:x:0:0:root:/root:/bin/sh" > etc/passwd
  291. echo "root::13525:0:99999:7:::" > etc/shadow
  292. echo "root:x:0:" > etc/group
  293. echo "root:*::" > etc/gshadow
  294. chmod 640 etc/shadow
  295. chmod 640 etc/gshadow
  296. status
  297. #echo -n "Copying kernel modules..."
  298. #cp -a ../$kerneldir/_pkg/* .
  299. #status
  300. #echo -n "Copying kernel headers..."
  301. #cp -a ../$kerneldir/_hdr/* .
  302. #status
  303. echo -n "Compiling termtypes for core terminfo...."
  304. tic -o ./share/terminfo ../../../cfg/terminfo/termtypes > /dev/null 2>&1
  305. status
  306. echo -n "Finishing up..."
  307. echo "# /etc/securetty: List of terminals on which root is allowed to login.
  308. #
  309. console
  310. # For people with serial port consoles
  311. ttyS0
  312. # Standard consoles
  313. tty1
  314. tty2
  315. tty3
  316. tty4
  317. tty5
  318. tty6
  319. tty7" > etc/securetty
  320. echo "/bin/sh" > etc/shells
  321. echo "/bin/dash" >> etc/shells
  322. echo "Planck Linux\r \l" > etc/issue
  323. echo "" >> etc/issue
  324. echo "proc /proc proc defaults 0 0
  325. sysfs /sys sysfs defaults 0 0
  326. devpts /dev/pts devpts defaults 0 0
  327. tmpfs /dev/shm tmpfs defaults 0 0" > etc/fstab
  328. echo "Welcome to
  329. ______________ ______
  330. ___ __ \\__ /_____ ________________ /__
  331. __ /_/ /_ /_ __ \`/_ __ \\ ___/_ //_/
  332. _ ____/_ / / /_/ /_ / / / /__ _ ,<
  333. /_/ /_/ \\__,_/ /_/ /_/\\___/ /_/|_|
  334. Linux - With no GNU libraries!
  335. " > etc/motd
  336. echo "[SUID]
  337. # Allow command to be run by anyone.
  338. su = ssx root.root
  339. passwd = ssx root.root
  340. loadkmap = ssx root.root
  341. mount = ssx root.root
  342. reboot = ssx root.root
  343. halt = ssx root.root" > etc/busybox.conf
  344. echo "# /etc/profile: system-wide .profile file for the Bourne shells
  345. PATH=\"/freon/bin:/freon/sbin:/freon/usr/bin:/freon/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/sbin\"
  346. LD_LIBRARY_PATH=\"/freon/lib:/freon/lib64:/freon/usr/lib:/lib64:/usr/lib:/lib:/usr/local/lib\"
  347. TERM=\"xterm\"
  348. TERMINFO=\"/share/terminfo\"
  349. NORMAL=\"\\[\\e[0m\\]\"
  350. RED=\"\\[\\e[0;31m\\]\"
  351. GREEN=\"\\[\\e[0;32m\\]\"
  352. BLUE=\"\\[\\e[0;34m\\]\"
  353. YELLOW=\"\\[\\e[1;33m\\]\"
  354. MAGENTA=\"\\[\\e[0;35m\\]\"
  355. CYAN=\"\\[\\e[0;36m\\]\"
  356. if [ \"\`id -u\`\" -eq 0 ]; then
  357. PS1=\"$RED\\u$GREEN@$BLUE\\h [ $MAGENTA\\w$BLUE ]# \$NORMAL\"
  358. else
  359. PS1=\"$RED\\u$GREEN@$BLUE\\h [ $MAGENTA\\w$BLUE ]\\\$ \$NORMAL\"
  360. fi
  361. export PATH LD_LIBRARY_PATH PS1 DISPLAY ignoreeof
  362. umask 022
  363. export G_FILENAME_ENCODING=iso8859-1
  364. " > etc/profile
  365. echo "proc /planck/proc proc defaults 0 0
  366. sysfs /planck/sys sysfs defaults 0 0
  367. devpts /planck/dev/pts devpts defaults 0 0
  368. tmpfs /planck/dev/shm tmpfs defaults 0 0" > etc/fstab
  369. status
  370. cd $workdir
  371. }
  372. # generate initramfs for live boot.
  373. gen_rootfs()
  374. {
  375. echo -e "[$YELLOW Working $NORMAL] Generating filesystem..."
  376. cd $workdir/src/rootfs
  377. ln -s planck/bin bin
  378. ln -s planck/lib lib
  379. ln -s planck/share share
  380. ln -s planck/sbin sbin
  381. ln -s planck/etc etc
  382. mkdir planck/proc
  383. mkdir planck/sys
  384. mkdir planck/run
  385. if [ ! -d planck/dev/pts ]; then
  386. mkdir planck/dev/pts
  387. fi
  388. ln -s planck/proc proc
  389. ln -s planck/sys sys
  390. mkdir root
  391. echo -n "Stripping build..."
  392. strip -g planck/lib/*.so > /dev/null 2>&1
  393. strip -g planck/lib/*.a > /dev/null 2>&1
  394. strip planck/bin/* > /dev/null 2>&1
  395. strip planck/sbin/* > /dev/null 2>&1
  396. cp ../../cfg/planck* planck/etc/.
  397. echo -n "Compressing rootfs tree..."
  398. find . -print | cpio -o -H newc | gzip -9 > ../../planck.gz 2>&1
  399. status
  400. cd $workdir
  401. }
  402. # setup bootloader for iso
  403. do_isolinux()
  404. {
  405. echo -e "[$YELLOW Working $NORMAL] Setting up bootloader."
  406. cd $workdir/src
  407. if [ ! -d cdroot ]; then
  408. mkdir cdroot
  409. mkdir cdroot/boot
  410. fi
  411. cd syslinux
  412. echo -n "Copying isolinux files to iso..."
  413. cp bios/core/isolinux.bin ../cdroot
  414. status_silent
  415. cp bios/com32/elflink/ldlinux/ldlinux.c32 ../cdroot
  416. status
  417. echo -n "Generating isolinux config..."
  418. echo "Planck Linux
  419. Press <enter> to boot" > ../cdroot/display.txt
  420. echo "display display.txt
  421. default Planck
  422. label Planck
  423. kernel /boot/bzImage
  424. append initrd=/boot/planck.gz rw root=/dev/null vga=788
  425. implicit 0
  426. prompt 1
  427. timeout 5" > ../cdroot/isolinux.cfg
  428. status
  429. cd $workdir
  430. }
  431. # generate complete iso ready for boot
  432. gen_iso()
  433. {
  434. echo -e -n "[$YELLOW Working $NORMAL] Generating bootable ISO image."
  435. cd $workdir/src
  436. cp ../planck.gz cdroot/boot
  437. cp linux-*/arch/x86/boot/bzImage cdroot/boot/bzImage
  438. genisoimage -R -o ../planck-$endtag.iso -b isolinux.bin \
  439. -c boot.cat -no-emul-boot -boot-load-size 4 \
  440. -V "Planck Linux" -input-charset iso8859-1 -boot-info-table cdroot > /dev/null 2>&1
  441. status
  442. }
  443. case $1 in
  444. full) do_kernel; do_musl; do_base; configure_system; gen_rootfs; do_isolinux; gen_iso;;
  445. rootfs) do_musl; do_base; configure_system; gen_rootfs;;
  446. *) echo "Unknown argument: ./build-planck [full|rootfs]";;
  447. esac