1 2# 3# spec file handling 4# 5 6# 7# Add a directory to a spec file 8# 9# $1 : directory to add 10# $2 : spec file 11add_dir_spec() { 12 echo "./$1 type=dir uid=0 gid=0 mode=0755" >> ${WORK_DIR}/$2 13} 14 15# 16# Add a file to a spec file 17# 18# $1 : file to add 19# $2 : spec file 20add_file_spec() { 21 echo "./$1 type=file uid=0 gid=0 mode=0755 size=$(wc -c < ${ROOT_DIR}/${1})" >> ${WORK_DIR}/$2 22} 23 24# 25# Add a symbolic link to a spec file 26# 27# $1 : symlink to add 28# $2 : link to 29# $3 : spec file 30add_link_spec() { 31 echo "./$1 type=link uid=0 gid=0 mode=0755 link=$2" >> ${WORK_DIR}/$3 32} 33 34# 35# workdir handling 36# 37 38# 39# Create the workdir (a directory where Minix is built using sets) 40# spec files are put in WORK_DIR, the file system created in ROOT_DIR 41# 42# $1 : sets to extract 43build_workdir() { 44 # Extract sets 45 mkdir -p ${ROOT_DIR} 46 for set in $1; do 47 if [ ! -e ${SETS_DIR}/${set}.tgz ]; then 48 echo "Missing ${SETS_DIR}/${set}.tgz, aborting" 49 echo "Are the release sets tarballs created?" 50 exit 1 51 fi 52 echo " * Extracting $set..." 53 (cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/${set}.tgz .) 54 done 55 56 # add rc (if any) 57 if [ -f ${RC} ]; then 58 cp ${RC} ${ROOT_DIR}/usr/etc/rc.local 59 fi 60 61 # Build login/password files 62 ${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${ROOT_DIR} ${ROOT_DIR}/etc/master.passwd 63 64 # Build specifications files 65 cp ${ROOT_DIR}/etc/mtree/set* ${WORK_DIR} 66 ${ROOT_DIR}/usr/bin/MAKEDEV -s -m all >> ${WORK_DIR}/extra.dev 67} 68 69# 70# Add tarball sets to the workdir (for installation CD) 71# 72workdir_add_sets() { 73 # Add sets to the root 74 mkdir -p ${ROOT_DIR}/${ARCH}/binary/sets; 75 add_dir_spec "${ARCH}" extra.sets 76 add_dir_spec "${ARCH}/binary" extra.sets 77 add_dir_spec "${ARCH}/binary/sets" extra.sets 78 79 DEST_SETS_DIR="${ARCH}/binary/sets" 80 for set in ${SETS_DIR}/*.tgz; do 81 # Copy set itself 82 cp ${set} ${ROOT_DIR}/${DEST_SETS_DIR} 83 add_file_spec "${DEST_SETS_DIR}/$(basename ${set})" extra.sets 84 85 # Add file count 86 COUNT_SRC=$(echo $(basename ${set}) | sed -e "s/\(.*\)\.tgz/\set.\1/") 87 COUNT_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.count/") 88 if [ -e "${DESTDIR}/etc/mtree/${COUNT_SRC}" ] 89 then 90 wc -l < ${DESTDIR}/etc/mtree/${COUNT_SRC} > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME} 91 else 92 # Can't find mtree file, set bogus number 93 echo 1 > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME} 94 fi 95 add_file_spec "${DEST_SETS_DIR}/${COUNT_NAME}" extra.sets 96 97 # Add file sizes 98 SIZE_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.size/") 99 ${CROSS_TOOLS}/nbpax -zvf ${set} . |grep -v 'bytes written in 1 secs [(]' | ${CROSS_TOOLS}/nbawk '{s+=$5} END{print s}' > ${ROOT_DIR}/${DEST_SETS_DIR}/${SIZE_NAME} 100 add_file_spec "${DEST_SETS_DIR}/${SIZE_NAME}" extra.sets 101 done 102 103 # Add checksums 104 cp ${SETS_DIR}/MD5 ${ROOT_DIR}/${DEST_SETS_DIR} 105 add_file_spec "${DEST_SETS_DIR}/MD5" extra.sets 106 cp ${SETS_DIR}/SHA512 ${ROOT_DIR}/${DEST_SETS_DIR} 107 add_file_spec "${DEST_SETS_DIR}/SHA512" extra.sets 108} 109 110# 111# Add CD boot files to the workdir 112# 113workdir_add_cdfiles() { 114 # Add boot monitor 115 cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/minixboot 116 add_file_spec "minixboot" extra.cdfiles 117 118 # Add README 119 cp releasetools/release/cd/README.TXT ${ROOT_DIR}/README.TXT 120 add_file_spec "README.TXT" extra.cdfiles 121} 122 123# 124# Extract kernel to designated directory 125# 126# $1: Directory where to extract 127workdir_add_kernel() 128{ 129 (cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/minix-kernel.tgz .) 130 131 # Move kernel files to the correct directory 132 if [ ! -d ${ROOT_DIR}/boot/$1 ] 133 then 134 mkdir -p ${ROOT_DIR}/boot/$1 135 add_dir_spec "boot/$1" extra.kernel 136 fi 137 138 mv ${ROOT_DIR}/boot/minix/.temp/* ${ROOT_DIR}/boot/$1 139 rm -rf ${ROOT_DIR}/boot/minix/.temp 140 for i in $(cd ${ROOT_DIR}/boot/$1 && echo *) 141 do 142 add_file_spec "boot/$1/$i" extra.kernel 143 done 144} 145 146# 147# Read METALOG and use mtree to convert the user and group names into uid and gids. 148# Used as the reference mtree for building file systems. 149# 150create_input_spec() 151{ 152 cat ${WORK_DIR}/set* ${WORK_DIR}/extra* | ${CROSS_TOOLS}/nbmtree -N ${ROOT_DIR}/etc -C -K device > ${WORK_DIR}/input 153 154 if [ ${ASR_HACK} -eq 1 ] 155 then 156 # Hacky workaround for ASR-randomized service binaries since they don't get nicely packaged in a tarball 157 # add any generated ASR-randomized service binaries 158 # TODO: apply stricter file permissions for both these and the base /service binaries, against local attacks 159 (cd ${DESTDIR} && find ./usr/service/asr -type f | sed 's/$/ type=file uid=0 gid=0 mode=0755/') >> ${WORK_DIR}/input 160 cp -r ${DESTDIR}/usr/service/asr ${ROOT_DIR}/usr/service 161 fi 162} 163 164# 165# Split mtree into partitions and create proto files for nbmkfs.mfs 166# 167# $1 : partitions to create (example: usr home) 168create_protos() 169{ 170 # build filter 171 FILTER_COMMAND="cat ${WORK_DIR}/input" 172 for i in $1 173 do 174 FILTER_COMMAND="$FILTER_COMMAND | grep -v \"^./$i/\" " 175 done 176 177 # fill root.img (skipping entries inside partitions while keeping partition mount points) 178 eval $FILTER_COMMAND | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.root 179 180 # create proto files for partitions using toproto 181 for i in $1 182 do 183 cat ${WORK_DIR}/input | grep "^\./$i/\|^. " | sed "s,\./$i,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR}/$i -o ${WORK_DIR}/proto.$i 184 done 185} 186 187# 188# Bundle packages (won't preinstall them) 189# 190# $1 : packages to bundle 191bundle_packages() 192{ 193 if [ -z "$1" ] 194 then 195 return 196 fi 197 198 if [ -z $PACKAGE_DIR ] 199 then 200 echo "Error: PACKAGE_DIR is not set while trying to bundle packages." 201 echo "Please fetch binary packages to bundle and set PACKAGE_DIR to continue." 202 exit 1 203 fi 204 205 DESTPACKAGES="usr/packages/$RELEASE_VERSION/$ARCH/All" 206 RELEASEPACKAGE="${ROOT_DIR}/$DESTPACKAGES" 207 index=pkg_summary 208 209 # create directories 210 mkdir -p $RELEASEPACKAGE 211 add_dir_spec "usr/packages" extra.pkgsrc 212 add_dir_spec "usr/packages/$RELEASE_VERSION" extra.pkgsrc 213 add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH" extra.pkgsrc 214 add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH/All" extra.pkgsrc 215 add_link_spec "packages" "usr/packages" extra.pkgsrc 216 for pkgprefix in $1 217 do 218 realfn=$(echo $PACKAGE_DIR/${pkgprefix}*.tgz | cut -d' ' -f1) 219 if [ -f "$realfn" ] 220 then 221 # Copy package 222 p="$(basename $realfn)" 223 echo " * Bundling $p..." 224 cp "$realfn" "$RELEASEPACKAGE/$p" 225 add_file_spec "$DESTPACKAGES/$p" extra.pkgsrc 226 else 227 echo "Error: Can't find $pkgprefix in directory $PACKAGE_DIR for bundling package." 228 exit 1 229 fi 230 done 231 232 if [ -x "$(which $PKG_INFO)" ] 233 then 234 # Create packages index 235 echo " * Generating package index..." 236 indexname=$indexpath/$p.$index 237 $PKG_INFO -X $RELEASEPACKAGE/*.tgz >> $RELEASEPACKAGE/$index 238 239 # Compress index 240 echo " * Compressing index..." 241 bzip2 -f $RELEASEPACKAGE/$index 242 add_file_spec "$DESTPACKAGES/$index.bz2" extra.pkgsrc 243 else 244 echo " * Skipping package index generation." 245 echo " PKG_INFO ("$(which $PKG_INFO)") not executable." 246 fi 247} 248 249# 250# stuff executed automatically to set up environment 251# 252 253usage() { 254 echo "Usage: $0 [options]" 255 echo " -X xsrc Build with X11 located in \"xsrc\" and extract its sets for image" 256 echo " (do not automatically extract for installation CD)" 257 echo " -b Add ASR service binaries to the image" 258 echo " (said binaries must be built beforehand)" 259 echo "" 260 echo "Environment variables:" 261 echo " CREATE_IMAGE_ONLY If set to 1, skip invocation of build.sh (default: 0)" 262 echo " JOBS Number of CPUs to use for build.sh to use (default: 1)" 263 echo " SETS Sets to extract for image (default: depends on script)" 264 echo " BUILDVARS Extra options passed to build.sh (default: none)" 265 echo "" 266 echo " PACKAGE_DIR Path to packages to bundle (default: none)" 267 echo " BUNDLE_PACKAGES List of packages to bundle (default: none)" 268 echo " PKG_INFO Path to 'pkg_info' for bundling (default: pkg_info)" 269} 270 271# parse options 272while getopts "iX:bh" c 273do 274 case "$c" in 275 i) echo "This method of generating the ISO installation media is obsolete." 276 echo "Run ./releasetools/x86_cdimage.sh instead." 277 exit 1;; 278 279 X) # we don't want to extract X sets by default for the installation CD 280 if ! echo "$0" | grep -q cdimage 281 then 282 SETS="$SETS xbase xcomp xetc xfont xserver" 283 fi 284 MKX11=yes 285 export MKX11 286 BUILDVARS="$BUILDVARS -X $OPTARG";; 287 288 b) # bitcode build: increase partition sizes 289 ROOT_SIZE="$((${ROOT_SIZE} + 192*(2**20)))" 290 USR_SIZE="$((${USR_SIZE} + 256*(2**20)))" 291 ASR_HACK=1;; 292 293 h) usage 294 exit 0;; 295 296 :) usage 297 exit 2;; 298 299 \?) 300 usage 301 exit 2;; 302 esac 303done 304 305# 306# Are we going to build the minix sources? 307# 308 309if [ ${CREATE_IMAGE_ONLY} -eq 1 ] 310then 311 if [ ! -d ${DESTDIR} ] 312 then 313 echo "Minix source code doesn't appear to have been built." 314 echo "Please try with \$CREATE_IMAGE_ONLY set to 0." 315 exit 1 316 fi 317 if [ ! -d ${RELEASEDIR} ] 318 then 319 echo "Minix release tarball sets don't appear to have been created." 320 echo "Please try with \$CREATE_IMAGE_ONLY set to 0." 321 exit 1 322 fi 323 # FIXME: this won't change anything for tarballs 324 #${CROSS_TOOLS}/nbmake-i386 -C releasetools do-hdboot 325else 326 echo "Going to build Minix source code..." 327 # 328 # Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'. 329 # 330 rm -f ${FSTAB} 331 332 # 333 # Now start the build. 334 # 335 sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u release 336 337fi 338 339# sanity check 340if [ -d "${WORK_DIR}/.git" ] 341then 342 echo "WORK_DIR directory has a Git repository in it, abort!" 343 exit 1 344fi 345 346# clean working directory 347if [ -e "${WORK_DIR}" ] 348then 349 rm -rf "${WORK_DIR}" 350fi 351mkdir -p ${WORK_DIR} 352 353# get absolute paths to those directories 354CROSS_TOOLS=$(cd ${CROSS_TOOLS} && pwd) 355DESTDIR=$(cd ${DESTDIR} && pwd) 356OBJ=$(cd ${OBJ} && pwd) 357SETS_DIR=$(cd ${SETS_DIR} && pwd) 358WORK_DIR=$(cd ${WORK_DIR} && pwd) 359ROOT_DIR=${WORK_DIR}/fs 360