onionbsd.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/sh -e
  2. ##################################################
  3. ###!! ONIONBSD v0.2 TOOLBOX !!###
  4. ###!! --- !!###
  5. ###!! Copyright 2019 The OnionBSD Project !!###
  6. ##################################################
  7. # CONTENTS:
  8. # 1. Variables
  9. # 2. Checks
  10. # 3. Download files
  11. # 4. Build functions
  12. # 5. Cleanup functions
  13. # ---
  14. # If you use this script to build your own
  15. # derative, please sign your distribution,
  16. # using the GPG key as pointed in BUILD.md
  17. fail() { >&2 echo "$@" exit 1; }
  18. ###
  19. # 1. VARIABLES
  20. ###
  21. # Which mirror to use to fetch the sets
  22. vmirror = "https://cdn.openbsd.org/pub/OpenBSD"
  23. # Declare which version of OpenBSD to use
  24. vversion = "6.5"
  25. # The architecture to use to build
  26. varch = "amd64"
  27. # The GPG key used to sign the build
  28. vsignkey = ""
  29. # The blocksize to use for the image
  30. vblocksize = 512
  31. # The size our resulting image should be
  32. vimagesize = "1900000000" # 1.9GB
  33. # The vnd identifier to use
  34. vnd = "vnd0"
  35. # The vnd device to use
  36. vnddev = "/dev/${vnd}a"
  37. # The raw vnd device to use
  38. vndrdev = "/dev/r${vnd}a"
  39. # The mountpoint for vnd to use
  40. vmountpoint = "${name}-fstmp"
  41. # Declare the workdir
  42. vworkdir = $(pwd)/workdir
  43. # Define the packages - base
  44. vbasepkgs = "tor git htop hotplug-diskmount"
  45. # Define the packages - XFCE
  46. vxfcepkgs_gui = "xfce-extras "
  47. vxfcepkgs_desk = "nano slim slim-themes"
  48. vxfcepkgs_imgs = "darktable gimp inkscape"
  49. vxfcepkgs_nets = "chromium iridium"
  50. vxfcepkgs_medi = "sox vlc audacious audacious-plugins ristretto"
  51. vxfcepkgs_font = "adobe-source-code-pro adobe-source-sans-pro adobe-source-serif-pro liberation-fonts freefont-ttf noto-fonts noto-emoji roboto-fonts"
  52. # Define the download tool
  53. vdownloader = "ftp -C"
  54. ###
  55. # 2. CHECKS
  56. ###
  57. runningobsd() {
  58. if [ "$(uname)" = "OpenBSD" ]; then
  59. bob = "thebuilder"
  60. else
  61. printf "OnionBSD requires OpenBSD to build, exiting..."
  62. fail();
  63. fi
  64. }
  65. depscheck() {
  66. }
  67. checkroot() {
  68. if [ ]
  69. }
  70. ###
  71. # 3. DOWNLOAD FILES
  72. ###
  73. downfiles() {
  74. downdir=site/home/root/pkg_cache
  75. todownload="HERE-COME-THE-PACKAGES-SAY-WHUT"
  76. if [ ! -d $downdir] then;
  77. printf "\t- Download directory doesn't exist, creating...\n"
  78. mkdir -p $outdir
  79. for p in $todownload; do
  80. if [ ! -f $downdir/$p ]; then
  81. ftp -C $PKG_PATH/$p
  82. mv $p $OUTDIR/
  83. fi
  84. done
  85. fi
  86. exit 0
  87. }
  88. ###
  89. # 4. BUILD FUNCTIONS
  90. ###
  91. prepdisk() {
  92. # Define the filesystem size construction
  93. fssize=$(expr $imagesize / $blocksize )
  94. # Create the mountpoint if it doesn't exist yet
  95. if [ ! -d $mountpoint ]; then
  96. printf "\t- Mountpoint doesn't exist, creating...\n"
  97. mkdir -p ${mountpoint}
  98. else
  99. printf "\t- Mountpoint already exists, skipping creation\n"
  100. fi
  101. printf "\t- Pre-allocating the disk image, this might take some time...\n"
  102. # Use dd to create the disk image and prefill it with random BS
  103. dd if=/dev/urandom of=${tmpimg} bs=${blocksize} count=${fssize}
  104. # Configure the vnode alias
  105. vnconfig ${vnd} ${tmpimg}
  106. printf "\t- Writing a GPT disk layout\n"
  107. # Format with GPT, rather than MBR
  108. fdisk -iy -g -b 960 ${vnd}
  109. printf "\t- Creating the partitions within the image\n"
  110. # Create the partitions
  111. echo "a\n\n\n\n\nw\nq\n" | disklabel -E ${vnd}
  112. printf "\t- Formatting the file system\n"
  113. # Well, actually format the filesystem
  114. newfs ${vndrdev}
  115. }
  116. builddisk() {
  117. printf "\t- Mounting and copying files over\n"
  118. mount ${vnddev} ${mountpoint}
  119. # Copy over the files
  120. cp -r ${name}/* ${mountpoint}
  121. # Install the bootloader
  122. installboot -r ${mountpoint} ${vnd} /usr/mdec/biosboot /usr/mdec/boot
  123. # Unmount and cleanup
  124. umount ${mountpoint}
  125. vnconfig -u ${vnd}
  126. rm -r ${mountpoint}
  127. mv ${tmpimg} onionbsd-v0.1.fs
  128. }
  129. prepiso() {
  130. if [ ! -e ${vname}.iso ]; then
  131. # Download the iso itself
  132. $vdownloader "${vmirror}/${vversion}/${varch}/install${vversion}.iso"
  133. # Download the corresponding checksum
  134. $ vdownloader "${vmirror}/${vversion}/${varch}/SHA256"
  135. if [ "$(uname)" = "OpenBSD" ]; then
  136. sha256 -C SHA256 install${vversion.iso
  137. if [ $? -ne 0 ]; then
  138. printf "\t- ERROR: SHA mismatch!\n"
  139. exit 1
  140. else
  141. printf "\t- The checksum matches, yay!\n"
  142. mv install${vversion}.iso ${vname}.iso
  143. fi
  144. fi
  145. fi
  146. if [ ! -d ${vname} ]; then
  147. printf "\t- Extracting the downloaded ISO\n"
  148. mkdir -p loopdir
  149. mkdir -p ./${vname}
  150. vnconfig vnd0 ${vname}.iso
  151. mount -t cd9660 /dev/vnd0c loopdir/
  152. cp -r loopdir/* ./${vname}
  153. umount loopdir/
  154. vnconfig -u vnd0
  155. rm -r loopdir/
  156. fi
  157. printf "\t- Confiuring the site set\n"
  158. mkdir -p site/etc
  159. touch site/install.site
  160. chmod 755 site/install.site
  161. touch site/etc/rc.firsttime
  162. chmod 755 site/etc/rc.firsttime
  163. }
  164. buildiso() {
  165. printf "\t- Creating the ISO\n"
  166. if [ -n "$(command -v mkisofs)" ]; then
  167. mkisofs -r -no-emul-boot -b ${vversion}/${varch}/cdbr -c boot.catalog -o ${vworkdir}/onionbsd.iso ${vname}
  168. else
  169. genisoimage -r -no-emul-boot -b ${vversion}/${varch}/cdbr -c boot.catalog -o ${vworkdir}/onionbsd.iso ${vname}
  170. fi
  171. }