#!/bin/sh
#(c) Copyright Barry Kauler 2009,2017. License GPL v3 (/usr/share/doc/legal)
#2createpackages has already built the generic packages in packages-$DISTRO_FILE_PREFIX/.
#these packages have generic names as specified in the second field of PKGS_SPECS_TABLE,
#which is a variable in ./DISTRO_PKGS_SPECS. The format of entries in table:
# yes|abiword|abiword,abiword-common|exe,dev,doc,nls
# ...if first field is 'yes' then it will be built into distro.
#170128 3buildeasydistro forked from script 3builddistro.
#170206 bring back aufs.
#170215 change download folder from /file to /mnt/home
#170217 add Q_DISTRO_VERSION to BOOT_SPECS file in initramfs.
#170220 remove pinstall.sh and pet.specs when create devx .sfs.
#170221 the old idea of /mnt/home not so good. now have /mnt/wkg/home
#170222 recent change prevented /usr/lib64 from being converted into a symlink to /usr/lib if a symlink in pet, but
# this upsets some pets from april64. affected pets: libdvdcss xfdiff-cut file hardinfo planner libgtkhtml xfdiff-cut_DEV xarchive metamail gnome-menus netpbm
# ...for ubuntu/debian builds, restore /usr/lib64 as a symlink.
#170224 for security reasons, do not turn on some daemons by default.
#170305 remove pre-created seamonkey container if sm not in build.
#170317 remove .img.gz if exists. 170325 DISTRO_SKELETON_IMAGE, no longer have SDFLAG
#170325 skeketon image may have 'skel2.sfs'. DISTRO_KERNEL_PET may be empty.
#170325 /usr/local/petget/0setup wants build-choices.
#170331 handle rpi skeleton image.
#170418 installing some april pkgs into yocto morty, there are two levels of symlinks, /usr/X11R7/lib64
#170429 yocto pyro, gtk-update-icon-cache did not exist.
#170429 omni.ja could be in seamonkey or firefox.
#170511 fix 'ca-certificates' package.
#170515 oe, usr/lib/gconv/gconv-modules.cache is missing.
#170517 python-tiny stays in main f.s. fix some indenting.
#170520 oe build, vmlinuz is a symlink.
#170521 if symlink is broken, the "-e" test fails, so add "-h".
#170526 keep the .a static libs!...
#170527 DISTRO_SPECS may have #EASY or #QUIRKY. 170528
#170624 oe pyro, no kernel pet, using kernel built in oe, depmod missing.
#170625 set KERNELVER
#170704 take out '--strip-unneeded' when strip.
#170730 remove gdisk as now have mbr, only need fdisk in initrd.
#170731 recent kernel 4.11.12 configured without aufs layer reval. export WOOF_TARGETARCH
#170801 /lib64 and /usr/lib64 may have to be symlinks.
#170801 fixed devx copy, following symlinks.
#170802 seems python ubuntu post-install script is moving usr/include to /include.
#170806 do not create bogus -BB-NOTUSED symlinks.
#170813 there is a lot of stuff in devx/usr/share/doc.
#170814 create devx .sfs, not .pet
#170826 have PuppyPin & globicons in rootfs-skeleton, make sure override ones in rox pet.
#170826 same as 170813, for rootfs-complete.
#171008 drive skeleton now 'easy-skeleton-amd64-640mb.img.gz' (ref input469/0-refind)
#171008 rename 'seamonkeyQNEW' to 'seamonkey' was in 3builddistro, bring back.
#171011 put version number into menu, refind.conf
#171016 remove trailing " #EASY" from DISTRO_SPECS
#171019 bump mksquashfs4.2 to mksquashfs4.3
#171022 oe: need symlinks /lib64 and /usr/lib64
#171105 32-bit i686, intel needs uxa
#171107 build-choice variable to keep static libs in devx.
#171109 run update-desktop-database
#171213 export WOOF_VARIANT so visible in pinstall.sh
#171214 make sure samba.sh from rootfs-skeleton is in rootfs-complete. 180120 no.
#171217 moved 170826 up.
#171218 remove Packages-pet-common-official
#171221 changed these to "no": BOOT_DISABLEXORGWIZARD BOOT_DISABLEALSACONF
#171231 fix for pkg named 'jwm2-976-pyro64'.
#180108 remove BOOT_DIRTYWRITE='1500' in rootfs-complete/etc/rc.d/BOOTCONSTRAINED
#180117 filter /tmp/DISTRO_PKGS_SPECS* for #EASY or #QUIRKY
#180120 overwrite rootfs-skeleton/etc/ssh/* to rootfs-complete
#180402 update icon cache for Adwaita, gtk3
#180407 create some containerized desktop icons.
#180411 check alsaconf exists.
#180518 new script 'build-rox-sendto' for right-click open-with menu.
#180523 hack to fix refind/syslinux rollback menu item.
#180523 trying to reduce size by moving gobject-introspection to devx (see pkg-list)
#180523 offer to rebuild all png files without compression.
#180531 changes in menus, refind.conf, syslinux.cfg
#180606 umount img_mntpt before exit.
#180618 run rootfs-complete/usr/local/EasyPak/create_db, creates devuan db files. 180706
#180628 busybox or coreutils may have installed 'df' applet as a symlink.
#180630 desktop icons for pre-existing conatiners: add ec-pet48.png
#180720 create ec-desk48.png for "desk" desktop icon.
#180818 need to keep libmvec.a in devx.
#180904 $KERNELNAME (vmlinuz or kernel8.img). see also easy-remaster, easy-version-control, initrd (init, rollback).
#181012 considered backup container icons, but not required.
#181029 change name from devx-${VER}-${DISTRO_FILE_PREFIX} to devx_${VER}_${DISTRO_TARGETARCH}
#181029 devx folder has some aufs whiteout files. these exist because of invalid symlinks in easy.sfs.
#181029 OE pkgs have file 'pkg.specs', stray one is left in devx.
#181102 create meta-data for sfs (ref: /usr/local/sfsget/dir2sfs). 181105 fix. 181112 fix.
#181114 change sha512sum to sha256sum.
#181117 new scripts in /.control in sfs.
#181121 quirky/woof-distro now easyos/easy-distro
#181122 q*.sfs renamed to easy*.sfs
#181130 'initrd.q' renamed to 'initrd'
#181201 Q_DISTRO* renamed to INIT_DISTRO* 181202 bug fix.
#181205 random number for disk-id
#190104 BOOT_SPECS now has INIT_LANG
#190107 build translations. #190108 find more translation files.
#190110 hunspell language dictionary.
#190110 translate home.htm, welcome.htm, help.htm  190111 fix.
#190111 deleted rootfs-skeleton/usr/local/EasyPak
#190112 libreoffice has .mo files, find these and maybe others.
#190112 host needs latest translation files.
#190113 download and install seamonkey language pack. 190114 bug fix.
#190115 make sure all langpacks adopt L18L's AppInfo.xml.in
#190115 rootfs-skeleton has .pot files, there may also be some in langpack.
#190123 need easy.png under sfs folder, as initrd will copy easy.sfs here at 1st bootup.
#190123 must not run sfsget inside a container.
#190128 create alternate 'initrd' without BOOT_SPECS file.
#190128 recompile kernel with inbuilt initrd. 190130 fix.
#190131 rock64 kernel name is 'Image'. fix for initrd builtin to kernel. fix for boot_dir
#190226 BOOT_SPECS content changed. UUIDs instead of disk-id.
#190305 syslinux.cfg now to have "vga=792"
#190307 new INITRD_X_GUI in BOOT_SPECS file.
#190310 no longer have BOOT_PARTNUM, WKG_PARTNUM, INITRD_X_GUI in BOOT_SPECS
#190311 do not want Xorg GUIs if english.
#190625 DEPENDENCIES-slackware is created in 0setup, copy to rootfs-complete/root/.packages
#190708 handle 5.x kernel.
#190712 make sure have latest fixdesk in host (fixinitrd and fixboot are symlinks to fixdesk)...
#190712 make sure have latest sss translations in host.
#190712 rename export-sfs to export-sfs-${DEFAULTLANG1}, support create-live-cd intl builds.
#190712 pre-configure keyboard layout choice in rootfs-complete
#190712 fixed composition of woof-installed-packages
#190713 fixed language translation.
#190729 need these symlinks for pyro binaries to work in multi-arch build. 190730 kernel ver fix.
#190804 buster, download debs with "-fr_" in name.
#190806 increase sleep when starting easy container. refer also dir2sfs
#190817 somehow rootfs-complete/DEBIAN got left.
#190821 restrict selection in 190804
#190829 home path changed from /mnt/wkg/home to /home
#190910 support default gtk3 theme.
#190911 "easy" container label on desktop needs to be changed to "pyro" or "buster".
#190912 url path changed for seamonkey language-packs.
#190919 files in etc/xdg/rox.sourceforge.net/MIME-types must override rox pet.
#190923 gnome-keyring is used by networkmanager and nm-applet to encrypt passwords.
#190926 remove /etc/xdg/autostart/*.desktop
#191002 buster: have two paths, both with drivers: /usr/lib/x86_64-linux-gnu/xorg/modules/drivers /usr/lib/xorg/modules/drivers
#191004a hack, easy buster, nothing much in 'pet-buster' repo, leave it out of ppm.
#191004 revert 190923
#191005 revert 190923 again. 191006 revert 191004a
#191007 may have two update-ca-certificates
#191009 do not create nss/nspr symlinks to seamonkey if already have system libs.
#191201 kernel lockdown feature (5.4 and later).
#191218 default xorg drivers kms on, set xorg driver detection to auto.
#200108 new variable BUILD_CHOICE_PNG_NOCOMPRESSION, ref 'build-choices' file.
#200109 fix gtk-update-icon-cache for adwaita.
#200110 new variable BUILD_CHOICE_LOAD_SWAP_BOOTUP, ref 'build-choices' file.
#200123 change WKG_DIR variable in file BOOT_SPECS from empty to "easyos/"
#200126 remove BOOT_UDEVDCHILDREN='1'
#200209 remove rootfs-complete/etc/rc0.d to rc6.d and rcS.d
#200210 remove old translation debs.
#200210 new BUILD_CHOICE_FILE_STRIP
#200220 fix sm langpack d/l url.
#200302 enable journal of ext4 working-partition.
#200322 refind.conf "ostype linux" must be "ostype Linux". also install ext4 driver.
#200406 save broken symlinks for later study.
#200511 livecode needs libstdc++.a to compile src pkg.
#200605 fix the menu entry for launching EasyOS in container.
#200708 the skeleton disk image has /EFI/BOOT/BOOTX64.EFI, check if we have a later version. remove BOOTIA32.EFI
#200711 override mime files from rootfs-skeleton.
#200720 test if "Copy session to RAM ..." already in refind.conf
#200727 gzip easy*.img with "--rsyncable" to make downloads with rsync more efficient.
#200728 disable lazy inode initialization in ext4.
#200804 write entire refind.conf and syslinux.cfg
#200806 "defaultbootup" for future editing. 200809 qfix=normal to remove permanent lockdown. 200810 remove "defaultbootup".
#200820 no longer using "lockdown=confidentialty" kernel param, it is done inside init.
#200929 more meaningful to change easy- to easy-${DISTRO_COMPAT_VERSION}- in .img.gz
#200930 oe dunfell: some pkgs have folder 'ptest' -- delete them.
#201012 fix xARCHDIR. may need symlinks for multiarch foreign pkgs to work in oe build.


#for easy linux, want to build a drive image, with just one 639MB fat32 partition.
#for PCs, bootable with syslinux. partition contains vmlinuz, initrd and easy.sfs
#for arm boards, use a ready-made skeleton image (which may have kernel in it).
#to make it easier for PCs, will also use a skeleton image, so no need to use syslinux to set it up.
# sd-skeleton-images has '*.img.gz', has one 639MB fat32 partition, total size
# of image is 640MB, appending a ext4 partition in target will start on a 8MB boundary.
#...actually, have made the image file 641MB, 1MB zeroes on end.

export LANG=C #faster.

#190107
if [ ! -e /usr/sbin/fixboot ];then
 echo "You must be running EasyOS version 1.0 or later. Aborting."
 exit 1
fi
if ! which gcc >/dev/null;then #need strip
 echo "You need to have the devx SFS installed. Aborting."
 exit 1
fi

#181205 random number for disk-id
if ! which openssl >/dev/null ;then
 echo 'utility openssl missing. aborting.'
 exit 1
fi
RANDHEX8="$(openssl rand -hex 4)" #want this for disk identifier.
[ "$RANDHEX8" == "12345678" ] && RANDHEX8="$(openssl rand -hex 4)" #181205 reserved, try again.
echo "Random hex number: ${RANDHEX8}"

#w482 use xorriso if it is installed (see also functions4puppy)...
CDRECORD='cdrecord'
MKISOFS='mkisofs'
if [ "`which xorriso`" != "" ];then
 CDRECORD='xorrecord'
 MKISOFS='xorrisofs' #growisofs reads this variable.
fi
export CDRECORD MKISOFS

. ./DISTRO_SPECS      #this has DISTRO_VERSION.
if [ ! "$DISTRO_DB_SUBNAME" ];then #121102
 DISTRO_DB_SUBNAME="$DISTRO_COMPAT_VERSION" #fallback if DISTRO_DB_SUBNAME not defined in file DISTRO_SPECS.
 echo '#subname for online PETs dir. Ex: "slacko14", dir "pet_packages-slacko14", db file "Packages-pet-slacko14-official":
#note: prior to existence of this variable, online subname was set to $DISTRO_COMPAT_VERSION or via some hack code.
' >> ./DISTRO_SPECS
 echo "DISTRO_DB_SUBNAME='${DISTRO_DB_SUBNAME}'" >> ./DISTRO_SPECS
fi
if [ -f ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
else
. ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} #130306
fi
if [ -f ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #w478
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} #has FALLBACKS_COMPAT_VERSIONS
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}" #161003
else
. ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT} #has FALLBACKS_COMPAT_VERSIONS
 DPSFILE="DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}" #161003
fi

. ./PKGS_MANAGEMENT #101013 want variable PKG_PREFER_OLDER.
. ./DISTRO_PET_REPOS #120506 want variable PACKAGELISTS_PET_ORDER

if [ -f WOOFMERGEVARS ];then #111123
. ./WOOFMERGEVARS #has variables WOOF_HOSTARCH, WOOF_TARGETARCH, WOOF_COMPATDISTRO, WOOF_COMPATVERSION, WOOF_VARIANT
else
 echo 'File WOOFMERGEVARS does not exist. This is created by script
merge2out. Your setup is wrong, quiting.'
 exit
fi
export WOOF_TARGETARCH WOOF_VARIANT #170731 want this in rootfs-skeleton/pinstall.sh 171213

#141206
BUILD_CHOICE_XORG_DRIVERS_ALTERNATE='' #values: 'none', 
BUILD_CHOICE_TRUE_SCSI_KERNEL_DRIVERS='' #150122 values: 'keep', 'delete'
BUILD_CHOICE_FB_KERNEL_DRIVERS='' #150122 values: 'keep', 'delete'
BUILD_CHOICE_EXOTIC_KERNEL_DRIVERS='' #150122 values: 'keep', 'delete'
BUILD_CHOICE_RADICAL_KERNEL_DRIVERS='' #150122 values: 'keep', 'delete'
BUILD_CHOICE_MERGE_DEVX='' #150725 values: 'yes' or anything else for no.
BUILD_CHOICE_README_DEV_DESK_ICON='' #150726 ditto.
BUILD_CHOICE_LANG='' #150726 default LANG, or empty to ask.
BUILD_CHOICE_BOARD='' #161003 values: raspi, odroidx, anything else for pc.
if [ -f build-choices ];then
. ./build-choices
fi

#120506. 160928. 161003. 170325
case "$BUILD_CHOICE_BOARD" in #in file build-choices.
 raspi) BOOT_BOARD='raspi' ;;
 odroidx) BOOT_BOARD='odroidx' ;;
 *) BOOT_BOARD='pc' ;; #building for a pc.
esac
export BOOT_BOARD #161022 want this in pinstall.sh
echo "WARNING: building for board: ${BOOT_BOARD}"
#160928 filter pkg selection based on board type...
xBOOT_BOARD="#$(echo -n "$BOOT_BOARD" | tr '[a-z]' '[A-Z]')" #ex: #ODROIDX
xBOARDS='#RASPI #ODROIDX #MELE #PC'
cp -f ${DPSFILE} /tmp/DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}COPY
#also filter DISTRO_SPECS...
cp -f DISTRO_SPECS /tmp/DISTRO_SPECSCOPY
for eachBOARD in $xBOARDS
do
 [ "$eachBOARD" == "$xBOOT_BOARD" ] && continue
 sed -i "/${eachBOARD}/d" /tmp/DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}COPY
 sed -i "/${eachBOARD}/d" /tmp/DISTRO_SPECSCOPY
done
echo "PKGS_SPECS_TABLE has been filtered for board '${xBOOT_BOARD}'"
echo "File DISTRO_SPECS has been filtered for board '${xBOOT_BOARD}'"
#180117 filter /tmp/DISTRO_PKGS_SPECS* for #EASY or #QUIRKY...
echo "File DISTRO_PKGS_SPECS-* has been filtered for #EASY"
sed -i '/#QUIRKY/d' /tmp/DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}COPY

. /tmp/DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}COPY

#170527 DISTRO_SPECS may have #EASY or #QUIRKY
#3buildeasydistro is only for the former...
echo "File DISTRO_SPECS has been filtered for distro #EASY"
sed -i '/#QUIRKY/d' /tmp/DISTRO_SPECSCOPY
#171016 remove trailing " #EASY"...
sed -i -e 's% +#EASY$%%' /tmp/DISTRO_SPECSCOPY

. /tmp/DISTRO_SPECSCOPY

#140125 DISTRO_ARCHDIR and DISTRO_ARCHDIR_SYMLINKS are in DISTRO_SPECS, created in 2createpackages.
ARCHDIR="$DISTRO_ARCHDIR"
xARCHDIR=""
if [ "$ARCHDIR" ];then #201011
 if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
  if [ "$ARCHDIR" == "lib64" ];then #150102
   xARCHDIR="64"
  else
   xARCHDIR="/${ARCHDIR}"
  fi
 fi
fi
export xARCHDIR #151123

#the files that have compatible-distro pkg docs (these were downloaded by 0setup)...
PKGLISTS_COMPAT="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | tr '\n' ' ' | sed -e 's% $%%'`" #see file DISTRO_PKGS_SPECS-ubuntu
#...format ex: 'Packages-ubuntu-intrepid-main Packages-ubuntu-intrepid-universe'

WKGDIR="`pwd`"

if grep -qw aufs /proc/filesystems; then #170206
 LAYERFS='aufs'
 RO='=ro'
else
 LAYERFS='overlay' #170128
 RO=''
fi

KERNVER="$(uname -r)"

#120506 params passed from woof_gui_tabs. moved up...
#KERNELPKG=""
#[ $1 ] && KERNELPKG="$1"
CHOICE_BIGMODEM=""
[ $3 ] && CHOICE_BIGMODEM="$3" #Erase_big_modems Keep_big_modems Zdrv_big_modems
#CHK_FB_STATE=""
#[ $4 ] && CHK_FB_STATE="$4"
#CHK_EXOTIC_STATE=""
#[ $5 ] && CHK_EXOTIC_STATE="$5"
#CHK_RADICAL_STATE=""
#[ $6 ] && CHK_RADICAL_STATE="$6"


#w003 remove comments from PKGS_SPECS_TABLE
zPKGS_SPECS_TABLE="`echo "$PKGS_SPECS_TABLE" | grep -v '^#'`"
PKGS_SPECS_TABLE="$zPKGS_SPECS_TABLE"

mkdir -p sandbox3

#cp -a -f install-quirky-to-drive.sh sandbox3/ #140119  140120 no.

export DISTRO_FILE_PREFIX #140128
export DISTRO_NAME
export DISTRO_VERSION
if [ "`echo -n "$DISTRO_VERSION" | grep '\.'`" = "" ];then #110422
 DIGIT1="`echo "$DISTRO_VERSION" | cut -b 1`"
 DIGIT2="`echo "$DISTRO_VERSION" | cut -b 2`"
 DIGIT3="`echo "$DISTRO_VERSION" | cut -b 3`"
 RIGHTVER="${DIGIT1}.${DIGIT2}.${DIGIT3}"
 [ "$DIGIT3" = "0" ] && RIGHTVER="${DIGIT1}.${DIGIT2}"
else
 RIGHTVER="$DISTRO_VERSION"
fi

#the kernel is supposed to be a .pet package, already downloaded into packages-pet...
KERNELPKG="$DISTRO_KERNEL_PET"
if [ "$DISTRO_KERNEL_PET" == "" ];then #160824
 KERNELVER=''
 MKSQUASHFS='mksquashfs4.3'
else
 echo "The kernel pkg that you are using is: $KERNELPKG"
 echo "This is specified in variable DISTRO_KERNEL_PET in file DISTRO_SPECS."
 echo "Note, the linux_kernel PET needs to be in directory packages-pet."
 #110826
 KERNELVER="`tar --list -z -f packages-pet/${KERNELPKG} 2>/dev/null | grep -o '/lib/modules/[2345]\..*' | head -n 1 | cut -f 4 -d '/'`" #120502 hide error msg. 150704 4.x kernel. 190708 5.x kernel.
 dotnum="`echo -n "$KERNELVER" | sed -e 's%[^\.]%%g' | wc -c`"
 if [ "$dotnum" = "2" ];then
  #SUB_SUB_KERNELVER=`echo -n "$KERNELPKG" | cut -f 3 -d '-'`
  SUB_SUB_KERNELVER=0 #cos we don't really know what it is.
 else
  SUB_SUB_KERNELVER=`echo -n "$KERNELVER" | cut -f 1 -d '-' | cut -f 4 -d '.'`
 fi
 SUB_KERNELVER=`echo -n "$KERNELVER" | cut -f 1 -d '-' | cut -f 3 -d '.'`
 MAJ_KERNELVER=`echo -n "$KERNELVER" | cut -f 1 -d '-' | cut -f 1 -d '.'` #111014 2 or 3. 150704 or 4. 190708 or 5.
 echo
 echo "You have chosen $KERNELPKG, which is version $KERNELVER."
 #if >= 2.6.29 kernel, use mksquashfs v4.0...
 if [ "$MAJ_KERNELVER" = "2" ];then
  MKSQUASHFS='mksquashfs3.3'
  [ $SUB_KERNELVER -ge 29 ] && MKSQUASHFS='mksquashfs4.0'
  [ $SUB_KERNELVER -ge 39 ] && MKSQUASHFS='mksquashfs4.3' #110713
  [ $SUB_KERNELVER -eq 18 ] && MKSQUASHFS='mksquashfs3.3' #w479 2.6.18.8 kernel
  [ $SUB_KERNELVER -eq 18 ] && [ $SUB_SUB_KERNELVER -eq 1 ] && MKSQUASHFS='mksquashfs3.2' #w479
  [ $SUB_KERNELVER -eq 27 ] && [ $SUB_SUB_KERNELVER -gt 46 ] && MKSQUASHFS='mksquashfs4.0' #100607
 else #111014
  MKSQUASHFS='mksquashfs4.3'
 fi
fi #160824

SQUASHFSMAJOR="`echo -n "$MKSQUASHFS" | cut -f 1 -d '.' | rev | cut -c 1`" #3 or 4.

#150727 don't ask...
COMPCHOICE=''
if [ "$MKSQUASHFS" = "mksquashfs4.3" ];then #110713
# echo
# echo ".sfs files are normally compressed with gzip."
# echo "However, this kernel supports xz, which is higher compression."
# echo -n "Press ENTER only for gzip, any other char for xz: "
# read XZCHOICE
# if [ "$XZCHOICE" ];then
#  echo "...xz chosen"
  COMPCHOICE='-comp xz'
# else
#  echo "...gzip chosen"
#  COMPCHOICE=''
# fi
fi

#110823
echo
./findwoofinstalledpkgs #creates woof-installed-packages, which later gets copied into sandbox3/rootfs-complete/root/.packages/
#121028 ...now also creates devx-only-installed-packages.

#140119 traditional names only...
PREFIX1CHAR="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`"
#160824 KERNEL3CHARS="`echo -n "$KERNELVER" | tr -d '.' | tr -d '\-' | tr -d '[a-z]' | rev | cut -c 1,2,3 | rev`"
PUPPYSFS="puppy_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
ZDRVPET="linux_modules_extra-${DISTRO_VERSION}-${DISTRO_FILE_PREFIX}.pet"
CHK_SIMPLE_FILENAMES='false'

#170325 ex: DISTRO_SKELETON_IMAGE='easy-skeleton-amd64-520mb.img.gz' 170331
SKELETON_NAME="${DISTRO_SKELETON_IMAGE%.img.?z}"
ROCK64flg="$(echo -n ${SKELETON_NAME} | grep -o 'rock64')" #190131
cp -f sd-skeleton-images/${SKELETON_NAME}.img.gz sandbox3/
sync
cd sandbox3
[ -f ${SKELETON_NAME}.img ] && rm -f ${SKELETON_NAME}.img
gunzip ${SKELETON_NAME}.img.gz

#190226 change UUID of the filesystems...
echo
echo "Assigning random UUIDs to ${SKELETON_NAME}.img"
LOOP1="$(losetup -f)" #free loop device, ex: /dev/loop2
if [ "$ROCK64flg" ];then
 OFF1='16777216' #16M first vfat partition.
 OFF2='687865856' #656M second ext4 partition
else
 OFF1='1048576' #1M
 OFF2='671088640' #640M
fi
losetup -o ${OFF1} ${LOOP1} ${SKELETON_NAME}.img
LOOP2="$(losetup -f)"
losetup -o ${OFF2} ${LOOP2} ${SKELETON_NAME}.img
BOOT_FS="$(blkid ${LOOP1} | grep -o 'TYPE=.*' | cut -f 2 -d '"')"
WKG_FS="$(blkid ${LOOP2} | grep -o 'TYPE=.*' | cut -f 2 -d '"')"
mlabel -n -i ${LOOP1} :: 2>/dev/null #assign new random serial number (uuid).
UUID1="$(blkid ${LOOP1} | grep -o 'UUID=.*' | cut -f 2 -d '"')"
tune2fs -U time ${LOOP2} #new random uuid.
tune2fs -O has_journal,^uninit_bg ${LOOP2} #200302 enable journal. 200728 disable lazy inode init.
fsck.ext4 -f -p ${LOOP2}
UUID2="$(blkid ${LOOP2} | grep -o 'UUID=.*' | cut -f 2 -d '"')"
sync
losetup -d ${LOOP2}
losetup -d ${LOOP1}
echo "  first (vfat) partition, UUID='${UUID1}'"
echo "  second (ext4) partition, UUID='${UUID2}'"

echo
echo "Mounting sandbox3/${SKELETON_NAME}.img"
mkdir -p img_mntpt
if [ "$ROCK64flg" ];then #190131
 mount -t ext4 -o offset=16M,loop ${SKELETON_NAME}.img img_mntpt #busybox mount does not support "offset="
else
 mount -t vfat -o offset=1048576,loop ${SKELETON_NAME}.img img_mntpt #busybox mount does not support "offset="
fi
if [ $? -ne 0 ];then #171011 precaution
 echo "FAILED: mount -t vfat -o offset=1048576,loop ${SKELETON_NAME}.img img_mntpt"
 exit
fi

BOOTDIR=''
if [ "$ROCK64flg" ];then
 BOOTDIR='boot/' 
fi

##171011
##a hack, in case spelling error still exists:
#sed -i -e 's%Filsystem%Filesystem%' img_mntpt/syslinux.cfg
#now using rEFInd...  180531 
#200804 write entire refind.conf, syslinux.cfg... 200806 "defaultbootup" for future editing. 200810 remove "defaultbootup".
if [ -f img_mntpt/EFI/BOOT/refind.conf ];then
 echo "timeout 10
textonly on
textmode 0
showtools shutdown,reboot,firmware
#scan_all_linux_kernels off
#scanfor manual,internal
scanfor manual
menuentry \"EasyOS ${DISTRO_VERSION}\" {
 loader /vmlinuz
 initrd /initrd
 ostype Linux
 options \"rw\"
 submenuentry \"Normal bootup (remove lockdown)\" {
  add_options \"qfix=normal\"
 }
 submenuentry \"Filesystem check\" {
  add_options \"qfix=fsck\"
 }
 submenuentry \"Commandline only, do not start X\" {
  add_options \"qfix=nox\"
 }
 submenuentry \"Rollback to last saved session\" {
  add_options \"qfix=bak\"
 }
 submenuentry \"Rollback to pristine first-boot\" {
  add_options \"qfix=new\"
 }
 submenuentry \"Copy session to RAM & unmount partitions\" {
  add_options \"qfix=lock1\"
 }
 submenuentry \"Copy session to RAM & disable drives\" {
  add_options \"qfix=lock2\"
 }
 submenuentry \"initrd shell: Nothing yet mounted\" {
  add_options \"qfix=dropout0\"
 }
 submenuentry \"initrd shell: Boot & wkg partitions mounted\" {
  add_options \"qfix=dropout1\"
 }
 submenuentry \"initrd shell: Before recovery & maintenance operations\" {
  add_options \"qfix=dropout2\"
 }
 submenuentry \"initrd shell: Before version control\" {
  add_options \"qfix=dropout3\"
 }
 submenuentry \"initrd shell: Before setting up SFS layers\" {
  add_options \"qfix=dropout4\"
 }
 submenuentry \"initrd shell: Before moving mount points to wkg f.s.\" {
  add_options \"qfix=dropout5\"
 }
 submenuentry \"initrd shell: Just before switch_root\" {
  add_options \"qfix=dropout6\"
 }
}
menuentry \"Windows 10\" {
 volume SYSTEM
 loader \EFI\Microsoft\Boot\bootmgfw.efi
 disabled
}" > img_mntpt/EFI/BOOT/refind.conf
fi
if [ -f img_mntpt/syslinux.cfg ];then #180531 181202 200804
 echo "ui menu.c32

menu title EasyOS ${DISTRO_VERSION}
default defboot
timeout 100

label defboot
menu label Default startup
kernel vmlinuz
append initrd=initrd rw vga=792

label normal
menu label Normal startup (remove lockdown)
kernel vmlinuz
append initrd=initrd rw qfix=normal vga=792

label fsck
menu label Filesystem check
kernel vmlinuz
append initrd=initrd rw qfix=fsck vga=792

label nox
menu label Commandline only, do not start X
kernel vmlinuz
append initrd=initrd rw qfix=nox vga=792

label bak
menu label Rollback to last saved session
kernel vmlinuz
append initrd=initrd rw qfix=bak vga=792

label new
menu label Rollback to pristine first-boot
kernel vmlinuz
append initrd=initrd rw qfix=new vga=792

label lock1
menu label Copy session to RAM & unmount partitions
kernel vmlinuz
append initrd=initrd rw qfix=lock1 vga=792

label lock2
menu label Copy session to RAM & disable drives
kernel vmlinuz
append initrd=initrd rw qfix=lock2 vga=792

menu begin Developers only: dropout to a shell in initrd

label dropout0
menu label initrd shell: Nothing yet mounted
kernel vmlinuz
append rw qfix=dropout0 vga=792

label dropout1
menu label initrd shell: Boot & wkg partitions mounted
kernel vmlinuz
append rw qfix=dropout1 vga=792

label dropout2
menu label initrd shell: Before recovery & maintenance operations
kernel vmlinuz
append rw qfix=dropout2 vga=792

label dropout3
menu label initrd shell: Before version control
kernel vmlinuz
append rw qfix=dropout3 vga=792

label dropout4
menu label initrd shell: Before setting up SFS layers
kernel vmlinuz
append rw qfix=dropout4 vga=792

label dropout5
menu label initrd shell: Before moving mount points to wkg f.s.
kernel vmlinuz
append rw qfix=dropout5 vga=792

label dropout6
menu label initrd shell: Just before switch_root
kernel vmlinuz
append rw qfix=dropout6 vga=792

menu end" > img_mntpt/syslinux.cfg
fi

cd ..
sync

#now build rootfs-complete, the main filesystem...
echo
echo "Now building sandbox3/rootfs-complete, with the complete filesystem..."
echo '#!/bin/sh' > sandbox3/pinstall.sh
rm -rf sandbox3/rootfs-complete
sync
mkdir sandbox3/rootfs-complete

#150731 moved this up, as some pkgs were overwriting skeleton scripts...
if [ -f status/findpkgs_GENERIC_NAMES-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #150714
 #150728 want to create a minimal chroot-able rootfs-complete, so can run pre- and post-install deb scripts...
 echo "Creating minimal chroot-able f.s. in sandbox3/rootfs-complete..."
 #150730 'awk' may not be in busybox... ubuntu 'coreutils' has no deps, but needs libacl.so.1 and libattr.so.1 ... 'awk' needs mpfr...
 #150730 perl is installing too late so put here... 'glib' also...
 for AMINPKG in busybox glibc pcre libselinux bash ncurses dpkg readline libffi gawk acl attr mpfr4 perl glib
 do
  [ -d packages-${DISTRO_FILE_PREFIX}/${AMINPKG} ] && cp -a -f --remove-destination packages-${DISTRO_FILE_PREFIX}/${AMINPKG}/* sandbox3/rootfs-complete/
 done
 [ -e sandbox3/rootfs-complete/pet.specs ] && rm -f sandbox3/rootfs-complete/pet.specs
 [ -e sandbox3/rootfs-complete/pinstall.sh ] && rm -f sandbox3/rootfs-complete/pinstall.sh
 rm -rf sandbox3/rootfs-complete/DEBIAN* 2> /dev/null
fi

mkdir -p sandbox3/rootfs-complete/etc
#cp DISTRO_SPECS sandbox3/rootfs-complete/etc/
cp -f /tmp/DISTRO_SPECSCOPY sandbox3/rootfs-complete/etc/DISTRO_SPECS #170528

#copy the skeleton...
cp -a -f --remove-destination rootfs-skeleton/* sandbox3/rootfs-complete/ #150731
cat sandbox3/rootfs-complete/pinstall.sh >> sandbox3/pinstall.sh
rm -f sandbox3/rootfs-complete/pinstall.sh

rm -f /tmp/3builddistro_removed_alt 2>/dev/null #101013

#170801 /lib64 and /usr/lib64 may have to be symlinks...
#note, already created the minimal chrootable f.s. above, may need to fix.
echo "/lib" > sandbox3/rootfs-complete/etc/ld.so.conf
echo "/usr/lib" >> sandbox3/rootfs-complete/etc/ld.so.conf
case $WOOF_TARGETARCH in #161002
 x86|armv7) #32-bit
  true
 ;;
 *) #64-bit ex: amd64
  if [ "$ARCHDIR" ];then #ex1: i386-linux-gnu  ex2: x86_64-linux-gnu
   for aLIB in lib usr/lib
   do
    if [ "$ARCHDIR" != "lib64" ];then #150102
     if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
      mkdir -p sandbox3/rootfs-complete/${aLIB}/${ARCHDIR}
      if [ -e sandbox3/rootfs-complete/${aLIB}64 ];then #coz of chrootable f.s.
       if [ ! -h sandbox3/rootfs-complete/${aLIB}64 ];then
        cp -a -f --remove-destination sandbox3/rootfs-complete/${aLIB}64/* sandbox3/rootfs-complete/${aLIB}/${ARCHDIR}/
        rm -rf sandbox3/rootfs-complete/${aLIB}64
       fi
      fi
      ln -snf lib/${ARCHDIR} sandbox3/rootfs-complete/${aLIB}64
      echo "/${aLIB}/${ARCHDIR}" >> sandbox3/rootfs-complete/etc/ld.so.conf
     else
      if [ -e sandbox3/rootfs-complete/${aLIB}64 ];then #coz of chrootable f.s.
       if [ ! -h sandbox3/rootfs-complete/${aLIB}64 ];then
        cp -a -f --remove-destination sandbox3/rootfs-complete/${aLIB}64/* sandbox3/rootfs-complete/${aLIB}/
        rm -rf sandbox3/rootfs-complete/${aLIB}64
       fi
      fi
      ln -snf ./ sandbox3/rootfs-complete/${aLIB}64
     fi
    else
     if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
      mkdir -p sandbox3/rootfs-complete/${aLIB}64
      echo "/${aLIB}64" >> sandbox3/rootfs-complete/etc/ld.so.conf
     else
      if [ -e sandbox3/rootfs-complete/${aLIB}64 ];then #coz of chrootable f.s.
       if [ ! -h sandbox3/rootfs-complete/${aLIB}64 ];then
        cp -a -f --remove-destination sandbox3/rootfs-complete/${aLIB}64/* sandbox3/rootfs-complete/${aLIB}/
        rm -rf sandbox3/rootfs-complete/${aLIB}64
       fi
      fi
      ln -snf ./ sandbox3/rootfs-complete/${aLIB}64
     fi
    fi
   done
   #190729 need these symlinks for pyro binaries to work in multi-arch build...
   if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
    ln -s ${ARCHDIR}/libc.so.6 sandbox3/rootfs-complete/lib/libc.so.6
    case "$WOOF_TARGETARCH" in
     amd64)
      ln -s ${ARCHDIR}/ld-linux-x86-64.so.2 sandbox3/rootfs-complete/lib/ld-linux-x86-64.so.2
     ;;
     *)
      ln -s ${ARCHDIR}/ld-linux-${WOOF_TARGETARCH}.so.2 sandbox3/rootfs-complete/lib/ld-linux-${WOOF_TARGETARCH}.so.2
     ;;
    esac
   fi
  fi
 ;;
esac
#140123 note, ld.so.conf appended-to further down.

echo "3builddistro found these pkgs missing in packages-${DISTRO_FILE_PREFIX}:" > zmissing-pkgs-3builddistro #141107
if [ -f status/findpkgs_GENERIC_NAMES-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #150714 150731
 #these names are listed in dependency-order, not alphabetical.
 PKGLIST="$(cat status/findpkgs_GENERIC_NAMES-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} | tr '\n' ' ')" #names in dependency-order.
else
 PKGLIST="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | cut -f 2 -d '|' | tr '\n' ' '`"
fi

if [ "$BUILD_CHOICE_MERGE_DEVX" == "yes" ];then #150725
 #manipulate the pkg-list to remove "dev" target...
 xPKGS_SPECS_TABLE="$(echo "$PKGS_SPECS_TABLE" | sed -e 's%dev>exe%YYYYYY%' -e 's%dev>null%ZZZZZZ%' -e 's%exe>dev%exe%' -e 's%nls>dev%nls>exe%' -e 's%doc>dev%doc>exe%' -e 's%,dev%%' | sed -e 's%>dev%%' -e 's%dev,%%' -e 's%ZZZZZZ%dev>null%' -e 's%YYYYYY%dev>exe%' -e 's%,|%|%')"
 PKGS_SPECS_TABLE="$xPKGS_SPECS_TABLE"
fi

echo "Populating sandbox3/rootfs-complete from packages-${DISTRO_FILE_PREFIX}..."
rm -f deb-postinst-log 2>/dev/null
for ONEPKG in $PKGLIST
do
 if [ ! -d packages-${DISTRO_FILE_PREFIX}/${ONEPKG} ];then
  if [ ! -d packages-${DISTRO_FILE_PREFIX}/${ONEPKG}_DEV ];then #pkg may go entirely into devx.
   if [ ! -d packages-${DISTRO_FILE_PREFIX}/${ONEPKG}_DOC ];then #pkg may go entirely into docs.
    echo "WARNING, PKG DOES NOT EXIST: packages-${DISTRO_FILE_PREFIX}/${ONEPKG}"
    echo "${ONEPKG}" >> zmissing-pkgs-3builddistro #141107
    continue
   fi
  fi
 fi
 echo -n '.'

 #110923 avoid conflict between busybox applets and full utilities...
 [ "$ONEPKG" == "busybox" ] && continue #see below.
 
 #170801 remove lib hyperlinks, some pets have it...
 [ -h packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/lib64 ] && rm -f packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/lib64
 [ -h packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/usr/lib64 ] && rm -f packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/usr/lib64
 
 #cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/* sandbox3/rootfs-complete/ 2> /dev/null
 #w003 problem. pet pkg seamonkey_addon_adblock has files in /usr/lib/seamonkey but in rootfs-complete
 #usr/lib/seamonkey is a symlink to seamonkey-1.1.14 and copy fails. this will follow path with a
 #symlink (hopefully doesn't break something else)...
 #looks okay. the --remove-destination ensures that if target file already exists as a symlink
 #it will be deleted first and won't be followed. shit no, it changed /usr/lib/seamonkey into a dir...
 #cp -r --preserve=mode,ownership,timestamps,links --dereference --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/* sandbox3/rootfs-complete/ 2> /dev/null
 #/usr/sbin/petget solves this a different way, let's try that...
 
 #130430 new problem with coreutils 8.20... ex building raring pup...
 #ex: cp -a --remove-destination packages-raring/synclient/* sandbox3/rootfs-complete/
 #coreutils 5.2.1 stderr: cannot overwrite non-directory `sandbox3/rootfs-complete/usr/X11' with directory `packages-raring/synclient/usr/X11'
 #coreutils 8.20 (in Raring) stderr: cp: cannot overwrite non-directory ‘sandbox3/rootfs-complete/usr/X11’ with directory ‘packages-raring/synclient/usr/X11’
 #...!!!! ok, attempt to fix...
 
 cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEPKG}/* sandbox3/rootfs-complete/ 2> /tmp/3builddistro-cp-errlog
 sync #110727 running drake pup 0.3 with k2.6.39-3 new laptop, mysterious loss of dirs/files. try sync.
 if [ -s /tmp/3builddistro-cp-errlog ];then #130430 next line fixes those quote chars... 150929 weird, tr creating multiple ' chars...
  #cat /tmp/3builddistro-cp-errlog | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'" |
  while read ONEDIRSYMLINK
  do
   xONEDIRSYMLINK="`echo -n "$ONEDIRSYMLINK" | sed -e 's%sandbox3/rootfs-complete%%'`"
   #adding that extra trailing / does the trick...
   cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEPKG}${xONEDIRSYMLINK}/* sandbox3/rootfs-complete${xONEDIRSYMLINK}/ 2> /tmp/3builddistro-cp-errlog2
   #170418 installing some april pkgs into yocto morty, there are two levels of symlinks, /usr/X11R7/lib64...
   if [ -s /tmp/3builddistro-cp-errlog2 ];then
    cat /tmp/3builddistro-cp-errlog2 | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'" |
    while read ONEDIRSYMLINK2
    do
     xONEDIRSYMLINK2="`echo -n "$ONEDIRSYMLINK2" | sed -e 's%sandbox3/rootfs-complete%%'`"
     #adding that extra trailing / does the trick...
     cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEPKG}${xONEDIRSYMLINK2}/* sandbox3/rootfs-complete${xONEDIRSYMLINK2}/
    done
    sync
   fi
  done<<_END1
$(cat /tmp/3builddistro-cp-errlog | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'")
_END1
 fi
 #...now seems ok. note, there are two places in woof v003 where this problem occurs: /usr/lib/seamonkey
 # and /usr/share/cups/model.
 
 if [ -f sandbox3/rootfs-complete/pinstall.sh ];then
  #note, do not filter #! /bin/sh (with a space)...
  grep  -E -v '^\#\!\/bin\/sh' sandbox3/rootfs-complete/pinstall.sh >> sandbox3/pinstall.sh
  rm -f sandbox3/rootfs-complete/pinstall.sh
 fi
 #get rid of a .specs file...
 rm -f sandbox3/rootfs-complete/*.specs
 #window and menu icons can also be in the top-level directory of the package...
 mv sandbox3/rootfs-complete/*24.xpm sandbox3/rootfs-complete/usr/local/lib/X11/pixmaps/ 2>/dev/null
 mv sandbox3/rootfs-complete/*32.xpm sandbox3/rootfs-complete/usr/local/lib/X11/pixmaps/ 2>/dev/null
 mv sandbox3/rootfs-complete/*32.png sandbox3/rootfs-complete/usr/local/lib/X11/pixmaps/ 2>/dev/null
 mv sandbox3/rootfs-complete/*48.xpm sandbox3/rootfs-complete/usr/local/lib/X11/pixmaps/ 2>/dev/null
 mv sandbox3/rootfs-complete/*48.png sandbox3/rootfs-complete/usr/local/lib/X11/pixmaps/ 2>/dev/null
 mv sandbox3/rootfs-complete/*.xpm sandbox3/rootfs-complete/usr/local/lib/X11/mini-icons/ 2>/dev/null
 mv sandbox3/rootfs-complete/*.png sandbox3/rootfs-complete/usr/local/lib/X11/mini-icons/ 2>/dev/null

 #150728 .deb may have preinst and postinst scripts...
 if [ "$WOOF_HOSTARCH" == "$WOOF_TARGETARCH" ];then
  #only execute them if pkglist sorted into dependency-order, ie this file exists...
  if [ -f status/findpkgs_GENERIC_NAMES-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #150714
   FNDDEBIAN="$(find sandbox3/rootfs-complete -maxdepth 1 -type d -name 'DEBIAN*' | tr '\n' ' ')"
   for ADEBIAN in $FNDDEBIAN
   do
    echo -n 'p'
    baseDEBIAN="$(basename $ADEBIAN)"
    if [ -x sandbox3/rootfs-complete/${baseDEBIAN}/postinst ];then
     echo >> deb-postinst-log
     REALPKGNAME="$(echo -n "$baseDEBIAN" | sed -e 's%^DEBIAN%%')"
     echo "${ONEPKG} ${REALPKGNAME}" >> deb-postinst-log
     chroot sandbox3/rootfs-complete /${baseDEBIAN}/postinst configure >> deb-postinst-log 2>&1
    fi
    rm -rf sandbox3/rootfs-complete/${baseDEBIAN}
   done
  fi
 #else
 # rm -rf sandbox3/rootfs-complete/DEBIAN* 2> /dev/null
 fi
 rm -rf sandbox3/rootfs-complete/DEBIAN* 2> /dev/null #161005

done
echo
[ -s deb-postinst-log ] && echo "...'deb-postinst-log' has log of executing postinst scripts"
echo

#200322 refind, also copy the ext4 driver...
if [ -f sandbox3/rootfs-complete/usr/share/refind/drivers_x64/ext4_x64.efi ];then
 mkdir -p sandbox3/img_mntpt/EFI/BOOT/drivers
 cp -a -f sandbox3/rootfs-complete/usr/share/refind/drivers_x64/ext4_x64.efi sandbox3/img_mntpt/EFI/BOOT/drivers/
fi
#200708 the skeleton disk image has /EFI/BOOT/BOOTX64.EFI, check if we have a later version...
if [ -f sandbox3/rootfs-complete/usr/share/refind/easy/refind_x64.efi ];then
 mkdir -p sandbox3/img_mntpt/EFI/BOOT
 cp -a -f sandbox3/rootfs-complete/usr/share/refind/easy/refind_x64.efi sandbox3/img_mntpt/EFI/BOOT/BOOTX64.EFI
fi
#200708 hack, don't want this...
[ -f sandbox3/img_mntpt/EFI/BOOT/BOOTIA32.EFI ] && rm -f sandbox3/img_mntpt/EFI/BOOT/BOOTIA32.EFI

#190712 moved this up...
cp -a -f woof-installed-packages sandbox3/rootfs-complete/root/.packages/

#120216 set default LANG and KMAP... 120401 improve...  190107 moved up...
echo
DEFAULTKMAP="us" #190712
if [ "$BUILD_CHOICE_LANG" != "" ];then #150726
 DEFAULTLANG="$BUILD_CHOICE_LANG"
else
 echo
 echo "Puppy is built with a default locale LANG=en_US and keyboard layout KMAP=us,
which may be changed after bootup.
However, if you are building a language-specific Puppy, you may change the
defaults now. But, please do make sure that your Puppy has a 'langpack' PET
for your language installed -- if one does not exist, then you will have to
create one -- see MoManager in the Utility menu, also read the Menu -> Help
-> HOWTO Internationalization."
 echo
 echo "These are the available LANG values (in /usr/share/i18n/locales):
aa_DJ aa_ER aa_ER@saaho aa_ET af_ZA am_ET an_ES ar_AE ar_BH ar_DZ ar_EG ar_IN ar_IQ ar_JO ar_KW ar_LB ar_LY ar_MA ar_OM ar_QA ar_SA ar_SD ar_SY ar_TN ar_YE as_IN ast_ES az_AZ be_BY be_BY@latin ber_DZ ber_MA bg_BG bn_BD bn_IN br_FR br_FR@euro bs_BA byn_ER ca_AD ca_ES ca_ES@euro ca_FR ca_IT crh_UA csb_PL cs_CZ cy_GB da_DK de_AT de_AT@euro de_BE de_BE@euro de_CH de_DE de_DE@euro de_LU de_LU@euro dz_BT el_CY el_GR el_GR@euro en_AU en_BW en_CA en_DK en_GB en_HK en_IE en_IE@euro en_IN en_NG en_NZ en_PH en_SG en_US en_ZA en_ZW es_AR es_BO es_CL es_CO es_CR es_DO es_EC es_ES es_ES@euro es_GT es_HN es_MX es_NI es_PA es_PE es_PR es_PY es_SV es_US es_UY es_VE et_EE eu_ES eu_ES@euro fa_IR fi_FI fi_FI@euro fil_PH fo_FO fr_BE fr_BE@euro fr_CA fr_CH fr_FR fr_FR@euro fr_LU fr_LU@euro fur_IT fy_DE fy_NL ga_IE ga_IE@euro gd_GB gez_ER gez_ER@abegede gez_ET gez_ET@abegede gl_ES gl_ES@euro gu_IN gv_GB ha_NG he_IL hi_IN hr_HR hsb_DE hu_HU hy_AM id_ID ig_NG ik_CA is_IS it_CH it_IT it_IT@euro iu_CA iw_IL ja_JP ka_GE kk_KZ kl_GL km_KH kn_IN ko_KR ks_IN ku_TR kw_GB ky_KG lg_UG li_BE li_NL lo_LA lt_LT lv_LV mai_IN mg_MG mi_NZ mk_MK ml_IN mn_MN mr_IN ms_MY mt_MT nb_NO nds_DE nds_NL ne_NP nl_BE nl_BE@euro nl_NL nl_NL@euro nn_NO nr_ZA nso_ZA oc_FR om_ET om_KE or_IN pa_IN pap_AN pa_PK pl_PL pt_BR pt_PT pt_PT@euro ro_RO ru_RU ru_UA rw_RW sa_IN sc_IT se_NO shs_CA sid_ET si_LK sk_SK sl_SI so_DJ so_ET so_KE so_SO sq_AL sr_ME sr_RS sr_RS@latin ss_ZA st_ZA sv_FI sv_FI@euro sv_SE ta_IN te_IN tg_TJ th_TH ti_ER ti_ET tig_ER tk_TM tl_PH tn_ZA tr_CY tr_TR ts_ZA tt_RU tt_RU@iqtelif ug_CN uk_UA ur_PK uz_UZ uz_UZ@cyrillic ve_ZA vi_VN wa_BE wa_BE@euro wal_ET wo_SN xh_ZA yi_US yo_NG zh_CN zh_HK zh_SG zh_TW zu_ZA"
 echo "ENTER only for default, else type one of the above. Usually, you would want UTF-8 enabled, so append that. ex: de_DE.UTF-8."
 echo "(the default is en_US.UTF-8)"
 echo -n "ENTER only for default, or type it now: "
 read DEFAULTLANG
fi
if [ "$DEFAULTLANG" ];then
 echo "...ok, set to ${DEFAULTLANG}"
 DEFAULTLANG1="${DEFAULTLANG%_*}"
 if [ "$DEFAULTLANG1" != "en" ];then
  echo
  echo "These are the available keyboard layout values (in /lib/keymaps):
azerty be-latin1 br-abnt2 br-abnt br-latin1-abnt2 br-latin1-us by cf croat cz de de-latin1 dk dvorak dvorak-l dvorak-r es et fi fr gr hu101 hu il it jp106 lt mk nl no pl pt-latin1 ro ru se sg sk-qwerty sk-qwertz slovene sv-latin1 uk us wangbe"
  echo "You don't have to choose a default here, as Easy will ask at first bootup. Whatever, after bootup the user will have the opportunity to change it, in the QuickSetup window."
  echo -n "Enter only for 'us', else type one of the above: "
  read DEFAULTKMAP
  [ "$DEFAULTKMAP" = "" ] && DEFAULTKMAP="us"
  echo "...ok, set to ${DEFAULTKMAP}"
 fi
else
 DEFAULTLANG="en_US.UTF-8" #121123
 DEFAULTLANG1="en" #190107
 echo "...ok, set to ${DEFAULTLANG}"
fi
DEFAULTLANG12="${DEFAULTLANG%.*}"
#i think also, set LANG in /etc/profile...
sed -i -e "s%^LANG=.*%LANG=${DEFAULTLANG}%" sandbox3/rootfs-complete/etc/profile
echo

#190712 set the default keyboard layout...
echo -n "${DEFAULTKMAP}" > sandbox3/rootfs-complete/etc/keymap
#code duplication, see 'ask-country-x' in initrd and /usr/sbin/quicksetup...
# do this now, so don't have to do it at first bootup...
  KMAPPATH='sandbox3/rootfs-complete/lib/keymaps'
  [ -d sandbox3/rootfs-complete/usr/share/kbd/keymaps/i386 ] && KMAPPATH='sandbox3/rootfs-complete/usr/share/kbd/keymaps/i386'
  [ -d sandbox3/rootfs-complete/usr/share/keymaps/i386 ] && KMAPPATH='sandbox3/rootfs-complete/usr/share/keymaps/i386' #debian, gentoo. note, debian files have extension .kmap.gz, gentoo have .map.gz
   echo -n "" > sandbox3/rootfs-complete/var/local/quickset-keyboard-list
   case $KMAPPATH in
    sandbox3/rootfs-complete/lib/keymaps) KMAPFILES="`find sandbox3/rootfs-complete/lib/keymaps -mindepth 1 -maxdepth 1 -name '*.gz' | sort`" ;; #ex: us.gz
    *) KMAPFILES="`find ${KMAPPATH}/[^i]* -name '*.map' -o -name '*.kmap' -o -name '*.map.gz' -o -name '*.kmap.gz' -not -name 'defkeymap*' | sort`" ;;
   esac
   for AFILE in $KMAPFILES
   do
    AKMAP="`basename $AFILE .gz`" #us, fr, br, etc.
    AKMAP="`basename $AKMAP .kmap`"
    AKMAP="`basename $AKMAP .map`"
    case $AKMAP in
     us*) ACNTRY="(USA)";;
     fr*) ACNTRY="(France)";;
     it*) ACNTRY="(Italy)";;
     ba*) ACNTRY="(Bashkir)";;
     be*) ACNTRY="(Belgium)";;
     bg*) ACNTRY="(Bulgaria)";;
     br*) ACNTRY="(Brazil)";;
     by*) ACNTRY="(Byelorussian)";;
     cf*) ACNTRY="(French-Canadian)";;
     croat*) ACNTRY="(Croatia)";;
     cz*) ACNTRY="(Czech)";;
     de) ACNTRY="(Germany)";;
     de_*) ACNTRY="(Germany)";;
     de-*) ACNTRY="(Germany)";;
     dk*) ACNTRY="(Denmark)";;
     es*) ACNTRY="(Spain)";;
     fi*) ACNTRY="(Finland)";;
     hu*) ACNTRY="(Hungary)";;
     ka*) ACNTRY="(Kazakhstan)";;
     ky*) ACNTRY="(Kyrgyzstan)";;
     et*) ACNTRY="(Estonia)";;
     lt*) ACNTRY="(Lithuania)";;
     mk*) ACNTRY="(Macedonia)";;
     sr*) ACNTRY="(Serbia)";;
     tr*) ACNTRY="(Turkey)";;
     tt*) ACNTRY="(Tatar)";;
     sg*) ACNTRY="(Swiss-German)";;
     ua*) ACNTRY="(Ukraine)";;
     gr*) ACNTRY="(Greece)";;
     il*) ACNTRY="(Israel)";;
     is*) ACNTRY="(Iceland)";;
     jp*) ACNTRY="(Japan)";;
     pc*) ACNTRY="(Japanese/English)";;
     la*) ACNTRY="(Latin_America)";;
     nl*) ACNTRY="(Netherlands)";;
     no*) ACNTRY="(Norway)";;
     pl*) ACNTRY="(Poland)";;
     pt*) ACNTRY="(Portugal)";;
     ro*) ACNTRY="(Romania)";;
     ru*) ACNTRY="(Russia)";;
     se*) ACNTRY="(Sweden)";;
     sv*) ACNTRY="(Sweden)";;
     sk*) ACNTRY="(Slovakia)";;
     sl*) ACNTRY="(Slovenia)";;
     uk*) ACNTRY="(UK)";;
     wangbe*) ACNTRY="(Belgium)";;
     azerty) ACNTRY="(Tandon)";;
     dvorak-r) ACNTRY="(Right_single-handed)";;
     dvorak-l) ACNTRY="(Left_single-handed)";;
     *)  ACNTRY="-";;
    esac
    if [ "$DEFAULTKMAP" = "$AKMAP" ];then
     echo "$AKMAP \"${ACNTRY}\" on" >> sandbox3/rootfs-complete/var/local/quickset-keyboard-list
    else
     echo "$AKMAP \"${ACNTRY}\" off" >> sandbox3/rootfs-complete/var/local/quickset-keyboard-list
    fi
   done


#190107 need this in host system...
if [ ! -d /usr/lib/locale/${DEFAULTLANG12}.utf8 ];then
 localedef -f UTF-8 -i ${DEFAULTLANG12} --no-archive ${DEFAULTLANG12}.utf8
fi
#190112 host needs latest translation files...
mkdir -p /usr/share/locale/${DEFAULTLANG1}
cp -a -f -u sandbox3/rootfs-complete/usr/share/locale/${DEFAULTLANG1}/* /usr/share/locale/${DEFAULTLANG1}/
for aSSS in boot_strings desk_strings doc_strings initrd_strings menu_strings script_strings
do
 if [ -f sandbox3/rootfs-complete/usr/share/sss/${aSSS}/${aSSS}.${DEFAULTLANG1} ];then
  cp -a -f -u sandbox3/rootfs-complete/usr/share/sss/${aSSS}/${aSSS}.${DEFAULTLANG1} /usr/share/sss/${aSSS}/
 fi
done

#110923 fix busybox applets...
if [ -d packages-${DISTRO_FILE_PREFIX}/busybox ];then #141123 buildroot build has busybox inside 0buildroot. refer FIXUPHACK in 0buildroot template.
 #160921 took 'strings' out of this list, as want the busybox strings...
 DEVXUTILS=' config ar ar86 as as86 audiofile-config autoconf autoheader autom4te automake autopoint autoreconf autoscan autoupdate bacon bacongui bcc bison c2ph catchsegv cc ccmake chem cmake combinediff config_data corelist cpack cpan cpan2dist cpanp cpanp-run-perl cpp ctest cups-config curl-config cvs cvsbug db_archive db_checkpoint db_deadlock db_dump db_hotbackup db_load db_printlog db_recover db_stat db_upgrade db_verify dehtmldiff diet dnsd dprofpp dvdnav-config dvdread-config editdiff elftrunc enc2xs envsubst eqn eqn2graph espdiff filterdiff find2perl fixcvsdiff flex flipdiff freetype-config gccbug gcov gdb gdbserver gdbtui gdiffmk gencat getconf getent gettext gettext.sh gettextize gfortran git git-cvsserver git-receive-pack git-shell git-upload-archive git-upload-pack gitk glade-3 gmake gnome-menu-spec-test gperf gphoto2-config gphoto2-port-config gprof grap2graph grepdiff grn grodvi groff groffer grog grolbp grolj4 grops grotty h2ph h2xs hpftodit iconv idle ifnames indxbib info infokey install-info instmodsh interdiff intltool-extract intltool-merge intltool-prepare intltool-update intltoolize ld ld86 ldd lddlibc4 lex lib-i386 libart2-config libnetcfg libpng-config libpng12-config libtool libtoolize libusb-config lkbib locale localedef lookbib lsdiff m4 make makeinfo man man1 man2dvi man2html mmroff msgattrib msgcat msgcmp msgcomm msgconv msgen msgexec msgfilter msgfmt msggrep msginit msgmerge msgunfmt msguniq mtrace nasm ndisasm neon-config neqn netpbm-config ngettext nm nm86 nroff objcopy objdump objdump86 onsgmls osgmlnorm ospam ospcat ospent osx patch pcap-config pcprofiledump pcre-config pdfroff pdftexi2dvi perl perlbug perldoc perlivp perlthanks pfbtops pic pic2graph piconv pkg-config pl2pm pod2html pod2latex pod2man pod2text pod2usage podchecker podselect post-grohtml pre-grohtml preconv prove psed pstruct ptar ptardiff pydoc ranlib rcs2log readelf recode-sr-latin recountdiff rediff refer rman roff2dvi roff2html roff2pdf roff2ps roff2text roff2x rpcgen s2p sane-config scrollkeeper-config scrollkeeper-extract scrollkeeper-gen-seriesid scrollkeeper-get-cl scrollkeeper-get-content-list scrollkeeper-get-extended-content-list scrollkeeper-get-index-from-docpath scrollkeeper-get-toc-from-docpath scrollkeeper-get-toc-from-id scrollkeeper-install scrollkeeper-preinstall scrollkeeper-rebuilddb scrollkeeper-uninstall scrollkeeper-update shasum size size86 soelim splain splitdiff sprof strace strace-graph strip svn svnadmin svndumpfilter svnlook svnserve svnsync svnversion sysprof sysprof-cli tbl texi2dvi texi2pdf texindex tfmtodit troff tzselect unwrapdiff update-mime-database vsyasm whatis xgettext xml2-config xslt-config xsubpp xtrace yacc yasm ytasm zsoelim iconvconfig makewhatis nscd rpcinfo visudo zic ' #11104 111204 remove zdump.
 cp -a -f packages-${DISTRO_FILE_PREFIX}/busybox/bin/busybox ./sandbox3/rootfs-complete/bin/
 osPTN="s%packages-${DISTRO_FILE_PREFIX}/busybox%%"
 for ONEAPPLET in `find packages-${DISTRO_FILE_PREFIX}/busybox -type l | tr '\n' ' '`
 do
  ONESPEC="`echo -n "$ONEAPPLET" | sed -e "$osPTN"`"
  ONEPATH="`dirname $ONESPEC`"
  ONENAME="`basename $ONESPEC`"
  FNDFULL="`find ./sandbox3/rootfs-complete/bin ./sandbox3/rootfs-complete/sbin ./sandbox3/rootfs-complete/usr/bin ./sandbox3/rootfs-complete/usr/sbin -name ${ONENAME}`"
  #130129 deb 'bsdmainutils' has broken 'cal' and 'hd' symlinks... 130204 01micko: fix for spaces in names...
  if [ "$FNDFULL" ];then
   if [ -h "$FNDFULL" ];then
    FULLPATH="$(dirname "$FNDFULL")"
    FULLLINK="$(readlink "$FNDFULL")"
    xFULLLINK="${FULLPATH}/${FULLLINK}"
    [ "`echo -n "$FULLLINK" | cut -c 1`" = "/" ] && xFULLLINK="sandbox3/rootfs-complete${FULLLINK}"
    if [ ! -e "${xFULLLINK}" ];then
     rm -f "$FNDFULL" #130130
     FNDFULL=""
    fi
   fi
  fi
  #111004 need to check in devx also...
  if [ ! "$FNDFULL" ];then
   if [ "$ONENAME" != "[" ];then
    if [ "$ONENAME" != "[[" ];then
     oaPTN=" ${ONENAME} "
     FNDFULL="`echo -n "$DEVXUTILS" | grep "$oaPTN"`"
    fi
   fi
  fi
  if [ "$FNDFULL" ];then
   #170806 need a hack here, as already created busybox applets above, when created
   #chrootable f.s. this code is getting a bit contorted. anyway, put in test...
   if [ ! -e ./sandbox3/rootfs-complete${ONEPATH}/${ONENAME} ];then
    cp -a -f $ONEAPPLET ./sandbox3/rootfs-complete${ONEPATH}/${ONENAME}-BB-NOTUSED
   fi
  else
   cp -a -f $ONEAPPLET ./sandbox3/rootfs-complete${ONEPATH}/
  fi
 done
 [ -f packages-${DISTRO_FILE_PREFIX}/busybox/pinstall.sh ] && cat packages-${DISTRO_FILE_PREFIX}/busybox/pinstall.sh >> sandbox3/pinstall.sh
fi

echo 'echo "END OF pinstall.sh SCRIPT."' >> sandbox3/pinstall.sh

#171217 have moved this up, as these get written to in pinstall.sh...
#170826 have these in rootfs-skeleton, make sure override ones in rox pet...
cp -a -f rootfs-skeleton/root/Choices/ROX-Filer/PuppyPin sandbox3/rootfs-complete/root/Choices/ROX-Filer/
cp -a -f rootfs-skeleton/root/Choices/ROX-Filer/globicons sandbox3/rootfs-complete/root/Choices/ROX-Filer/

chmod 755 sandbox3/pinstall.sh

#run post-install script...
echo
echo "Executing sandbox3/pinstall.sh post-install script..."
cd $WKGDIR/sandbox3/rootfs-complete
SAVEWKGDIR="$WKGDIR"
$WKGDIR/sandbox3/pinstall.sh
echo "If you did not get 'End of pinstall.sh' message above, then"
echo -n "it aborted before completion. Press ENTER or CTRL-C: "
read isitbad
WKGDIR="$SAVEWKGDIR"
cd $WKGDIR

if [ "$DISTRO_KERNEL_PET" == "" ];then #160824
 cd sandbox3 #160824
else
 #now do the kernel...
 echo
 echo "Now installing the kernel and modules into rootfs-complete/..."
 rm -f sandbox3/$KERNELPKG
 KERNPKGNAMEONLY="`basename $KERNELPKG .pet`"
 rm -rf sandbox3/$KERNPKGNAMEONLY
 cp packages-pet/${KERNELPKG} sandbox3/
 cd sandbox3
 pet2tgz $KERNELPKG
 tar -zxf $KERNPKGNAMEONLY.tar.gz
 cp -a --remove-destination $KERNPKGNAMEONLY/* rootfs-complete/
 
 if [ -d ../kernel-skeleton ];then #170128
  #100603 i'm now putting common kernel files in here...
  cp -a -f ../kernel-skeleton/* rootfs-complete/
  #110918 kernel-skeleton now has a pinstall.sh script...
  cd rootfs-complete
  ./pinstall.sh
  sync
  rm -f ./pinstall.sh
  cd ..
 fi
 [ -f rootfs-complete/etc/modules/firmware.dep ] && mv -f rootfs-complete/etc/modules/firmware.dep rootfs-complete/etc/modules/firmware.dep.${KERNELVER}
fi #160824

#170325 pi2 skeleton image has this... 170331
if [ -f img_mntpt/skel2.sfs ];then
 mkdir -p skel2_mntpt
 busybox mount -t squashfs -o loop,noatime img_mntpt/skel2.sfs skel2_mntpt
 cp -a -f --remove-destination skel2_mntpt/* rootfs-complete/
 sync
 busybox umount skel2_mntpt
 rmdir skel2_mntpt
 rm -f img_mntpt/skel2.sfs
fi

#170520 oe build, vmlinuz is a symlink...
VMLINUZ=''; SYSMAP=''
[ -e rootfs-complete/boot/vmlinuz ] && VMLINUZ="vmlinuz"
[ -h rootfs-complete/boot/vmlinuz ] && VMLINUZ="$(readlink rootfs-complete/boot/vmlinuz)"
[ -e rootfs-complete/boot/System.map ] && SYSMAP="System.map"
[ -h rootfs-complete/boot/System.map ] && SYSMAP="$(readlink rootfs-complete/boot/System.map)"
[ "$SYSMAP" ] && mv -f rootfs-complete/boot/${SYSMAP} ./System.map
[ "$VMLINUZ" ] && mv -f rootfs-complete/boot/${VMLINUZ} ./vmlinuz
KERNELNAME=vmlinuz #180904
if [ -f rootfs-complete/boot/kernel8.img ];then #180904 rpi3
 mv -f rootfs-complete/boot/kernel8.img ./
 KERNELNAME='kernel8.img'
fi
if [ -f rootfs-complete/boot/Image ];then #190131 rock64
 mv -f rootfs-complete/boot/Image ./
 KERNELNAME='Image'
fi
rm -rf rootfs-complete/boot

if [ "$DISTRO_KERNEL_PET" != "" ];then #160824 ###########
 #110722 need this, to put into woof-installed-packages...
 KERNEL_DB_ENTRY="`cat rootfs-complete/pet.specs`"
fi #160824 #############
rm -f rootfs-complete/pet.specs

#arch .INSTALL files
#130316 NOTE: maybe could do this without chroot, as for slackware in 2createpackages (see 2createpackages-hack-install.sh).
# ok, I have looked through all pkgs used in build, most .INSTALL are trivial. these are slight exceptions: 
#  cmake glibc_dev_DEV libglade2 libwmf man_DEV openldap perl_DEV subversion_DEV
# but, don't really need to execute those either. besides, the code below is only operating upon rootfs-complete, it would be better
# to aufs mount the devx, as is done in sandbox2b in 2createpackages. comment out all of below...
if [ "${DISTRO_BINARY_COMPAT}" = "arch" ]; then
 rm -f rootfs-complete/.INSTALL*
# numberOfDotInstall=1
# for FOLDER in `ls -1 ${WKGDIR}/packages-${DISTRO_FILE_PREFIX} | tr '\n' ' '` #130307
# do
#  [ ! -f ${WKGDIR}/packages-${DISTRO_FILE_PREFIX}/${FOLDER}/.INSTALL ] && continue
#  PKGVER="`grep -e '^pkgver' "${WKGDIR}/packages-${DISTRO_FILE_PREFIX}/${FOLDER}/.PKGINFO" | sed 's/^pkgver\ =\ //' | sed 's/-[^-]//'`"
#  cp ${WKGDIR}/packages-${DISTRO_FILE_PREFIX}/${FOLDER}/.INSTALL "rootfs-complete/.INSTALL${numberOfDotInstall}-${PKGVER}"
#  let numberOfDotInstall++
# done
# if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #130316
#  cp ${WKGDIR}/support/arch/runDotInstalls rootfs-complete/
#  chroot "${PWD}/rootfs-complete" "/runDotInstalls" &> /dev/null
#  rm -f rootfs-complete/runDotInstalls
# else
#  echo "Unfortunately, cannot execute Arch install scripts, as this is a cross-build."
# fi
# rm -f rootfs-complete/.INSTALL*
fi
#130314 want to run arch post-install script from ppm also...
mkdir -p rootfs-complete/usr/local/petget
cp ${WKGDIR}/support/arch/runDotInstalls rootfs-complete/usr/local/petget/ArchRunDotInstalls
chmod 755 rootfs-complete/usr/local/petget/ArchRunDotInstalls

#190107 non-english build... 190111 moved up.
if [ "$DEFAULTLANG1" != "en" ];then
 echo "EXECUTING: chroot rootfs-complete localedef -f UTF-8 -i ${DEFAULTLANG12} --no-archive ${DEFAULTLANG12}.utf8"
 chroot rootfs-complete localedef -f UTF-8 -i ${DEFAULTLANG12} --no-archive ${DEFAULTLANG12}.utf8
fi

#190107 copy langpack if exists...
cd ..
if [ "$DEFAULTLANG1" != "en" ];then
 LANGPACK="$(grep "^langpack_${DEFAULTLANG1}\-[0-9]" Packages-pet-noarch-official | tail -n 1 | cut -f 1 -d '|')" #190114 fix.
 if [ ! "$LANGPACK" ];then
  echo "WARNING: there is no 'langpack_${DEFAULTLANG1}' PET in the 'noarch' database."
  echo "This will mean a somewhat incomplete translation."
 else
  if [ ! -f packages-pet/${LANGPACK}.pet ];then
   echo "ERROR: packages-pet/${LANGPACK}.pet does not exist."
   echo -n "Please obtain it, then press ENTER key to continue: "
   read waitforlp
  fi
  if [ ! -f packages-pet/${LANGPACK}.pet ];then
   echo "WARNING: proceeding without installing ${LANGPACK}.pet"
  else
   cp -f packages-pet/${LANGPACK}.pet sandbox3/
   cd sandbox3
   [ -d ./${LANGPACK} ] && rm -rf ./${LANGPACK}
   pet2dir ${LANGPACK}.pet
   echo "Copying ${LANGPACK} contents into rootfs-complete..."
   #mv -f ${LANGPACK}/pinstall.sh ${LANGPACK}/pinstall.shLP
   rm -f ${LANGPACK}/pinstall.sh #190115 see below.
   [ -f ${LANGPACK}/pinstall_hacks.sh ] && rm -f ${LANGPACK}/pinstall_hacks.sh #de: cannot run, as has absolute paths.
   [ -d ${LANGPACK}/archive ] && rm -rf ${LANGPACK}/archive
   for aAPP in `find ${LANGPACK}/usr/local/apps -mindepth 1 -maxdepth 1 -type d | tr '\n' ' '`
   do
    bAPP="$(basename $aAPP)"
    [ ! -d rootfs-complete/usr/local/apps/${bAPP} ] && rm -rf ./${aAPP}
   done
   cat ${LANGPACK}/pet.specs >> rootfs-complete/root/.packages/woof-installed-packages
   #190115 rename all AppInfo.xml to AppInfo.xml.in ... 190119 hide err.
   for aAI in `ls -1 ${LANGPACK}/usr/local/apps/*/AppInfo.xml 2>/dev/null | tr '\n' ' '`
   do
    if [ -f ${aAI}.in ];then #precaution
     rm -f ./${aAI}
     continue
    fi
    mv -f ./${aAI} ${aAI}.in
   done
   #190115 also need the latest pinstall.sh to process those *.in files...
   cp -f ../rootfs-skeleton/usr/share/doc/langpack-template/pinstall.sh ${LANGPACK}/pinstall.shLP
   #rm -f ${LANGPACK}/pet.specs
   cp -a -f --remove-destination ${LANGPACK}/* rootfs-complete/
   cd rootfs-complete
   sed -i -e 's%pupdialog%#pupdialog%' pinstall.shLP #remove popup.
   #NEWLANG="`grep '^LANG=' etc/profile | cut -f 2 -d '=' | cut -f 1 -d ' '`" #190713
   sed -i -e "s%TARGETLANG%${DEFAULTLANG1}%g" pinstall.shLP #190713 substitution reqd
   ./pinstall.shLP
   cd ../../
   rm -f sandbox3/rootfs-complete/pet.specs #190110 keep until after exec pinstall.shLP
   rm -f sandbox3/rootfs-complete/pinstall.shLP
   #190115 rootfs-skeleton has .pot files, there may also be some in langpack...
   for aPOT in `find rootfs-skeleton -mindepth 1 -type f -name '*.pot' | grep -v ' ' | cut -f 2- -d '/'`
   do
    [ "$aPOT" == "" ] && continue
    aCUT="$(dirname $aPOT)"
    cp -a -f --remove-destination rootfs-skeleton/${aPOT} sandbox3/rootfs-complete/${aCUT}/
   done
  fi
 fi
fi
#190107 copy package translations...
echo "Copying package translations..."
DEFAULTLANG12="${DEFAULTLANG%.*}"
mkdir -p sandbox3/rootfs-complete/usr/share/locale/${DEFAULTLANG1}
echo "  ${DEFAULTLANG1}"
cp -a -f packages-${DISTRO_FILE_PREFIX}/*_NLS/usr/share/locale/${DEFAULTLANG1}/LC_MESSAGES sandbox3/rootfs-complete/usr/share/locale/${DEFAULTLANG1}/
LANGDIRS="$(find packages-${DISTRO_FILE_PREFIX}/*_NLS/usr/share/locale -mindepth 1 -maxdepth 1 -type d -name "${DEFAULTLANG1}_*" | rev | cut -f 1 -d '/' | rev | sort -u | tr '\n' ' ')"
for aLANGDIR in $LANGDIRS
do
 echo "  ${aLANGDIR}"
 mkdir -p sandbox3/rootfs-complete/usr/share/locale/${aLANGDIR}
 cp -a -f packages-${DISTRO_FILE_PREFIX}/*_NLS/usr/share/locale/${aLANGDIR}/LC_MESSAGES sandbox3/rootfs-complete/usr/share/locale/${aLANGDIR}/
done
#190108 find more translation files...
echo 'finding more translation files...'
NLSFILES="$(find packages-${DISTRO_FILE_PREFIX}/*_NLS -mindepth 1 -maxdepth 7 -type f -name "*[-_.]${DEFAULTLANG1}[-_.]*" -o -name "${DEFAULTLANG1}[-_.]*" -o -name "*[-_.]${DEFAULTLANG1}" | grep -v ' ')"
for aNLSFILE in $NLSFILES
do
 [ "$aNLSFILE" == "" ] && continue
 [ "$(echo -n "$aNLSFILE" | grep "NLS/usr/share/locale/")" != "" ] && continue
 aCUTDIR="$(dirname $aNLSFILE | cut -f 3- -d '/')"
 mkdir -p sandbox3/rootfs-complete/${aCUTDIR}
 echo -n '.'
 cp -a -f --remove-destination $aNLSFILE sandbox3/rootfs-complete/${aCUTDIR}/
done
echo
#190112 libreoffice has .mo files, find these and maybe others...
echo "Finding more .mo files..."
MOFILES="$(find packages-${DISTRO_FILE_PREFIX}/*_NLS -mindepth 1 -maxdepth 7 -type f -name '*.mo' | grep -E "/${DEFAULTLANG1}/|/${DEFAULTLANG1}_[A-Z]*/" | grep -v ' ')"
for aMOFILE in $MOFILES
do
 [ "$aMOFILE" == "" ] && continue
 [ "$(echo -n "$aMOFILE" | grep "NLS/usr/share/locale/")" != "" ] && continue
 aCUTDIR="$(dirname $aMOFILE | cut -f 3- -d '/')"
 mkdir -p sandbox3/rootfs-complete/${aCUTDIR}
 echo -n '.'
 cp -a -f --remove-destination ${aMOFILE} sandbox3/rootfs-complete/${aCUTDIR}/
done
echo
#190110 hunspell dictionary for non-english...
if [ "$DEFAULTLANG1" != "en" ];then
 echo "Installing non-english hunspell dictionary..."
 HSPETS="$(grep "^hunspell-${DEFAULTLANG1}\-" Packages-pet-noarch-official | cut -f 1 -d '|')" #maybe more than one.
 if [ ! "$HSPETS" ];then
  echo "WARNING: there is no 'hunspell-${DEFAULTLANG1}' PET in the 'noarch' database."
  echo "This will mean a somewhat incomplete translation."
 else
  for aHSPET in $HSPETS
  do
   [ "$aHSPET" == "" ] && continue
   if [ ! -f packages-pet/${aHSPET}.pet ];then
    echo "ERROR: packages-pet/${aHSPET}.pet does not exist."
    echo -n "Please obtain it, then press ENTER key to continue: "
    read waitforlp
   fi
   if [ ! -f packages-pet/${aHSPET}.pet ];then
    echo "WARNING: proceeding without installing ${aHSPET}.pet"
   else
    cp -f packages-pet/${aHSPET}.pet sandbox3/
    cd sandbox3
    [ -d ./${aHSPET} ] && rm -rf ./${aHSPET}
    pet2dir ${aHSPET}.pet
    echo "Copying ${aHSPET} contents into rootfs-complete..."
    mv -f ${aHSPET}/pinstall.sh ${aHSPET}/pinstall.shHS
    cat ${aHSPET}/pet.specs >> rootfs-complete/root/.packages/woof-installed-packages
    rm -f ${aHSPET}/pet.specs
    cp -a -f --remove-destination ${aHSPET}/* rootfs-complete/
    cd rootfs-complete
    LANG="$DEFAULTLANG" ./pinstall.shHS #post-install script. 190713
    cd ..
    rm -f rootfs-complete/pinstall.shHS
    cd ..
    rm -rf sandbox3/${aHSPET}
   fi
  done
 fi
fi
#190110 need to sort sandbox3/rootfs-complete/root/.packages/woof-installed-packages
if [ "$DEFAULTLANG1" != "en" ];then
 #sort alphabetically...
 sort --key=1 --field-separator="|" sandbox3/rootfs-complete/root/.packages/woof-installed-packages > /tmp/petget_woof-installed-packages
 mv -f /tmp/petget_woof-installed-packages sandbox3/rootfs-complete/root/.packages/woof-installed-packages
fi
#190110 translate home.htm, welcome.htm, help.htm...
if [ "$DEFAULTLANG1" != "en" ];then
 echo "Translating home.htm, welcome.htm, help.htm..."
 if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then
  LANG=${DEFAULTLANG} chroot sandbox3/rootfs-complete /usr/share/doc/easy/help.sh
  LANG=${DEFAULTLANG} chroot sandbox3/rootfs-complete /usr/share/doc/easy/home.sh
  LANG=${DEFAULTLANG} chroot sandbox3/rootfs-complete /usr/share/doc/easy/welcome.sh
 else
  #have to do it in the host...
  LANG=${DEFAULTLANG} /usr/share/doc/easy/help.sh
  LANG=${DEFAULTLANG} /usr/share/doc/easy/home.sh
  LANG=${DEFAULTLANG} /usr/share/doc/easy/welcome.sh
  cp -a -f --remove-destination /usr/share/doc/easy/*.htm sandbox3/rootfs-complete/usr/share/doc/easy/
  ln -snf home_${LANG%_*}.htm /usr/share/doc/easy/home.htm  #restore
  ln -snf home_${LANG%_*}.htm /usr/share/doc/easy/help.htm
  ln -snf home_${LANG%_*}.htm /usr/share/doc/easy/welcome.htm
 fi 
fi
cd sandbox3
#190107 also have to translate boot-partition, mounted at img_mntpt. done below, line 3609...
#190113 also have to download and install seamonkey language-pack. done below...

if [ "$BUILD_CHOICE_TRUE_SCSI_KERNEL_DRIVERS" = "" ];then #150122
 #w462 true-scsi drives
 echo
 echo "Would you like the distro to be able to recognise and even boot from"
 echo "old true-SCSI hard drives and CD drives?"
 echo "Most likely you would just press the ENTER key only to decline, as the"
 echo "vast majority of PCs do not have true-SCSI hardware. However, 10-20 years"
 echo "ago it was popular in network server computers."
 echo "Note, really old pre-PCI computers will not be supported at all."
 echo -n "Enter only to decline, any other key to keep SCSI drivers: "
 read wantscsi
 BUILD_CHOICE_TRUE_SCSI_KERNEL_DRIVERS="delete"
 [ "$wantscsi" != "" ] && BUILD_CHOICE_TRUE_SCSI_KERNEL_DRIVERS="keep" 
fi

if [ "$DISTRO_KERNEL_PET" != "" ];then #160824 #############
 #130613 kmod depmod wants these two... they are moved in later, but do it here also...
 mkdir -p rootfs-complete/lib/modules/$KERNELVER
 [ -f rootfs-complete/etc/modules/modules.builtin ] && cp -a -f rootfs-complete/etc/modules/modules.builtin rootfs-complete/lib/modules/$KERNELVER/
 [ -f rootfs-complete/etc/modules/modules.order ] && cp -a -f rootfs-complete/etc/modules/modules.order rootfs-complete/lib/modules/$KERNELVER/
 
 #110712 modinfo won't work if modules.* files missing...
 #130418 if kmod, do not use busybox depmod...
 USINGKMOD='no'
 [ "`grep '^kmod' ../woof-installed-packages`" != "" ] && USINGKMOD='yes'
 [ "$DISTRO_BINARY_COMPAT" == "buildroot" ] && USINGKMOD='yes' #141118
 if [ "$USINGKMOD" == "no" ];then
  cp -f ../boot/depmod ./
  if [ ! -f rootfs-complete/lib/modules/$KERNELVER/modules.dep ];then
   busybox depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  fi
 else
  cp -f ../boot/kmod ./
  ln -snf kmod depmod
  if [ ! -f rootfs-complete/lib/modules/$KERNELVER/modules.dep ];then
   ./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  fi
 fi
 
 if [ "$CHOICE_BIGMODEM" != "Erase_big_modems" ];then #v431
 # INTELMODEMMOD="`find rootfs-complete/lib/modules/${KERNELVER} -type f -iname intel5*ko*`"
  INTELMODEMMOD="`find rootfs-complete/lib/modules/${KERNELVER} -type f -iname 'intel5*ko' -o -iname 'intel5*HIDE'`" #101222
  if [ "$INTELMODEMMOD" != "" ];then
   echo
   if [ "$CHOICE_BIGMODEM" ];then
    echo "You already selected what to do with the \"big modems\", however, this"
    echo "question is specifically about the Intel 536 and 537 analog modems, that"
    echo "are enormous and you might want to delete them, independently of the"
    echo "choice already made for the big modems."
   else
    echo "The next question will ask what to do with the \"big modems\", however, this"
    echo "question is specifically about the Intel 536 and 537 analog modems, that"
    echo "are enormous and you might want to delete them, independently of the"
    echo "choise that will be made next for the big modems."
   fi
   echo
   echo "Would you like to remove the Intel 536 and 537 analog modem modules?"
   echo "These are an enormous waste of space (1MB - 18MB uncompressed) if you"
   echo "don't have one of those particular old modem dialup cards."
   echo -n "Press ENTER only to delete them: "
   read DELINTEL
   if [ "$DELINTEL" = "" ];then
    for ONEMODEM in $INTELMODEMMOD
    do
     echo "Removing $ONEMODEM"
     rm -f $ONEMODEM
    done
   fi
  fi
 fi
 
 #140119 erase-big-modems code removed.
 
 if [ "$BUILD_CHOICE_FB_KERNEL_DRIVERS" = "" ];then
  #w481 remove framebuffer modules...
  echo
  echo "The kernel is configured with the vesafb driver builtin, which is usually enough"
  echo "if it is ever required to boot in framebuffer video mode. The other framebuffer"
  echo "modules take up about 1.4MB uncompressed and are not normally required."
  echo -n "Press ENTER only to delete the other framebuffer modules: "
  read DELFBM
  BUILD_CHOICE_FB_KERNEL_DRIVERS="keep"
  [ "$DELFBM" = "" ] && BUILD_CHOICE_FB_KERNEL_DRIVERS="delete"
 fi
 
 if [ "$BUILD_CHOICE_FB_KERNEL_DRIVERS" == "delete" ];then
  #130430 gpu/drm/sis.ko needs sisfb.ko, must keep...
  echo
  echo "Deleting framebuffer modules..."
  find rootfs-complete/lib/modules/$KERNELVER/kernel/drivers/video -type f -name '*fb.ko' -o -name '*fb_*.ko' |
  while read ONEMODULE
  do
   ONEBASE="`basename $ONEMODULE`"
   [ "$ONEBASE" = "sisfb.ko" ] && continue #130430
   #160323 drivers/video.fbdev/core has fb_sys_ops.ko (needed by i915.ko) and fb_ddc.ko -- must keep...
   [ "${ONEBASE:0:2}" == "fb" ] && continue #160323
   echo -n "$ONEBASE "
   rm -f $ONEMODULE
  done
  echo
 fi
 
 if [ "$BUILD_CHOICE_EXOTIC_KERNEL_DRIVERS" = "" ];then
  echo
  echo "A bit later in the script you will be asked if you would like to cut the modules"
  echo "right down to a fairly basic selection. However, for now you can choose a minor"
  echo "cutdown of some 'exotic' modules that are unlikely to be needed."
  echo "Press any printable character to to remove 'exotic' modules, or"
  echo -n "press ENTER only to keep them: "
  read keepexotic
  BUILD_CHOICE_EXOTIC_KERNEL_DRIVERS="delete"
  [ "$keepexotic" = "" ] && BUILD_CHOICE_EXOTIC_KERNEL_DRIVERS="keep"
 fi
 
 if [ "$BUILD_CHOICE_EXOTIC_KERNEL_DRIVERS" == "delete" ];then
  echo
  echo "Deleting exotic modules..."
  #v423 nfs.ko needs sunrpc.ko and lockd.ko... nfsd.ko needs exportfs.ko...
  #v423 someone is working on autofs, so bring that back too...
  #EXOTICFS=' fs/autofs fs/autofs4 fs/befs fs/bfs fs/coda fs/cramfs fs/exportfs fs/freevxfs fs/jffs2 fs/jfs fs/lockd fs/ncpfs fs/romfs fs/sysv '
  #EXOTICNET=' net/appletalk net/ipv6 net/ipx net/llc net/sunrpc net/wanrouter '
  EXOTICFS=' fs/befs fs/bfs fs/coda fs/cramfs fs/freevxfs fs/jffs2 fs/jfs fs/ncpfs fs/romfs fs/sysv '
  EXOTICNET=' net/appletalk net/ipv6 net/ipx net/llc net/wanrouter '
  EXOTICDRIVERS=' drivers/block/paride drivers/block/aoe drivers/mtd drivers/telephony '
  for ONEDIR in $EXOTICFS $EXOTICNET $EXOTICDRIVERS
  do
   if [ -d rootfs-complete/lib/modules/$KERNELVER/kernel/$ONEDIR ];then
    echo -n "$ONEDIR "
    rm -rf rootfs-complete/lib/modules/$KERNELVER/kernel/$ONEDIR
   fi
  done
  sync
  echo
 fi
 
 
 if [ "$BUILD_CHOICE_TRUE_SCSI_KERNEL_DRIVERS" == "delete" ];then #150122
  #get rid of scsi modules except some essentials...
  rm -rf /tmp/scsi-keep
  mkdir /tmp/scsi-keep
  for ONEKEEP in imm.ko ppa.ko raid_class.ko sg.ko scsi_wait_scan.ko
  do
   ONEFND="`find rootfs-complete/lib/modules/$KERNELVER/kernel/drivers/scsi -type f -name $ONEKEEP`"
   [ "$ONEFND" ] && cp -a $ONEFND /tmp/scsi-keep/
  done
  rm -rf rootfs-complete/lib/modules/$KERNELVER/kernel/drivers/scsi
  cp -a /tmp/scsi-keep rootfs-complete/lib/modules/$KERNELVER/kernel/drivers/scsi
 fi
 
 
 #w091029 use busybox depmod, creates smaller modules* files...
 if [ "$USINGKMOD" == "no" ];then #130418
  cp -f ../boot/depmod ./
  #./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  busybox depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
 else
  #180903 cp -f ../boot/depmod ./depmod.veryold
  cp -f ../boot/kmod ./kmod
  ln -snf kmod depmod
  ./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
 fi
 sync
fi #160824 ##########

#170625 set KERNELVER
if [ "$KERNELVER" == "" ];then
 KERNELVER="$(find rootfs-complete/lib/modules -mindepth 1 -maxdepth 1 -type d | head -n 1 | rev | cut -f 1 -d '/' | rev)"
fi
#170624 oe pyro, no kernel pet, using kernel built in oe...
if [ ! -e depmod ];then
 cp -f ../boot/kmod ./
 ln -snf kmod depmod
 if [ "$KERNELVER" ];then #170625
  if [ ! -f rootfs-complete/lib/modules/$KERNELVER/modules.dep ];then
   ./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  fi
 fi
fi

#101027 Iguleder reported DISTRO_SPECS did not have a carriage-return on last line...
xDISTROSPECS="`cat rootfs-complete/etc/DISTRO_SPECS`"
echo "$xDISTROSPECS" > rootfs-complete/etc/DISTRO_SPECS


#120225 this is read by /usr/share/doc/convert-raw-docs...
DISTRO_PUPPYDATE="`date | tr -s " " | cut -f 2,6 -d " "`"
echo "DISTRO_PUPPYDATE='${DISTRO_PUPPYDATE}'" >> rootfs-complete/etc/DISTRO_SPECS


DEVTMPFSFLG=0
if [ "$DISTRO_KERNEL_PET" != "" ];then #160824 #############
 #130618 check udev version... 130710 01micko: fix...
 #130612 if kernel has CONFIG_DEVTMPFS=y (and CONFIG_DEVTMPFS_MOUNT=y) then empty /dev...
 if [ "`grep 'CONFIG_DEVTMPFS.*=y' rootfs-complete/etc/modules/DOTconfig*`" != "" ];then
  UDEV3=`grep -E '^[e]*udev[_-][0-9]' ../woof-installed-packages | cut -f 3 -d '|' | cut -c 1-3 | head -n 1` #141206
  [ ! $UDEV3 ] && UDEV3=200 #eudev
  [ "$(echo -n "$UDEV3"| grep -F '.')" != "" ] && UDEV3=200 #141206 eudev may actually be named udev, and has 1.x version.
  if [ $UDEV3 -ge 176 ];then #175 is last version that creates device nodes.
   DEVTMPFSFLG=2 #see further down.
  fi
 fi
fi #160824 ###############
sync

if [ "$DISTRO_KERNEL_PET" != "" ];then #160824 #############
 #offer to cutdown the modules, to build a smaller live-cd...
 rm -rf zdrv 2>/dev/null #note, current dir is in sandbox3.
 rm -f ${ZDRVPET} #100911 zdrv.sfs
 
 if [ "$BUILD_CHOICE_RADICAL_KERNEL_DRIVERS" = "" ];then
  echo
  echo -n "Press any char for radical cutdown of modules, or ENTER only to retain all: "
  read cutthemdown
  BUILD_CHOICE_RADICAL_KERNEL_DRIVERS="delete"
  [ "$cutthemdown" = "" ] && BUILD_CHOICE_RADICAL_KERNEL_DRIVERS="keep"
 fi
 
 if [ "$BUILD_CHOICE_RADICAL_KERNEL_DRIVERS" == "delete" ];then
  if [ "$USINGKMOD" = "no" ];then #130418
   busybox depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  else
   ./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  fi
  cd rootfs-complete/lib/modules/$KERNELVER #makes it easier to handle find results.
  #create a list of essential modules...
  echo "Creating must-have lists..."
  SOUNDMODS="`find ./kernel/sound/ -type f | sed -e 's/^\.\///g'`" #want all the alsa sound mods.
  IPV4MODS="`find ./kernel/net/ipv4 -type f | sed -e 's/^\.\///g'`" #want all the firewall mods.
  NETFILTERMODS="`find ./kernel/net/netfilter -type f | sed -e 's/^\.\///g'`"
  #IEEE80211MODS="`find ./kernel/net/ieee80211 -type f | sed -e 's/^\.\///g'`" #want all the ieee80211 mods.
  IEEE80211MODS="`find ./kernel/net/wireless -type f | sed -e 's/^\.\///g'`" #want all the wireless 80211 mods.
  RFKILLMODS="`find ./kernel/net/rfkill -type f | sed -e 's/^\.\///g'`"
  MAC80211MODS="`find ./kernel/net/mac80211 -type f | sed -e 's/^\.\///g'`"
  WIMAXMODS="`find ./kernel/net/wimax -type f | sed -e 's/^\.\///g'`"
  NETWORKMODS="`find ./kernel/drivers/net -type f | grep -vE '/wan/|/appletalk/' | sed -e 's/^\.\///g'`" #want all the network interface drivers.
  UBUNTUMODS=""
  [ -d ./kernel/ubuntu ] && UBUNTUMODS="`find ./kernel/ubuntu -type f | grep -vE '/compcache/|/gnbd/|/heci/|/lirc/' | sed -e 's/^\.\///g'`"
  MMCMODS="`find ./kernel/drivers/mmc -type f | sed -e 's/^\.\///g'`" #include mmc/sd host drivers.
  MEMSTICKMODS="`find ./kernel/drivers/memstick -type f | sed -e 's/^\.\///g'`"
  MISCMODS="`find ./kernel/drivers/misc -type f | sed -e 's/^\.\///g'`"
  USBMODS="`find ./kernel/drivers/usb -type f | sed -e 's/^\.\///g'`"
  ACPIMODS="`find ./kernel/drivers/acpi -type f | sed -e 's/^\.\///g'`"
  AGPMODS="`find ./kernel/drivers/char/agp -type f | sed -e 's/^\.\///g'`"
  I2CMODS="`find ./kernel/drivers/i2c -type f | sed -e 's/^\.\///g'`"
  PLATFORMMODS="`find ./kernel/drivers/platform -type f | sed -e 's/^\.\///g'`"
  BLUETOOTHMODS="`find ./kernel/drivers/bluetooth -type f | sed -e 's/^\.\///g'`"
  #w475 k2.6.29.3 has these usb webcam drivers...
  GSPCAMODS=""
  [ -d ./kernel/drivers/media/video/gspca ] && GSPCAMODS="`find ./kernel/drivers/media/video/gspca -type f | sed -e 's/^\.\///g'`"
  #k2.6.25.16: kernel/drivers/char/drm, k2.6.27.4: kernel/drivers/gpu/drm...
  DRMMODS="`find ./kernel/drivers -type f | grep '/drm/' | sed -e 's/^\.\///g'`"
  USBMODEMLIST="cdc-acm.ko pl2303.ko nozomi.ko hso.ko option.ko sierra.ko"
  ANALOGMODEMLIST="mwave.ko martian_dev.ko pctel.ko ltserial.ko slamr.ko slusb.ko esscom.ko"
  CPUSCALING2MODS="`find ./kernel/drivers/cpufreq -type f | sed -e 's/^\.\///g'`" #100127
  CPUSCALINGMODS="`find ./kernel/arch/x86/kernel/cpu/cpufreq -type f | sed -e 's/^\.\///g'`" #v431
  CRYPTOMODS="`find ./kernel/crypto -type f | sed -e 's/^\.\///g'`" #100126
  FBCONMODS="`find ./kernel/drivers/video/console -type f | sed -e 's/^\.\///g'`" #110518
  #create a list of extra modules... w476 added nls_cp850.ko nls_cp852.ko...
  EXTRALIST="blkcipher.ko cbc.ko apm.ko cdrom.ko mwave.ko synclink_cs.ko serial_cs.ko lp.ko n_hdlc.ko nvram.ko sonypi.ko generic_serial.ko agpgart.ko ali-agp.ko amd-k7-agp.ko amd64-agp.ko ati-agp.ko intel-agp.ko nvidia-agp.ko sis-agp.ko sworks-agp.ko via-agp.ko blowfish.ko aes.ko arc4.ko crc32c.ko deflate.ko des.ko md5.ko sha1.ko cramfs.ko ext3.ko fat.ko fuse.ko isofs.ko jbd.ko lockd.ko minix.ko msdos.ko nfs.ko nls_cp437.ko nls_cp850.ko nls_cp852.ko nls_iso8859-1.ko nls_iso8859-13.ko nls_iso8859-14.ko nls_iso8859-15.ko nls_iso8859-2.ko nls_iso8859-3.ko nls_iso8859-4.ko nls_iso8859-5.ko nls_iso8859-6.ko nls_iso8859-7.ko nls_iso8859-8.ko nls_iso8859-9.ko nls_utf8.ko ntfs.ko reiserfs.ko smbfs.ko squashfs.ko udf.ko unionfs.ko vfat.ko i2c-core.ko i2c-algo-bit.ko ide-cs.ko ide-tape.ko ide-cd.ko ide-floppy.ko gameport.ko analog.ko pcigame.ko pcspkr.ko psmouse.ko sermouse.ko serport.ko serio.ko evdev.ko joydev.ko input.ko keybdev.ko mousedev.ko crc32.ko crc-ccitt.ko libcrc32c.ko zlib_deflate.ko firmware_class.ko parport_pc.ko parport_serial.ko parport.ko parport_cs.ko i82365.ko pd6729.ko tcic.ko yenta_socket.ko i82092.ko rsrc_nonstatic.ko pcmcia_core.ko ds.ko imm.ko scsi_mod.ko scsi_transport_spi.ko sd_mod.ko sg.ko sr_mod.ko ide-scsi.ko scsi_debug.ko scsi_transport_fc.ko cdc-acm.ko usb-midi.ko usblp.ko audio.ko bluetty.ko usbcore.ko sl811-hcd.ko uhci-hcd.ko ehci-hcd.ko ohci-hcd.ko uhci.ko usb-ohci.ko usb-uhci.ko usbkbd.ko usbhid.ko hid.ko usbmouse.ko usbnet.ko ir-usb.ko usbserial.ko usb-storage.ko scanner.ko printer.ko fan.ko ibm_acpi.ko ac.ko battery.ko processor.ko thermal.ko paride.ko cryptoloop.ko pktcdvd.ko floppy.ko loop.ko 8250_pnp.ko serial_core.ko 8250.ko 8250_pci.ko ndiswrapper.ko ungrab-winmodem.ko cifs.ko ssb.ko pl2303.ko aufs.ko serio_raw.ko ecb.ko output.ko"
  #FBMODS="intelfb.ko rivafb.ko sisfb.ko fbcon-vga-planes.ko fbcon-mfb.ko fbgen.ko mdacon.ko neofb.ko tridentfb.ko vgastate.ko vga16fb.ko "
  EXTRAMODS=""
  for ONEMOD in $EXTRALIST $USBMODEMLIST #$ANALOGMODEMLIST
  do
   ONEFND="`find ./ -type f -name $ONEMOD | sed -e 's/^\.\///g'`"
   if [ "$ONEFND" != "" ];then
    EXTRAMODS="$EXTRAMODS
$ONEFND"
   fi
  done
  cd ../../../../ #back into sandbox3.
  CHOSENMODS="$SOUNDMODS
 $IPV4MODS
 $NETFILTERMODS
 $IEEE80211MODS
 $RFKILLMODS
 $MAC80211MODS
 $WIMAXMODS
 $NETWORKMODS
 $UBUNTUMODS
 $MMCMODS
 $MEMSTICKMODS
 $MISCMODS
 $USBMODS
 $ACPIMODS
 $AGPMODS
 $I2CMODS
 $PLATFORMMODS
 $GSPCAMODS
 $BLUETOOTHMODS
 $DRMMODS
 $CPUSCALING2MODS
 $CPUSCALINGMODS
 $CRYPTOMODS
 $FBCONMODS
 $EXTRAMODS"
  echo "$CHOSENMODS"| tr -s '\n'  > /tmp/chosenmods.txt
  echo "Finding all dependent modules..."
  echo -n "" > /tmp/alldeps.txt
  echo "$CHOSENMODS" |
  while read ONEMOD
  do
   [ "$ONEMOD" = "" ] && continue #precaution
   ONEBASE="`basename $ONEMOD`"
   DPATTERN="/${ONEBASE}:"
   PPATTERN="s/^\/lib\/modules\/${KERNELVER}\///g"
   ONEDEPS="`cat rootfs-complete/lib/modules/$KERNELVER/modules.dep | grep "$DPATTERN" | cut -f 2 -d ':' | tr ' ' '\n' | sed -e "$PPATTERN"`"
   [ "$ONEDEPS" != "" ] && echo "$ONEDEPS" >> /tmp/alldeps.txt
  done
  sync
  sort -u /tmp/alldeps.txt > /tmp/alldepssorted.txt #remove duplicate lines.
  cat /tmp/alldepssorted.txt >> /tmp/chosenmods.txt
  sort -u /tmp/chosenmods.txt > /tmp/allmodssorted.txt
  sync
  #now delete all mods not in the list...
  echo "Moving unwanted modules to a separate pet file..." #"Deleting unwanted modules..." 150210
  find rootfs-complete/lib/modules/$KERNELVER/ -type f -name '*.ko' -o -name '*.HIDE' |
  while read ONEMODSPEC
  do
   ONEMODNAME="`basename $ONEMODSPEC`"
   mPATTERN='/'"$ONEMODNAME"
   if [ "`grep "$mPATTERN" /tmp/allmodssorted.txt`" = "" ];then
    ONEMODPATH="`dirname $ONEMODSPEC`"
    xONEMODPATH="`echo -n "$ONEMODPATH" | sed -e 's%^rootfs\-complete/%%'`"
    mkdir -p zdrv/${xONEMODPATH}
    cp -a $ONEMODSPEC zdrv/${xONEMODPATH}/
    rm -f $ONEMODSPEC
    #091203 remove firmware tarball...
    ONEMODBASE="`basename $ONEMODSPEC`"
    ombPATTERN='[:,]'"$ONEMODBASE"
    FWFND="`grep "$ombPATTERN" rootfs-complete/etc/modules/firmware.dep.${KERNELVER} | cut -f 1 -d ':'`"
    if [ "$FWFND" ];then
     if [ -f rootfs-complete/lib/modules/all-firmware/${FWFND}.tar.gz ];then
      mkdir -p zdrv/lib/modules/all-firmware
      mv -f rootfs-complete/lib/modules/all-firmware/${FWFND}.tar.gz zdrv/lib/modules/all-firmware/
     fi
    fi
   fi
  done
  
  #special case:
  mv -f rootfs-complete/lib/modules/all-firmware/intel537ep.tar.gz zdrv/lib/modules/all-firmware/
  cp -a -f --remove-destination rootfs-complete/lib/modules/${KERNELVER}/intelmodem zdrv/lib/modules/${KERNELVER}/
  rm -rf rootfs-complete/lib/modules/${KERNELVER}/intelmodem
 
  #echo "Creating ${ZDRVPET} 'zdrv' file..." #100911
  sync
  #w091029 use busybox depmod, creates smaller modules* files...
  #./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  if [ "$USINGKMOD" = "no" ];then #130418
   busybox depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  else
   ./depmod -b $WKGDIR/sandbox3/rootfs-complete -F $WKGDIR/sandbox3/System.map $KERNELVER
  fi
  sync
  MAKEZDRV="unwanted-modules" #w481 delay. 100903
 fi
fi #160824 ##############

#100622 slackware 13.1: just in case any got through, remove c-shell scripts...
rm -f rootfs-complete/etc/profile.d/*.csh* 2>/dev/null

#sanity check...
echo
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 chroot rootfs-complete echo 'testing chroot'
 if [ $? -ne 0 ];then
  echo "ERROR: could not 'chroot' into sandbox3/rootfs-complete"
  echo "This means that something is incomplete, perhaps a library"
  echo "needed by bash. Check it out. Have to exit script now."
  exit
 fi
else
 echo "Normally, the script now does a sanity-test by chrooting into"
 echo "sandbox3/rootfs-complete, however as you are doing a cross-build, this"
 echo "cannot be done."
fi

#before building puppy.sfs from rootfs-complete, check for any invalid symlinks
#and move them to the devx...
echo
echo "Finding invalid symlinks..."
rm -rf devx
mkdir devx
#v431 aaargh, latest pburn (3.1.1) has a symlink with spaces in name...
#for ONESYMLINK in `find rootfs-complete/ -type l`
find rootfs-complete/ -type l |
while read ONESYMLINK
do
 [ "`echo -n "$ONESYMLINK" | grep '/dev/'`" != "" ] && continue
 [ "`echo -n "$ONESYMLINK" | grep '/proc/'`" != "" ] && continue
 xONESYMLINK="`echo -n "$ONESYMLINK" | sed -e 's/^rootfs\-complete//'`"
 #w018 some symlinks become valid after puppy 1st boot...
 
 if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
  LINKTO="`chroot rootfs-complete readlink "$xONESYMLINK"`"
  [ "`echo -n "$LINKTO" | grep 'lib/X11/pixmaps'`" != "" ] && continue #these images created 1st boot.
  if [ "`chroot rootfs-complete readlink -e "$xONESYMLINK"`" = "" ];then
   UPONE="`dirname "$xONESYMLINK"`"
   mkdir -p devx${UPONE}
   cp -a -f "$ONESYMLINK" devx${UPONE}/
   rm -f "$ONESYMLINK"
  fi
 else
  #do it without chroot...
  LINKTO="`readlink rootfs-complete"${xONESYMLINK}"`" #120502 fix for spaces in path.
  [ -e rootfs-complete${LINKTO} ] && continue #absolute path
  UPONE="`dirname "$xONESYMLINK"`"
  [ -e rootfs-complete${UPONE}/${LINKTO} ] && continue #relative path
  mkdir -p devx${UPONE}
  cp -a -f "$ONESYMLINK" devx${UPONE}/
  rm -f "$ONESYMLINK"
 fi
 
done
#for ONESYMLINK in `find rootfs-complete/ -type l`
#do
# [ "`echo -n "$ONESYMLINK" | grep '/dev/'`" != "" ] && continue
# [ "`echo -n "$ONESYMLINK" | grep '/proc/'`" != "" ] && continue
# xONESYMLINK="`echo -n "$ONESYMLINK" | sed -e 's/^rootfs\-complete//'`"
# #w018 some symlinks become valid after puppy 1st boot...
# LINKTO="`chroot rootfs-complete readlink $xONESYMLINK`"
# [ "`echo -n "$LINKTO" | grep 'lib/X11/pixmaps'`" != "" ] && continue #these images created 1st boot.
# if [ "`chroot rootfs-complete readlink -e $xONESYMLINK`" = "" ];then
#  UPONE="`dirname $xONESYMLINK`"
#  mkdir -p devx${UPONE}
#  cp -a -f $ONESYMLINK devx${UPONE}/
#  rm -f $ONESYMLINK
# fi
#done

sync

#if [ "$DISTRO_COMPAT_VERSION" = "quirky6" ];then
# #131211 hack for quirky6, only want these...
# cp -a -f ../Packages-pet-common-official rootfs-complete/root/.packages/
# cp -a -f ../Packages-pet-noarch-official rootfs-complete/root/.packages/
# cp -a -f ../Packages-pet-quirky6-official rootfs-complete/root/.packages/
# cp -a -f ../Packages-t2-quirky6-official rootfs-complete/root/.packages/ #131214
#else
# #get info about the ubuntu pkgs...
# echo "Updating pkg data in rootfs-complete/root/.packages ..."
# #copy them into the live-cd also...
# #in case of Ppup4, PKGLISTS_COMPAT='Packages-pet-4xx-official'
# for ONELIST in $PKGLISTS_COMPAT
# do
#  cp -f ../$ONELIST ./
#  cp -f ../$ONELIST rootfs-complete/root/.packages/
# done
# for ONELIST in $PACKAGELISTS_PET_ORDER #120506
# do
#  cp -f ../$ONELIST ./
#  cp -f ../$ONELIST rootfs-complete/root/.packages/
# done
# #note, Ppup4, findwoofinstalledpkgs.sh (below) needs above file, then deletes it.
# #also copy the pet package databases...
# cp -f ../Packages-pet-[0-9]-official rootfs-complete/root/.packages/ 2>/dev/null
# cp -f ../Packages-pet-common-official rootfs-complete/root/.packages/ 2>/dev/null #110608
# #cp -f ../Packages-pet-wary5-official rootfs-complete/root/.packages/
# cp -f ../Packages-pet-noarch-official rootfs-complete/root/.packages/ #120305
# #121102
# if [ -f ../Packages-pet-${DISTRO_DB_SUBNAME}-official ];then #110723 ex: Packages-pet-drake-official
#  cp -f ../Packages-pet-${DISTRO_DB_SUBNAME}-official rootfs-complete/root/.packages/
#  cp -f ../Packages-pet-${DISTRO_DB_SUBNAME}-official ./
#  #120506...
#  ../support/rationalize_categories Packages-pet-${DISTRO_DB_SUBNAME}-official
#  cp -f /tmp/rationalized_categories rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
# fi
# #101014 rationalise categories... 110726 must *always* copy Packages-pet-wary5-official (it is going to be the fallback)...
# #if [ "$DISTRO_COMPAT_VERSION" = "wary5" ];then #101025
# if [ -f Packages-pet-wary5-official ];then
#  ../support/rationalize_categories Packages-pet-wary5-official
#  cp -f /tmp/rationalized_categories rootfs-complete/root/.packages/Packages-pet-wary5-official
# fi
#fi

#140202 simplify...
case $DISTRO_DB_SUBNAME in
 quirky6) SUBS="common noarch wary5 quirky6" ;;
 tahr) SUBS="common noarch wary5 quirky6 precise tahr" ;;
 unicorn) SUBS="common noarch wary5 quirky6 precise tahr unicorn" ;; #141023
 april) SUBS="common noarch wary april" ;; #150209
 *) SUBS="noarch ${DISTRO_DB_SUBNAME}" ;; #150209 171218
esac
for APSUB in $SUBS
do
 [ -f rootfs-complete/root/.packages/Packages-pet-${APSUB}-official ] && continue
 [ ! -f ../Packages-pet-${APSUB}-official ] && continue
 ../support/rationalize_categories ../Packages-pet-${APSUB}-official
 cp -f /tmp/rationalized_categories rootfs-complete/root/.packages/Packages-pet-${APSUB}-official
done
for APDB in `find ../ -maxdepth 1 -type f  -name "Packages-${DISTRO_BINARY_COMPAT}-*" | tr '\n' ' '`
do
 #../support/rationalize_categories $APDB
 #APBASE="`basename $APDB`"
 #cp -f /tmp/rationalized_categories rootfs-complete/root/.packages/${APBASE}
 cp -f $APDB rootfs-complete/root/.packages/
done
echo

#also copy this...
cp -f ../PKGS_MANAGEMENT rootfs-complete/root/.packages/

#190625 this is created in 0setup...
[ -f ../DEPENDENCIES-slackware ] && cp -f ../DEPENDENCIES-slackware rootfs-complete/root/.packages/

#477 a puppy-puppy build will not have any compat-distro databases...
petcntlimit=3
COMPATDISTRO_DB_FILES="`ls -1 rootfs-complete/root/.packages/Packages-[^p]* 2>/dev/null`"
[ "$COMPATDISTRO_DB_FILES" = "" ] && petcntlimit=5

#w476 swap to make sure 3 pet repos get chosen...
enabledrepos=" "

#100207 now using the quirky pet repo for all puppy builds... 131214 remove...
#[ -f ../Packages-pet-quirky-official ] && cp -f ../Packages-pet-quirky-official rootfs-complete/root/.packages/

#100730 DISTRO_COMPAT_VERSION for puppy builds no longer limited to a number 1-5 (ex: wary5)
fNUM1=`echo -n "$DISTRO_COMPAT_VERSION" | wc -c`

#100116 quirky, want the quirky db first in list... 101126 no, now building quirky from wary5 pkgs...
#if [ "`echo "$DISTRO_NAME" | grep -i 'quirky'`" != "" ];then
# enabledrepos="Packages-pet-quirky-official Packages-pet-4-official Packages-pet-3-official "
# #cp -f ../Packages-pet-quirky-official rootfs-complete/root/.packages/
#else
 repocnt=1
 case $DISTRO_FILE_PREFIX in  #110906 fix. $DISTRO_COMPAT_VERSION in #100911
  lucid|lupu|luci) #110906 fix. 120305 120312
   enabledrepos="Packages-pet-lucid-official Packages-pet-noarch-official "
  ;;
  wary|racy) #110906 110917 120305 120312 121105
   enabledrepos="Packages-pet-${DISTRO_DB_SUBNAME}-official Packages-pet-quirky-official Packages-pet-noarch-official Packages-pet-4-official " #110824 added -common-
  ;;
  slacko) #110824 120305 120312 121105
   enabledrepos="Packages-pet-${DISTRO_DB_SUBNAME}-official Packages-pet-noarch-official "
  ;;
  dpup|sqzd) #110824 110906 120305 120312
   enabledrepos="Packages-pet-dpup-official Packages-pet-noarch-official "
  ;;
  *)
   #add the puppy repos... (i want 5, 4, 3)... 131215 fix...
   for ONEREPO in `ls -1 rootfs-complete/root/.packages/Packages-pet* | sort -r`
   do
    [ $repocnt -gt $petcntlimit ] && break #limit of 3 puppy repos.
    BASEREPO="`basename $ONEREPO`"
    [ "$BASEREPO" = "Packages-pet-wary5-official" ] && continue #100911 handled above.
    [ "$BASEREPO" = "Packages-pet-lucid-official" ] && continue #100911 handled above.
    [ "$BASEREPO" = "Packages-pet-slacko-official" ] && continue #110824 handled above.
    #w478 a problem if building an old puppy-puppy, don't want more recent db's... 100730...
    if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then
     ONEREPNUM=`echo -n "$BASEREPO" | cut -f 3 -d '-'`
     fNUM2=`echo -n "$ONEREPNUM" | wc -c`
     #[ "`echo -n "$ONEREPNUM" | grep '[a-z]'`" != "" ] && continue
     [ $fNUM1 -eq 1 ] && [ $fNUM2 -eq 1 ] && [ $ONEREPNUM -gt $DISTRO_COMPAT_VERSION 2>/dev/null ] && continue
    fi
   # #w019 have decided don't want this showing up in PPM...
   # [ "$BASEREPO" = "Packages-pet-woof-official" ] && continue
    enabledrepos="${enabledrepos}${BASEREPO} "
    repocnt=`expr $repocnt + 1`
   done
  ;;
 esac
 #191004 hack, easy buster, nothing much in 'pet-buster' repo, leave it out of ppm... 191006 revert...
 #[ "$DISTRO_BINARY_COMPAT" == "debian" ] && enabledrepos="Packages-pet-noarch-official "
 #add compat-distro repos...
 if [ "$COMPATDISTRO_DB_FILES" != "" ];then
  for ONEREPO in `ls -1 rootfs-complete/root/.packages/Packages-[^p]*`
  do
   [ $repocnt -gt 5 ] && break #only allow 5 active repos in PPM.
   BASEREPO="`basename $ONEREPO`"
   enabledrepos="${enabledrepos}${BASEREPO} "
   repocnt=`expr $repocnt + 1`
  done
 fi
#fi

#120831 above code ok, but really just want these...
case $DISTRO_BINARY_COMPAT in
 ubuntu)
  xPUPPYREPOS="Packages-pet-${DISTRO_DB_SUBNAME}-official Packages-pet-noarch-official" #Packages-pet-common-official 
  xCOMPATREPOS="$(ls -1 rootfs-complete/root/.packages/Packages-[^p]* | grep -E '\-main$|\-universe$|\-multiverse$' | rev | cut -f 1 -d '/' | rev | tr '\n' ' ')"
  #130330 would like universe first...
  xCOMPATREPOS1="$(ls -1 rootfs-complete/root/.packages/Packages-[^p]* | grep -E '\-universe$' | rev | cut -f 1 -d '/' | rev | tr '\n' ' ')"
  xCOMPATREPOS2="$(ls -1 rootfs-complete/root/.packages/Packages-[^p]* | grep -E '\-main$|\-multiverse$' | rev | cut -f 1 -d '/' | rev | tr '\n' ' ')"
  enabledrepos=" ${xCOMPATREPOS1} ${xCOMPATREPOS2} ${xPUPPYREPOS} "
 ;;
esac

#131211 only want these pet repos...
if [ "$DISTRO_BINARY_COMPAT" = "t2" ];then
 if [ "$DISTRO_COMPAT_VERSION" = "quirky6" ];then
  enabledrepos='Packages-pet-quirky6-official Packages-pet-noarch-official Packages-pet-common-official '
 fi
fi


echo "PKG_REPOS_ENABLED='${enabledrepos}'" >> rootfs-complete/root/.packages/PKGS_MANAGEMENT

if [ -f ../DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #w478
 cp -f ../DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} rootfs-complete/root/.packages/DISTRO_PKGS_SPECS
else
 cp -f ../DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT} rootfs-complete/root/.packages/DISTRO_PKGS_SPECS
fi
#101013 remove wrong alternate choice (old/new kernel optional pkgs)...
if [ -f /tmp/3builddistro_removed_alt ];then
 for ONEREMOVE in `cat /tmp/3builddistro_removed_alt | tr '\n' ' '`
 do
  orPATTERN='yes|'"$ONEREMOVE"'|'
  grep -v "$orPATTERN" rootfs-complete/root/.packages/DISTRO_PKGS_SPECS > /tmp/DISTRO_PKGS_SPECS-tempor
  cp -f /tmp/DISTRO_PKGS_SPECS-tempor rootfs-complete/root/.packages/DISTRO_PKGS_SPECS
 done
fi

if [ -f ../DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then
 cp -f ../DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} rootfs-complete/root/.packages/DISTRO_COMPAT_REPOS
else #130306
 cp -f ../DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} rootfs-complete/root/.packages/DISTRO_COMPAT_REPOS
fi
#this needed to update pkg db's in a running puppy...
cp -f ../0setup rootfs-complete/usr/local/petget/
#160923 no, host and target archs may differ. already have it in dest (pup-tools pet)...
##w015 0setup calls this for faster operation...
#cp -f ../support/find_cat rootfs-complete/usr/local/petget/
#w091017 0setup also needs these, fast conversion created by Wosh...
[ -f ../support/ppkg ] && cp -f ../support/ppkg rootfs-complete/usr/local/petget/
[ -f ../support/ppkg.ctg ] && cp -f ../support/ppkg.ctg rootfs-complete/usr/local/petget/
#110612 0setup needs these...
[ -f ../support/rpm2ppm ] && cp -f ../support/rpm2ppm rootfs-complete/usr/local/petget/
[ -f ../support/mageia2ppm ] && cp -f ../support/mageia2ppm rootfs-complete/usr/local/petget/
#160923 no, host and target archs may differ. already have it in dest (pup-tools pet)...
##121111 new fast deb to pup db converter, called by 0setup...
#[ -f ../support/debdb2pupdb ] && cp -f ../support/debdb2pupdb rootfs-complete/usr/local/petget/
#urls etc on the pet db's...
cp -f ../DISTRO_PET_REPOS rootfs-complete/root/.packages/
#w018 homepages of heaps of pkgs (see 0pre script)...
cp -f ../PKGS_HOMEPAGES rootfs-complete/root/.packages/
#cp -f ../support/inline_get_pet rootfs-complete/root/.packages/ #100801
#cp -f ../support/inline_get_compat rootfs-complete/root/.packages/ #100806
#cp -f ../support/findpkgs rootfs-complete/root/.packages/ #110821 110823 revert.

#130316 see 0setup and debdb2pupdb...
case ${DISTRO_BINARY_COMPAT} in
 debian|ubuntu|raspbian|devuan) #150419
  if [ ! -f ../invaliddepslist ];then
   echo "WARNING WARNING"
   echo "File 'invaliddepslist' does not exist.
This is created by script '0setup'. You must go back and rerun all of the
scripts from 0setup, 1download, 2createpackages.
Recommend abort this script now (ctrl-c).
Or, if you press ENTER to continue, an empty 'invaliddepslist' file will
be created."
   echo -n "Press ENTER to continue: "
   read justgoon
   touch ../invaliddepslist
  fi
 ;;
esac
[ -f ../invaliddepslist ] && cp -f ../invaliddepslist rootfs-complete/usr/local/petget/

touch ../devx-only-installed-packages #121028
cp ../devx-only-installed-packages rootfs-complete/root/.packages/ #121028

#110722 add kernel db line... 160824
if [ "$KERNEL_DB_ENTRY" ];then
 echo "$KERNEL_DB_ENTRY" >> rootfs-complete/root/.packages/woof-installed-packages
else
 echo "linux_kernel-4.x|linux_kernel|4.x||BuildingBlock|103380K||linux_kernel-4.x-i-do-not-exist.pet||Linux kernel 4.x built into sd skeleton image|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}||" >> rootfs-complete/root/.packages/woof-installed-packages
fi
#sort alphabetically...
sort --key=1 --field-separator="|" rootfs-complete/root/.packages/woof-installed-packages > /tmp/petget_woof-installed-packages
mv -f /tmp/petget_woof-installed-packages rootfs-complete/root/.packages/woof-installed-packages

#currently not using these...
rm -f rootfs-complete/etc/rc.d/rc.sysinit-UNIPUP
rm -f rootfs-complete/etc/rc.d/rc.shutdown-UNIPUP


#130326 script to adjust fonts to suit 96 dpi (puppy used to have 78 dpi)...
rootfs-complete/usr/sbin/hackfontsize

#130618 restore the "layer:" lines in /etc/xdg/templates/_root_.jwmrc...
#note, this file is now in Woof, I took it out of the JWM pet.
JWMFLG=0
#171231 fix for pkg named 'jwm2-976-pyro64'...
JWM3=`grep -E '^jwm[0-9]*[_-][0-9]' rootfs-complete/root/.packages/woof-installed-packages | cut -f 3 -d '|' | cut -c 1-3 | head -n 1`
[ ! $JWM3 ] && JWMFLG=1 #assume too old. note, there is a jwm2 pet, which is older version.
if vercmp $JWM3 ge 2.2; then JWMFLG=2; fi
if vercmp $JWM3 ge 790; then JWMFLG=2; fi
case $JWMFLG in
 2)
  sed -i -e 's%.*LAYER_MINIXCAL.*%\t\t<Option>layer:above</Option>%' rootfs-complete/etc/xdg/templates/_root_.jwmrc
  sed -i -e 's%.*LAYER_GTKDIALOGSPLASH.*%\t\t<Option>layer:above</Option>%' rootfs-complete/etc/xdg/templates/_root_.jwmrc
  sed -i -e 's%.*LAYER_SPLASHWINDOW.*%\t\t<Option>layer:above</Option>%' rootfs-complete/etc/xdg/templates/_root_.jwmrc
 ;;
esac


#shared library loading...
#140123 ld.so.conf started further up, now append more...
[ -d rootfs-complete/usr/local/lib ] && echo "/usr/local/lib" >> rootfs-complete/etc/ld.so.conf
#[ -d rootfs-complete/usr/X11R7/lib ] && echo "/usr/X11R7/lib" >> rootfs-complete/etc/ld.so.conf
[ -d rootfs-complete/opt/gnome2/lib ] && echo "/opt/gnome2/lib" >> rootfs-complete/etc/ld.so.conf
[ -d rootfs-complete/opt/qt4/lib ] && echo "/opt/qt4/lib" >> rootfs-complete/etc/ld.so.conf
[ -d rootfs-complete/opt/mozilla.org/lib ] && echo "/opt/mozilla.org/lib" >> rootfs-complete/etc/ld.so.conf
[ -d rootfs-complete/opt/samba/lib ] && echo "/opt/samba/lib" >> rootfs-complete/etc/ld.so.conf
[ "$BUILD_CHOICE_BOARD" == "raspi" ] && echo "/opt/vc/lib" >> rootfs-complete/etc/ld.so.conf #161012 raspberry pi.
[ -d rootfs-complete/root/my-applications/lib ] && echo "/root/my-applications/lib" >> rootfs-complete/etc/ld.so.conf #140204 test

#141110 NO, lib64 are now symlinks into lib/x86_64-linux-gnu, so delete this...
##141107 installing some slacko64 pets into quirky unicorn64...
#[ -d rootfs-complete/lib64 ] && echo "/lib64" >> rootfs-complete/etc/ld.so.conf
#[ -d rootfs-complete/usr/lib64 ] && echo "/usr/lib64" >> rootfs-complete/etc/ld.so.conf

#141113 ubuntu 14.10 glibc deb /etc/ld.so.conf has just this in it:
# include /etc/ld.so.conf.d/*.conf
#so, will gradually move to this format. for now, find all ld.so.conf files in various pkgs (ex: xorg_base, mesa)...
mkdir -p rootfs-complete/etc/ld.so.conf.d
echo 'include /etc/ld.so.conf.d/*.conf' >> rootfs-complete/etc/ld.so.conf
LDSOCONF="$(find rootfs-complete/usr -type f -name ld.so.conf | tr '\n' ' ')"
for ALDSOCONF in $LDSOCONF
do
 CONFPATH="$(dirname $ALDSOCONF)" #ex: rootfs-complete/mesa/usr/lib/x86_64-linux-gnu/mesa-egl
 CONFFOLDER="$(basename $CONFPATH)"
 CONFCONTENT="$(cat $ALDSOCONF)"
 if [ "$(grep -x "$CONFCONTENT" rootfs-complete/etc/ld.so.conf)" == "" ];then
  [ ! -f rootfs-complete/etc/ld.so.conf.d/${CONFFOLDER}.conf ] && mv -f $ALDSOCONF rootfs-complete/etc/ld.so.conf.d/${CONFFOLDER}.conf
 fi
 rm -f ${CONFPATH}/ld.so.conf 2>/dev/null
done

#161012 have ended up with some duplication...
for ONELD in `cat rootfs-complete/etc/ld.so.conf.d/*.conf | grep '^/' | tr '\n' ' '`
do
 dPTN="^${ONELD}$"
 grep -v "$dPTN" rootfs-complete/etc/ld.so.conf > /tmp/etc_ld.so.conf_temp
 mv -f /tmp/etc_ld.so.conf_temp rootfs-complete/etc/ld.so.conf
done

#generate /etc/ld.so.cache shared lib loading cache file... 140204 fix...
xLDCONFIG="$(find rootfs-complete/sbin rootfs-complete/usr/sbin -maxdepth 2 -type f -name ldconfig | head -n 1 | sed -e 's%rootfs-complete%%')" #140204
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123  140204 set -maxdepth 4
 echo "Running ldconfig..."
 if [ "$xLDCONFIG" ];then #140204
  chroot rootfs-complete ${xLDCONFIG}
 else
  LDCONFIG="`find ../packages-${DISTRO_FILE_PREFIX}/ -maxdepth 4 -type f -name ldconfig | grep '/sbin/' | head -n 1`"
  cp -a $LDCONFIG rootfs-complete/
  chroot rootfs-complete ./ldconfig
  rm -f rootfs-complete/ldconfig
 fi
 sync
else
 #***NOTICE*** have to run ldconfig at first boot.
 if [ ! "$xLDCONFIG" ];then #140204
  LDCONFIG="`find ../packages-${DISTRO_FILE_PREFIX}/ -maxdepth 4 -type f -name ldconfig | grep '/sbin/' | head -n 1`"
  cp -a -f $LDCONFIG rootfs-complete/sbin/
 fi
fi

#150115 missing libs test moved down, below setup of library paths:
#now do dependency check...
dependcheck() {
 echo -n "" > /tmp/missinglibs.txt
 echo -n "" > /tmp/notmissinglibs0.txt
 echo -n "" > /tmp/notusedlibs.txt
 #FNDFILES="`find $WKGDIR/sandbox3/rootfs-complete -type f | tr "\n" " "`"
 #for ONEFILE in $FNDFILES
 find $WKGDIR/sandbox3/rootfs-complete -type f | #110516
 while read ONEFILE #110516
 do
  echo -n '.'
  ISANEXEC="`file --brief $ONEFILE | grep -E "LSB executable|shared object"`"
  if [ ! "$ISANEXEC" = "" ];then
   #need to chroot into rootfs-complete...
    NUMBYTESALL="`echo -n "$ONEFILE" | wc -c | tr -s " " | cut -f 2 -d " "`"
    NUMBYTESHD=`echo -n "$WKGDIR/sandbox3/rootfs-complete" | wc -c | tr -s " " | cut -f 2 -d " "`
    NUMBYTESHD="`expr $NUMBYTESHD + 1`"
    NEWROOTFILE="`echo -n "$ONEFILE" | cut -b $NUMBYTESHD-$NUMBYTESALL`"
   LDDRESULT="`chroot ${WKGDIR}/sandbox3/rootfs-complete ldd ${NEWROOTFILE}`"

   MISSINGLIBS="`echo "$LDDRESULT" | grep "not found" | cut -f 2 | cut -f 1 -d " " | tr "\n" " "`"
   if [ ! "$MISSINGLIBS" = "" ];then
    echo "File $ONEFILE has these missing library files:" >> /tmp/missinglibs.txt
    echo " $MISSINGLIBS" >> /tmp/missinglibs.txt
    #141112 not working...
    #echo "The missing libs are in these packages:" >> /tmp/missinglibs.txt
    #for ONEMISSING in $MISSINGLIBS
    #do
    # find ${WKGDIR}/packages-${DISTRO_FILE_PREFIX} -name $ONEMISSING >> /tmp/missinglibs.txt
    #done
    echo "" >> /tmp/missinglibs.txt
   fi
   #find all libs not missing...
   NOTMISSING="`file --brief $ONEFILE | grep -v "not found" | grep "shared object"`"
   if [ "$NOTMISSING" != "" ];then
    basename "$ONEFILE" >> /tmp/notmissinglibs0.txt
   fi
  fi
 done
 sync
 sort -u /tmp/notmissinglibs0.txt > /tmp/notmissinglibs.txt
 #now go thru rootfs-complete and see if any unused libs...
 #FNDFILES="`find $WKGDIR/sandbox3/rootfs-complete -type f | tr "\n" " "`"
 #for ONEFILE in $FNDFILES
 find $WKGDIR/sandbox3/rootfs-complete -type f | grep '/lib' | #110516 180606
 while read ONEFILE #110516
 do
  ISANLIB="`file --brief $ONEFILE | grep "shared object"`"
  if [ ! "$ISANLIB" = "" ];then
   FILEBASE='/'"`basename $ONEFILE`"'$'
   FNDMATCH="`cat /tmp/notmissinglibs.txt | grep "$FILEBASE"`"
   if [ "$FNDMATCH" = "" ];then
    echo "File $ONEFILE is in Puppy but is not used." >> /tmp/notusedlibs.txt
   fi
  fi
 done
}

echo
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 echo "This script can now optionally do a thorough dependency check. "
 echo "Note, this may take a long time."
 echo -e "Press \"c\" key then ENTER to do thorough check,"
 echo -n "else just press ENTER key to bypass check: "
 read mmnn
else
 echo "Normally, the script now offers to perform a thorough dependency check."
 echo "However, as the host and target architectures are different, this cannot"
 echo "be done (host=${WOOF_HOSTARCH}, target=${WOOF_TARGETARCH})."
 echo "If you want to do this check, do a build with host and target the same,"
 echo "with same package selection."
 echo -n "Press ENTER key to continue: "
 read mmnn
 mmnn=""
fi

echo
if [ "$mmnn" = "c" ];then
 echo "Wait awhile..."
 dependcheck
 if [ -s /tmp/missinglibs.txt ];then #true if file not zero size.
  echo
  echo "UNFORTUNATELY, these libs are missing:"
  cat /tmp/missinglibs.txt
  echo
  echo -e "Press \"c\" key then  ENTER key to exit,"
  echo -n "or if you really want to ignore problem, just press ENTER: "
  read goto1
 fi
 if [ "$goto1" = "c" ];then
  sync
  busybox umount $WKGDIR/sandbox3/img_mntpt #180606
  exit
 fi
 if [ -s /tmp/notusedlibs.txt ];then
  echo
  echo "INTERESTING, the following libs are in Puppy but apparently not used:"
  cat /tmp/notusedlibs.txt
  echo
  echo -e "Press \"c\" key then  ENTER key to exit,"
  echo -n "or if you really want to ignore problem, just press ENTER: "
  read goto1
 fi
 if [ "$goto1" = "c" ];then
  sync
  busybox umount $WKGDIR/sandbox3/img_mntpt #180606
  exit
 fi
fi
echo "...done."

#150103 moved down, below setup of library paths.
#fix the menus...
#111123 ***NOTICE*** cross-build, will have to run fixmenus and indexgen.sh at first bootup.
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 echo
 echo "Constructing configuration files for JWM, Fvwm95, IceWM, openbox..."
 chroot rootfs-complete /usr/sbin/fixmenus
 #generate help index...
 chroot rootfs-complete /usr/sbin/indexgen.sh
 #...note, rootfs-skeleton/pinstall.sh pre-processes the help files.
fi

#i don't know what 'lintian' is for...
rm -rf rootfs-complete/usr/share/lintian 2>/dev/null
#maybe stray /install dir from slackware pkgs...
rm -rf rootfs-complete/install 2>/dev/null
#slackware pkg may create this...
rm -rf rootfs-complete/etc/cron.daily 2>/dev/null

#180120 no, coz have renamed samba.sh to samba-setup...
##171214 make sure have this from rootfs-skeleton, for samba (Simple Samba Management)...
#cp -a -f ../rootfs-skeleton/usr/sbin/samba.sh rootfs-complete/usr/sbin/

#180120 make sure these are overwritten...
cp -a -f ../rootfs-skeleton/etc/ssh/* rootfs-complete/etc/ssh/

#w460 theme selection...
echo
echo "Continuing to setup `pwd`/rootfs-complete..."
echo
#141204 optional file...
DEFAULT_THEME_GTK2=''
DEFAULT_THEME_GTK3='' #190910
DEFAULT_THEME_JWM=''
DEFAULT_THEME_OPENBOX=''
DEFAULT_THEME_WALLPAPER=''
DEFAULT_THEME_DESK_ICONS=''
DEFAULT_THEME_ROX_TEXT_FOREGROUND='black'
DEFAULT_THEME_ROX_TEXT_SHADOW='thin' #none, thin, or thick
DEFAULT_THEME_ROX_TEXT_FONT='DejaVu Sans 10'
DEFAULT_THEME_XORG_TEXT_DPI=  #141206
if [ -f ../default-theme ];then #141206
. ../default-theme
fi
export DEFAULT_THEME_GTK2 DEFAULT_THEME_JWM DEFAULT_THEME_OPENBOX DEFAULT_THEME_WALLPAPER DEFAULT_THEME_DESK_ICONS #141206
#w478 now have a gui for theme selection...
eval "`../support/choose_themes`"
#...returns BACKGROUNDIMAGE, DESKICONS, GTKTHEME, JWMTHEME.

if [ "$EXIT" = "OK" ];then
#BACKGROUNDIMAGE="zzzzzzzz"
#echo "Here are the available background images (ref: usr/share/backgrounds):"
#ls -1 rootfs-complete/usr/share/backgrounds
#echo
#while [ ! -f rootfs-complete/usr/share/backgrounds/$BACKGROUNDIMAGE ];do
# echo "Type the full filename of the one you want as default"
# echo -n "(ENTER only will select the first): "
# read BACKGROUNDIMAGE
# [ "$BACKGROUNDIMAGE" = "" ] && BACKGROUNDIMAGE="`ls -1 rootfs-complete/usr/share/backgrounds | head -n 1`"
#done
 case $BACKGROUNDIMAGE in #110831
  *.png|*.PNG)
   mv -f rootfs-complete/usr/share/backgrounds/$BACKGROUNDIMAGE rootfs-complete/usr/share/backgrounds/default.png
   sed -i -e 's%default\.jpg%default.png%' rootfs-complete/root/Choices/ROX-Filer/PuppyPin
   #i don't know what uses this, but change it anyway...
   sed -i -e 's%default\.jpg%default.png%' rootfs-complete/etc/Puppybackgroundpicture
  ;;
  *)
   mv -f rootfs-complete/usr/share/backgrounds/$BACKGROUNDIMAGE rootfs-complete/usr/share/backgrounds/default.jpg
  ;;
 esac



##w477 choose gtk theme...
#echo
#echo "Here are the available GTK themes (ref: usr/share/themes):"
#ls -1 rootfs-complete/usr/share/themes/*/gtk-2.0 | grep '^rootfs-complete/usr/share/themes' | cut -f 5 -d '/'
#echo
#GTKTHEME="zzzzzzzzzz"
#while [ ! -d "rootfs-complete/usr/share/themes/$GTKTHEME" ];do
# echo "Type the full filename of the one you want as default"
# echo -n "(ENTER only will select the first): "
# read GTKTHEME
# [ "$GTKTHEME" = "" ] && GTKTHEME="`ls -1 rootfs-complete/usr/share/themes/*/gtk-2.0 | grep '^rootfs-complete/usr/share/themes' | cut -f 5 -d '/' | head -n 1`"
#done
#130329 append extra line, needed for Qt4 theme matching. (see also /etc/profile.d/pup_gtk and /root/.config/Trolltech.conf)...
echo "# -- THEME AUTO-WRITTEN DO NOT EDIT
include \"/usr/share/themes/${GTKTHEME}/gtk-2.0/gtkrc\"

include \"/root/.gtkrc.mine\"

# -- THEME AUTO-WRITTEN DO NOT EDIT
gtk-theme-name=\"${GTKTHEME}\"" > rootfs-complete/root/.gtkrc-2.0

#190910...
##130401 01micko...
## gtk3 theme support thunor http://murga-linux.com/puppy/viewtopic.php?p=695722#695722
##[ -d rootfs-complete/root/.config/gtk-3.0 ] || mkdir -p rootfs-complete/root/.config/gtk-3.0
#pathGTK3THEME="`find rootfs-complete/usr/share/themes/${GTKTHEME} -type d -name gtk-3.0`"
#if [ "$pathGTK3THEME" ];then #XDG_CONFIG_HOME=/root/.config
## [ -f ${pathGTK3THEME}/settings.ini ] && cp -af ${pathGTK3THEME}/settings.ini rootfs-complete/root/.config/gtk-3.0/ || echo -e "[Settings] \ngtk-theme-name = \"${GTKTHEME}\" \ngtk-fallback-icon-theme = \"gnome\"" > rootfs-complete/root/.config/gtk-3.0/settings.ini
## #[ -f ${pathGTK3THEME}/gtk.css ] && cp -af ${pathGTK3THEME}/gtk.css rootfs-complete$XDG_CONFIG_HOME/gtk-3.0/ ||\# doesn't work
## echo "" > rootfs-complete/root/.config/gtk-3.0/gtk.css
#  #130404 link to actual theme...
#  ln -snf "$pathGTK3THEME" rootfs-complete/root/.config/gtk-3.0
#fi
if [ "$DEFAULT_THEME_GTK3" ];then #see file 'default-theme'
 #ex: gtk_theme_clearlooks_overcast:Clearlooks-Overcast
 #this file is in rootfs-skeleton...
 sed -i -e "s%^gtk-theme-name .*%gtk-theme-name = ${DEFAULT_THEME_GTK3/*:/}%" rootfs-complete/root/.config/gtk-3.0/settings.ini
fi

#echo
#DESKICONS="zzzzzzzzz"
#echo "Here are the available desktop icon themes (ref: usr/local/lib/X11/themes):"
#find rootfs-complete/usr/local/lib/X11/themes -maxdepth 1 -mindepth 1 -type d | rev | cut -f 1 -d '/' | rev
#while [ ! -d "rootfs-complete/usr/local/lib/X11/themes/$DESKICONS" ];do
# echo "Type the full filename of the one you want as default"
# echo -n "(ENTER only will select the first): "
# read DESKICONS
# [ "$DESKICONS" = "" ] && DESKICONS="`find rootfs-complete/usr/local/lib/X11/themes -maxdepth 1 -mindepth 1 -type d | rev | cut -f 1 -d '/' | rev | head -n 1`"
#done
echo -n "$DESKICONS" > rootfs-complete/etc/desktop_icon_theme

 if [ -d rootfs-complete/root/.jwm/themes ];then
  cp -f rootfs-complete/root/.jwm/themes/${JWMTHEME}-jwmrc rootfs-complete/root/.jwm/jwmrc-theme
  cp -f rootfs-complete/root/.jwm/themes/${JWMTHEME}-colors rootfs-complete/root/.jwm/jwm_colors 2>/dev/null
 fi

 if [ -f rootfs-complete/root/.config/openbox/rc.xml ];then #20100406
  obPATTERN="s%Natura%${OBTHEME}%"
  sed -i -e "$obPATTERN" rootfs-complete/root/.config/openbox/rc.xml
 fi
 sync
fi #end theme chooser ok.

#110807 don't ask...
##110803 workaround for 'pngoverlay' needs X runnning, also avoid cpu overhead at first startup...
##/usr/sbin/icon_switcher_cli is called from /etc/rc.d/rc.update.
#echo
#echo "There are currently issues with building the default desktop icons in"
#echo "usr/local/lib/X11/pixmaps at first bootup of Puppy (PUPMODE=5)."
#echo "Recommend do it now, which will also save cpu time at first bootup."
#echo "Press any printable character then ENTER to defer building desktop icons."
#echo -n "Recommend press ENTER key only: "
#read DOITNOW
#if [ "$DOITNOW" = "" ];then

#110826 no longer calling icon_switcher_cli from rc.update, don't need this...
# #modify start of rootfs-complete/usr/sbin/icon_switcher_cli...
# sed -i -e 's%^#DONEINWOOF .*%[ "$PUPMODE" = "5" ] \&\& exit%' rootfs-complete/usr/sbin/icon_switcher_cli

 #have copied code from icon_switcher_cli to here, modified...
 NEWTHEME="$DESKICONS" #see above
 for ONESVG in `find rootfs-complete/usr/local/lib/X11/themes/${NEWTHEME}/ -maxdepth 1 -type f -name \*.svg | tr '\n' ' '`
 do
  ONEBASENAME="`basename $ONESVG .svg`"
  rm -f rootfs-complete/usr/local/lib/X11/pixmaps/${ONEBASENAME}48.png
  rsvg-convert -w 48 -h 48 -o rootfs-complete/usr/local/lib/X11/pixmaps/${ONEBASENAME}48.png $ONESVG
  rm -f rootfs-complete/usr/local/lib/X11/pixmaps/${ONEBASENAME}24.png
  #rsvg-convert -w 24 -h 24 -o /tmp/${ONEBASENAME}24.png $ONESVG
  ##if svg has transparency, JWM does not render properly in x16 bit color, screen out...
  #pngtopnm -mix /tmp/${ONEBASENAME}24.png | pnmtopng > /usr/local/lib/X11/pixmaps/${ONEBASENAME}24.png
  rsvg-convert -w 24 -h 24 -o rootfs-complete/usr/local/lib/X11/pixmaps/${ONEBASENAME}24.png $ONESVG
 done
 for ONEPNG in `find rootfs-complete/usr/local/lib/X11/themes/${NEWTHEME}/ -maxdepth 1 -type f -name \*.png | tr '\n' ' '`
 do
  ONEBASENAME="`basename $ONEPNG .png`"
  cp -f $ONEPNG rootfs-complete/usr/local/lib/X11/pixmaps/
  touch -m rootfs-complete/usr/local/lib/X11/pixmaps/${ONEBASENAME}.png #v3.98
  xONEBASENAME="`basename $ONEBASENAME 48`"
  if [ "$xONEBASENAME" != "$ONEBASENAME" ];then #scale to 24 pixels...
   pngtopnm -alpha $ONEPNG > /tmp/temp.pbm #separate transparency channel.
   pnmscale -reduce 2 /tmp/temp.pbm > /tmp/temp2.pbm 2> /dev/null
   pngtopnm $ONEPNG | pnmscale -reduce 2 2>/dev/null | pnmtopng -alpha=/tmp/temp2.pbm > rootfs-complete/usr/local/lib/X11/pixmaps/${xONEBASENAME}24.png
   touch -m rootfs-complete/usr/local/lib/X11/pixmaps/${xONEBASENAME}24.png #v3.98
  fi
 done

 #140127 if these not in the theme, create them (see also /usr/sbin/icon_switcher)... 141022 bug fix...
 [ ! -f rootfs-complete/usr/local/lib/X11/pixmaps/drives48.png ] && cp -f rootfs-complete/usr/local/lib/X11/pixmaps/drive48.png rootfs-complete/usr/local/lib/X11/pixmaps/drives48.png 2>/dev/null
 [ ! -f rootfs-complete/usr/local/lib/X11/pixmaps/folders48.png ] && cp -f rootfs-complete/usr/local/lib/X11/pixmaps/folder48.png rootfs-complete/usr/local/lib/X11/pixmaps/folders48.png 2>/dev/null
 [ ! -f rootfs-complete/usr/local/lib/X11/pixmaps/drives24.png ] && cp -f rootfs-complete/usr/local/lib/X11/pixmaps/drive24.png rootfs-complete/usr/local/lib/X11/pixmaps/drives24.png 2>/dev/null
 [ ! -f rootfs-complete/usr/local/lib/X11/pixmaps/folders24.png ] && cp -f rootfs-complete/usr/local/lib/X11/pixmaps/folder24.png rootfs-complete/usr/local/lib/X11/pixmaps/folders24.png 2>/dev/null
 
 if [ "$DISPLAY" ];then #110726 pngoverlay does not work when X not running. --quick fix, perform this operation in woof in 3builddistro.
  #110721 new standardised icons to show when mounted...
  if [ -e rootfs-complete/usr/sbin/pngoverlay -a -e rootfs-complete/usr/local/lib/X11/pixmaps/closebox_outline48.png ];then #overlay app created by vovchik (see source /usr/sbin/pngoverlay.bac)
   rm -f rootfs-complete/usr/local/lib/X11/pixmaps/*_mntd*.png
   #cp -f rootfs-complete/usr/sbin/pngoverlay rootfs-complete/usr/local/lib/X11/pixmaps/ #dumb, but needs to be in same folder.
   #111123 get pngoverlay from host, in case of cross-build...
   cp -f /usr/sbin/pngoverlay rootfs-complete/usr/local/lib/X11/pixmaps/ #dumb, but needs to be in same folder.
   cd rootfs-complete/usr/local/lib/X11/pixmaps
   for ONEDRV in card drive floppy optical usbdrv
   do
    ./pngoverlay ${ONEDRV}48.png closebox_outline48.png ${ONEDRV}_mntd48.png #background foreground output.
    ./pngoverlay ${ONEDRV}48.png locked_outline48.png ${ONEDRV}_mntd_boot48.png
   done
   rm -f rootfs-complete/usr/local/lib/X11/pixmaps/pngoverlay
   cd ../../../../../../
  fi
 fi
#fi

#110912 modify jwm to use menu icon 'start-button.png' if present...
#note, similar code also in /usr/sbin/icon_switcher (desktop icon switcher script).
if [ -f rootfs-complete/root/.jwmrc-tray ];then
 if [ -f rootfs-complete/usr/local/lib/X11/${NEWTHEME}/start-button.png ];then #default theme has menu icon.
  if [ -f rootfs-complete/usr/local/lib/X11/pixmaps/start-button.png ];then #precaution.
   if [ "`grep 'start-button\.png' rootfs-complete/root/.jwmrc-tray`" = "" ];then
    #the default is to use 'mini-dog.xpm' with text "Menu"...
    echo "rootfs-complete/root/.jwmrc-tray modified to use start-button.png menu icon"
    echo "(which is in rootfs-complete/usr/local/lib/X11/pixmaps/)"
    PTN1='s%label="Menu" icon="mini-dog\.xpm"%icon="start-button.png"%'
    sed -i -e "$PTN1" rootfs-complete/root/.jwmrc-tray
   fi
  fi
 fi
fi

#170105 set colors of xload in jwm tray. ref file 'default-theme'
if [ "$DEFAULT_COLOR_JWM_XLOAD" ];then #ex: -bg "#ff9d63" -fg red -hl white
 if [ -f rootfs-complete/root/.jwmrc-tray ];then
  sed -i -e "s%xload -nolabel .*%xload -nolabel ${DEFAULT_COLOR_JWM_XLOAD}%" rootfs-complete/root/.jwmrc-tray
 fi
fi

#v423 moved down. remove 'default' image from cull list...
#w482 cutdown the background images, to 8 images, remove largest...
BIGBACKIMAGES="`ls -S -1 rootfs-complete/usr/share/backgrounds | head -n -8 | grep -v 'default' | tr '\n' ' '`"
for ONEBIGIMAGE in $BIGBACKIMAGES
do
 rm -f rootfs-complete/usr/share/backgrounds/$ONEBIGIMAGE
done

#141204 refer file 'default-theme' ...
if [ "$DEFAULT_THEME_ROX_TEXT_FOREGROUND" ];then # black=#000000000000 white=#ffffffffffff
 grep -v 'pinboard_fg_colour' rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options > /tmp/3builddistro_rox_options1
 grep -v '^</Options>' /tmp/3builddistro_rox_options1 > rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo "  <Option name=\"pinboard_fg_colour\">${DEFAULT_THEME_ROX_TEXT_FOREGROUND}</Option>" >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo '</Options>' >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
else
 echo 'ROX: Using black text, as no DEFAULT_THEME_ROX_TEXT_FOREGROUND in default-theme'
fi
if [ "$DEFAULT_THEME_ROX_TEXT_SHADOW" ];then # none=0 thin=  thick=
 grep -v 'pinboard_shadow_labels' rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options > /tmp/3builddistro_rox_options1
 grep -v '^</Options>' /tmp/3builddistro_rox_options1 > rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo "  <Option name=\"pinboard_shadow_labels\">${DEFAULT_THEME_ROX_TEXT_SHADOW}</Option>" >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo '</Options>' >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
else
 echo 'ROX: Using thin-shadow, as no DEFAULT_THEME_ROX_TEXT_SHADOW in default-theme'
fi
if [ "$DEFAULT_THEME_ROX_TEXT_FONT" ];then
 grep -v 'label_font' rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options > /tmp/3builddistro_rox_options1
 grep -v '^</Options>' /tmp/3builddistro_rox_options1 > rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo "  <Option name=\"label_font\">${DEFAULT_THEME_ROX_TEXT_FONT}</Option>" >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
 echo '</Options>' >> rootfs-complete/root/.config/rox.sourceforge.net/ROX-Filer/Options
else
 echo 'ROX: Using DejaVu Sans 10, as no DEFAULT_THEME_ROX_TEXT_FONT in default-theme'
fi
rm -f /tmp/3builddistro_rox_options1 2>/dev/null

#w464 maybe get rid of old mksquashfs... v424 fix
#w091019 running puppy with older glibc, mksquashfs may not work, so must chroot...
#141207 fix for alternate path:
#141231 do not chroot, gives "not enough physical memory" error (fixed in very latest mksquashfs). just assume v4.x.
SQPATH='/usr/sbin'
[ -e rootfs-complete/usr/bin/mksquashfs ] && SQPATH='/usr/bin'
if [ -e rootfs-complete${SQPATH}/mksquashfs ];then
 [ ! -e rootfs-complete${SQPATH}/mksquashfs4 ] && ln -s mksquashfs rootfs-complete${SQPATH}/mksquashfs4
fi
#ditto for unsquashfs... v424 fix w091019 chroot fix...
if [ -e rootfs-complete${SQPATH}/unsquashfs ];then
 [ ! -e rootfs-complete${SQPATH}/unsquashfs4 ] && ln -s unsquashfs rootfs-complete${SQPATH}/unsquashfs4
fi

if [ "$DISTRO_KERNEL_PET" != "" ];then #160824 #############
 #140119 delete all modules.* files...
 echo "...deleting modules.* files."
 [ -d rootfs-complete/lib/modules/$KERNELVER ] && rm -f rootfs-complete/lib/modules/$KERNELVER/modules.* 2>/dev/null
 #100628 my 2.6.34 pet has these...
 mkdir -p rootfs-complete/lib/modules/$KERNELVER #101023 not there if separate zdrv built.
 [ -f rootfs-complete/etc/modules/modules.builtin ] && cp -f rootfs-complete/etc/modules/modules.builtin rootfs-complete/lib/modules/$KERNELVER/
 [ -f rootfs-complete/etc/modules/modules.order ] && cp -f rootfs-complete/etc/modules/modules.order rootfs-complete/lib/modules/$KERNELVER/
fi #160824 #############

if [ "$MAKEZDRV" != "" ];then #w481 100903
 #v425 big analog modules may have got moved out to the zdrv...
 if [ -d big-modem-modules ];then
  mkdir -p zdrv
  cp -a -f big-modem-modules/rootfs-complete/* zdrv/
  mkdir -p zdrv/lib/modules/all-firmware
  cp -a -f big-modem-firmware/* zdrv/lib/modules/all-firmware/
  sync
 fi
 if [ "$MAKEZDRV" = "all-modules" ];then #100903
  mkdir -p zdrv/lib
  mkdir -p zdrv/etc
  mv -f rootfs-complete/lib/firmware zdrv/lib/
  mv -f rootfs-complete/etc/modules zdrv/etc/
 fi
 echo
 echo "Creating ${ZDRVPET}..."
 [ -f ${ZDRVPET} ] && rm -f ${ZDRVPET} #100911
 #150205 now creating pet...
 #../support/${MKSQUASHFS} zdrv ${ZDRVPET} ${COMPCHOICE} #100911 110713
 ZDRVNAME="$(basename $ZDRVPET .pet)" #ex: linux_modules_extra-6.97-april64
 [ -d $ZDRVNAME ] && rm -rf ./${ZDRVNAME}
 mv zdrv $ZDRVNAME
 DB_pkgname="$(echo -n $ZDRVNAME | cut -f 1 -d '-')"
 DB_version="$(echo -n $ZDRVNAME | cut -f 2- -d '-')"
 DB_size="$(du -s -k ${ZDRVNAME} | cut -f 1)"
 #db fields: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
 PETSPECS="${ZDRVNAME}|${DB_nameonly}|${DB_version}||BuildingBlock|${DB_size}K||${ZDRVPET}|+linux_kernel&eq${KERNELVER}|extra modules for linux version ${KERNELVER}, for ${DISTRO_FILE_PREFIX} version ${DISTRO_VERSION}|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}||"
 echo "$PETSPECS" > ${ZDRVNAME}/pet.specs
 #150210 need this:
 echo '#!/bin/sh
[ "`pwd`" == "/" ] && depmod' > ${ZDRVNAME}/pinstall.sh
 chmod 755 ${ZDRVNAME}/pinstall.sh
 echo '#!/bin/sh
depmod' > ${ZDRVNAME}/puninstall.sh
 chmod 755 ${ZDRVNAME}/puninstall.sh
 sync
 dir2tgz ${ZDRVNAME}/
 tgz2pet ${ZDRVNAME}.tar.gz
 sync
 rm -rf ./${ZDRVNAME}
 chmod 644 ${ZDRVPET}
 echo ' ...done'

 #150209 6update-pet-repo script adds pet to pet-repo, but want db-entry in rootfs-complete... 
 echo
 echo "Adding '${ZDRVPET}' db-entry to rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official..."
 sed -i '/^linux_modules_extra/d' rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
 echo "$PETSPECS" >> rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
 sort rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official > /tmp/p-p-o-tmp
 cp -a -f /tmp/p-p-o-tmp rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
 echo ' ...done'
 echo 'Note: script 6update-pet-repo needs to be run to add pet to local repo.'
fi

#170814 devx now only a sfs...
#if [ "$BUILD_CHOICE_MERGE_DEVX" != "yes" ];then #150726
# #150209 devx pet created later, but want db-entry in build...
# echo
# echo 'Creating a devx db-entry in build...'
# SIZEK="400000" #rough value
# sed -i '/^devx/d' rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
# PETSPECS="devx-${DISTRO_VERSION}-${DISTRO_FILE_PREFIX}|devx|${DISTRO_VERSION}-${DISTRO_FILE_PREFIX}||Utility;development|${SIZEK}K||devx-${DISTRO_VERSION}-${DISTRO_FILE_PREFIX}.pet||A complete C/C++/Vala/Genie/BaCon compiling environment for Quirky, with extras such as svn, git, gdb|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}||"
# echo "$PETSPECS" >> rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
# sort rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official > /tmp/p-p-o-tmp
# cp -a -f /tmp/p-p-o-tmp rootfs-complete/root/.packages/Packages-pet-${DISTRO_DB_SUBNAME}-official
# echo ' ...done'
# echo 'Note: script 6update-pet-repo needs to be run to add pet to local repo.'
# echo
#fi

#w470 create a table for dialog/Xdialog: /usr/share/i18n/dialog_table
#'chooselocale' is called from /etc/rc.d/rc.country at first boot and
#pre-creating this table speeds things up. 111123
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 echo "Locale setup in rootfs-complete..."
 echo "  EXECUTING: chroot rootfs-complete /usr/sbin/chooselocale composeonly"
 chroot rootfs-complete /usr/sbin/chooselocale composeonly
 #160914 instead of creating /usr/lib/locale/en_US at first boot, do it now...
 echo "  EXECUTING: chroot rootfs-complete /usr/bin/localedef  -f ISO-8859-1 -i en_US --no-archive en_US"
 chroot rootfs-complete /usr/bin/localedef  -f ISO-8859-1 -i en_US --no-archive en_US
 #and en_US.utf8 (read from LANG in rootfs-complete/etc/profile)...
 echo "  EXECUTING: chroot rootfs-complete /usr/sbin/chooselocale cli quiet"
 chroot rootfs-complete /usr/sbin/chooselocale cli quiet
 # ...also generates rootfs-complete/root/.jwmrc
fi


[ -f rootfs-complete/pet.specs ] && rm -f rootfs-complete/pet.specs #w478

#w478 save some space if medit and gtksourceview both installed...
if [ -d rootfs-complete/usr/share/gtksourceview-2.0 ];then
 if [ -d rootfs-complete/usr/share/moo/language-specs ];then
  echo
  echo "An optimisation can be done to share some files between medit and"
  echo -n "gtksourceview. Press ENTER only to do this: "
  read optsourceview
  if [ "$optsourceview" = "" ];then
   cp -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs/convert.py rootfs-complete/usr/share/moo/language-specs/ 2>/dev/null
   cp -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs/language2.rng rootfs-complete/usr/share/moo/language-specs/ 2>/dev/null
   cp -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs/language.rng rootfs-complete/usr/share/moo/language-specs/ 2>/dev/null
   cp -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs/language.dtd rootfs-complete/usr/share/moo/language-specs/ 2>/dev/null
   cp -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs/styles.rng rootfs-complete/usr/share/moo/language-specs/ 2>/dev/null
   rm -r -f rootfs-complete/usr/share/gtksourceview-2.0/language-specs
   rm -r -f rootfs-complete/usr/share/gtksourceview-2.0/styles
   ln -s /usr/share/moo/language-specs rootfs-complete/usr/share/gtksourceview-2.0/language-specs
   ln -s /usr/share/moo/language-specs rootfs-complete/usr/share/gtksourceview-2.0/styles
   echo "...usr/share/gtksourceview-2.0 now has links to usr/share/moo."
  fi
 fi
fi

#091123 t2 build get rid of some stray stuff...
[ -d rootfs-complete/usr/share/devhelp ] && rm -rf rootfs-complete/usr/share/devhelp
[ -d rootfs-complete/usr/share/man ] && rm -rf rootfs-complete/usr/share/man
[ -d rootfs-complete/usr/share/omf ] && rm -rf rootfs-complete/usr/share/omf

##091206 cleanup some icons if quirky build...
#c1DFP="`echo -n "$DISTRO_FILE_PREFIX" | cut -c 1`" #100516
##if [ "$DISTRO_FILE_PREFIX" = "quirky" ];then
#if [ "$c1DFP" = "q" ];then #100516
# ln -snf quirky-grey48x48.png rootfs-complete/usr/share/doc/puppylogo48.png
# ln -snf quirky-grey96x96.png rootfs-complete/usr/share/doc/puppylogo96.png
#else #111003
# rm -f rootfs-complete/usr/share/doc/quirky-grey48x48.png
# rm -f rootfs-complete/usr/share/doc/quirky-grey96x96.png
# case $DISTRO_FILE_PREFIX in
#  racy)
#   ln -snf racy48.png rootfs-complete/usr/share/doc/puppylogo48.png
#   ln -snf racy96.png rootfs-complete/usr/share/doc/puppylogo96.png
#  ;;
#  *)
#   rm -f rootfs-complete/usr/share/doc/racy48.png #111003
#   rm -f rootfs-complete/usr/share/doc/racy96.png #111003
#  ;;
# esac
#fi
#111006 generic logo mechanism for all pups...
if [ -f rootfs-complete/usr/share/doc/puplogos/${DISTRO_FILE_PREFIX}48.png ];then
 mv -f rootfs-complete/usr/share/doc/puplogos/${DISTRO_FILE_PREFIX}48.png rootfs-complete/usr/share/doc/${DISTRO_FILE_PREFIX}48.png
 ln -snf ${DISTRO_FILE_PREFIX}48.png rootfs-complete/usr/share/doc/puppylogo48.png
fi
if [ -f rootfs-complete/usr/share/doc/puplogos/${DISTRO_FILE_PREFIX}96.png ];then
 mv -f rootfs-complete/usr/share/doc/puplogos/${DISTRO_FILE_PREFIX}96.png rootfs-complete/usr/share/doc/${DISTRO_FILE_PREFIX}96.png
 ln -snf ${DISTRO_FILE_PREFIX}96.png rootfs-complete/usr/share/doc/puppylogo96.png
fi
rm -rf rootfs-complete/usr/share/doc/puplogos

#100208 hack so net-setup.sh can find ifplugstatus (pup 4.3.2 needs this)...
if [ ! -e rootfs-complete/sbin/ifplugstatus ];then
 if [ -e rootfs-complete/sbin/ifplugstatus-0.18 ];then
  ln -s ifplugstatus-0.18 rootfs-complete/sbin/ifplugstatus
 else
  if [ -e rootfs-complete/sbin/ifplugstatus-0.28 ];then
   ln -s ifplugstatus-0.28 rootfs-complete/sbin/ifplugstatus
  fi
 fi
fi

#100524 fix cups for samba, got this code from /usr/sbin/cups_shell...
#fixes from rcrsn51 for samba printing...
[ -f rootfs-complete/etc/cups/snmp.conf ] && [ "`stat --format=%U%G rootfs-complete/etc/cups/snmp.conf | grep 'UNKNOWN'`" != "" ] && chown root:nobody rootfs-complete/etc/cups/snmp.conf
#100706 no, this goes against all the docs, restore to a symlink...
#if [ ! -e rootfs-complete/usr/lib/cups/backend/smb ];then
# [ -f rootfs-complete/opt/samba/bin/smbspool ] && cp -a rootfs-complete/opt/samba/bin/smbspool rootfs-complete/usr/lib/cups/backend/smb
# [ -f rootfs-complete/usr/bin/smbspool ] && cp -a rootfs-complete/usr/bin/smbspool rootfs-complete/usr/lib/cups/backend/smb
#fi
if [ ! -e rootfs-complete/usr/lib/cups/backend/smb ];then
 [ -f rootfs-complete/opt/samba/bin/smbspool ] && ln -s /opt/samba/bin/smbspool rootfs-complete/usr/lib/cups/backend/smb
 [ -f rootfs-complete/usr/bin/smbspool ] && ln -s /usr/bin/smbspool rootfs-complete/usr/lib/cups/backend/smb
fi
[ -f rootfs-complete/etc/opt/samba/smb.conf ] && chmod 755 rootfs-complete/etc/opt/samba/smb.conf #need world-readable.
[ -f rootfs-complete/etc/samba/smb.conf ] && chmod 755 rootfs-complete/etc/samba/smb.conf #need world-readable.

#110907 rcrsn51: network printing, need this... 111027 revert, must have actual pdftops from cups pkg...
#if [ ! -e rootfs-complete/usr/lib/cups/filter/pdftops ];then
# [ -f rootfs-complete/usr/bin/pdftops ] && ln -s /usr/bin/pdftops rootfs-complete/usr/lib/cups/filter/pdftops
#fi

#111026 davids45: /tmp needs 777 permissions. i do have this in rootfs-skeleton, but lost in sandbox3/rootfs-complete
# (http://murga-linux.com/puppy/viewtopic.php?t=72258&start=90)
#130203 01micko: make that 1777 ref: http://murga-linux.com/puppy/viewtopic.php?p=677630#677630
chmod 1777 rootfs-complete/tmp
chmod 777 rootfs-complete/var

#110911 fix if any alternate drivers still at old location...
mkdir -p rootfs-complete/usr/lib/x/drivers-alternate
if [ -d rootfs-complete/usr/lib/xorg/modules/drivers-alternate ];then
 cp -a -f rootfs-complete/usr/lib/xorg/modules/drivers-alternate/* rootfs-complete/usr/lib/x/drivers-alternate/
 rm -rf rootfs-complete/usr/lib/xorg/modules/drivers-alternate
fi

#191002 buster: have two paths, both with drivers: /usr/lib/x86_64-linux-gnu/xorg/modules/drivers /usr/lib/xorg/modules/drivers
XDRVRMS="$(find rootfs-complete/usr -type f -name modesetting_drv.so | grep '/xorg/modules/drivers' | head -n 1)"
if [ "$XDRVRMS" ];then
 XDRVRPATH="$(dirname ${XDRVRMS})"
else
 XDRVRPATH="$(find rootfs-complete/usr -type d -name drivers | grep '/xorg/modules/drivers' | head -n 1)"
fi
#move any other drivers into one place...
for aDRVRPATH in `find rootfs-complete/usr -type d -name drivers | grep '/xorg/modules/drivers' | tr '\n' ' '`
do
 [ "$aDRVRPATH" == "$XDRVRPATH" ] && continue
 cp -a ${aDRVRPATH}/*.so ${XDRVRPATH}/
 rm -rf ${aDRVRPATH}
done

#131207 for quirky6, only has modesetting and vesa drivers...
#150928 find path, may not be rootfs-complete/usr/lib/xorg/modules/drivers ...
#XDRVRPATH="$(find rootfs-complete/usr -type d -name drivers | grep '/xorg/modules/drivers' | head -n 1)"
XDRVRLIST="$(ls -1 ${XDRVRPATH} | cut -f 1 -d '_' | sort | tr '\n' ' ')"
if [ "$XDRVRLIST" != "modesetting vesa " ];then 

#100319 move more xorg drivers to 'drivers-alternate' so won't be chosen by xorg...
if [ -d $XDRVRPATH ];then #well, always exists. 150928
 XORGBADDRIVERS=''

 #141206 easy-distro/*/*/*/build-choices can have some variables to preset build choices...
 if [ "$BUILD_CHOICE_XORG_DRIVERS_ALTERNATE" ];then
  #optional variable with list of xorg drivers to be moved to backup dir.
  #may have "none", none will be moved.
  NEWXORGBADDRVRS="$BUILD_CHOICE_XORG_DRIVERS_ALTERNATE"
 else
 
  if [ -f ${XDRVRPATH}/nvidia_drv.so -o -f ${XDRVRPATH}/nouveau_drv.so ];then #100527 100629
   [ -f ${XDRVRPATH}/nv_drv.so ] && XORGBADDRIVERS='nv' #120922 note, some builds don't have nv, or it may already be in drivers-alternate dir.
  fi
  [ -f ${XDRVRPATH}/modesetting_drv.so ] && XORGBADDRIVERS="${XORGBADDRIVERS} modesetting" #130330
  if [ "$XDRVRLIST" = "fbdev modesetting vesa " ];then #131208 quirky6
   XORGBADDRIVERS='fbdev'
  fi
  echo
  echo "Certain Xorg drivers have a bad reputation. Here you can choose to move them"
  echo "to /usr/lib/x/drivers-alternate so Xorg will not use them, instead"
  echo "will use the generic 'vesa' driver (or other more appropriate driver)."
  echo "However the Xorg Wizard has a mechanism to move any drivers in "
  echo "'drivers-alternate' back to 'drivers' directory."
  echo "Here is the list of drivers currently in 'drivers-alternate':"
  XORGBADDRIVERS="$XORGBADDRIVERS `ls -1 rootfs-complete/usr/lib/x/drivers-alternate | grep '_drv' | cut -f 1 -d '_' | tr '\n' ' '`"
  echo " $XORGBADDRIVERS"
  echo "Press ENTER only to accept this, or"
  echo "type a space-delimited list of drivers"
  echo -n " that you want to be in 'drivers-alternate': "
  read NEWXORGBADDRVRS
  [ "$NEWXORGBADDRVRS" = "" ] && NEWXORGBADDRVRS="$XORGBADDRIVERS"
 fi
 
 for ONEBADX in $NEWXORGBADDRVRS
 do
  #some builds have i810_drv.so symlink to intel_drv.so...
  if [ -h ${XDRVRPATH}/${ONEBADX}_drv.so ];then
   continue
  fi
  [ -f ${XDRVRPATH}/${ONEBADX}_drv.so ] && mv -f ${XDRVRPATH}/${ONEBADX}_drv.so rootfs-complete/usr/lib/x/drivers-alternate/
 done
 for ONECHK in `ls -1 rootfs-complete/usr/lib/x/drivers-alternate | grep '_drv' | cut -f 1 -d '_' | tr '\n' ' '` #110911
 do
  oPTN=" ${ONECHK} "
  if [ "`echo -n " ${NEWXORGBADDRVRS} " | grep "$oPTN"`" = "" ];then
   if [ ! -d $ONECHK ];then
    mv -f rootfs-complete/usr/lib/x/drivers-alternate/${ONECHK}_drv.so ${XDRVRPATH}/
   else
    echo "SORRY: cannot move '${ONECHK}_drv.so' from drivers-alternate back to"
    echo "main drivers, it must stay as an alternate driver only."
   fi
  fi
 done
fi
fi #131207

#101012 if 'depmod-FULL' exists, rename it to 'depmod'... 101024
if [ "$USINGKMOD" = "no" ];then #130418
 if [ ! -h rootfs-complete/sbin/depmod-FULL ];then #if hyperlink then assume to depmod.
  if [ -f rootfs-complete/sbin/depmod-FULL ];then
   mv -f rootfs-complete/sbin/depmod rootfs-complete/sbin/depmod-BB-NOTUSED
   mv -f rootfs-complete/sbin/depmod-FULL rootfs-complete/sbin/depmod
  fi
  ln -s depmod rootfs-complete/sbin/depmod-FULL
 fi
else
 [ -e rootfs-complete/bin/kmod ] && ln -snf ../bin/kmod rootfs-complete/sbin/depmod #130430 path fix.
fi

#101015 make sure our modified 'alsaconf' is used (just in case got overwritten)... 180411 check exists
[ -f ../rootfs-skeleton/usr/sbin/alsaconf ] && cp -a -f ../rootfs-skeleton/usr/sbin/alsaconf rootfs-complete/usr/sbin/

#w481 extra stripping...
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #120502 strip will not work for cross-build.
 if [ "$BUILD_CHOICE_FILE_STRIP" == "" ];then #200210
  echo
  echo "Would you like to strip all binary executables and shared library files?"
  echo "These are usually already stripped, although some packages may have the shared"
  echo "library files stripped with the '--strip-debug' option only, and extra stripping"
  echo "should be okay. It won't do any harm answering yes here."
  if [ "`which strip`" = "" ];then
   echo
   echo "OH, NO GOOD, you don't have the 'strip' executable. The 'devx' sfs has it."
   echo "PLEASE DECLINE THIS OFFER..."
   echo
  fi
  echo -n "ENTER only to strip, any other printable char to decline: "
  read NOSTRIP
 else
  if [ "$BUILD_CHOICE_FILE_STRIP" == "yes" ];then
   NOSTRIP=''
   if ! which strip >/dev/null;then
    echo "OH, NO GOOD, you don't have the 'strip' executable. The 'devx' sfs has it."
    NOSTRIP='y'
   fi
  else
   NOSTRIP='y'
  fi
 fi
 if [ "$NOSTRIP" = "" ];then
  find rootfs-complete/bin rootfs-complete/sbin rootfs-complete/usr/bin rootfs-complete/sbin -type f |
  while read ONEFILE
  do
   ONEBASE="`basename "$ONEFILE"`"
 #  if [ "`file "$ONEFILE" | grep 'ELF' | grep 'executable' | grep 'dynamically linked'`" != "" ];then #v424 fix.
   [ "$ONEBASE" = "e3" ] && continue #v431 cannot be stripped.
   [ "$ONEBASE" = "QtWeb" ] && continue #130721 cannot be stripped.
   if [ "`file "$ONEFILE" | grep 'ELF' | grep 'executable'`" != "" ];then #v431
    echo -n "$ONEBASE "
    #strip --strip-unneeded "$ONEFILE"
    strip "$ONEFILE" #170704
   fi
  done
  echo
  find rootfs-complete/usr/lib -type f -name \*.so* |
  while read ONEFILE
  do
   ONEBASE="`basename "$ONEFILE"`"
   #v431 libgdk-x11-2.0.so* compiled in pup4 with '--enable-debug', fixes insert-key mozilla crash.
   # it may be unwise to strip its debug symbols... no, it's ok...
   #[ "`echo "$ONEBASE" | grep 'libgdk'`" != "" ] && continue #v431
   if [ "`file "$ONEFILE" | grep 'ELF' | grep 'shared object'`" != "" ];then
    echo -n "$ONEBASE "
    #strip --strip-unneeded "$ONEFILE"
    strip "$ONEFILE" #170704
   fi
  done
  echo
 fi
fi

#100527 build a .pet with lists of all builtin files...
echo
echo "Now building sandbox3/0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.pet,"
echo "which is a PET package with lists of all packages and files in the build..."
rm -rf 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION} 2>/dev/null
mkdir 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}
mkdir /tmp/0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}
for ONEGENDIR in `find ../packages-${DISTRO_FILE_PREFIX} -maxdepth 1 -type d | tr '\n' ' '`
do
 ONEGENNAME="`basename $ONEGENDIR`"
# [ "`echo "$ONEGENNAME" | grep -E '_DEV|_DOC|_NLS|_NULL'`" != "" ] && continue #not really needed.
 ogPATTERN="|${ONEGENNAME}|"
 [ "`echo "$PKGS_SPECS_TABLE" | grep '^yes' | grep "$ogPATTERN"`" == "" ] && continue
 echo -n "$ONEGENNAME "
 ogPATTERN="s%^\\.\\./packages-${DISTRO_FILE_PREFIX}/${ONEGENNAME}/%/%"
 find $ONEGENDIR | sed -e "$ogPATTERN" | sort > /tmp/0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/${ONEGENNAME}.files
 sync
 #store the information more efficiently...
 mkdir -p 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/root/.packages/builtin_files
 PREVPATH=''; PREVPATH0=''
 cat /tmp/0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/${ONEGENNAME}.files |
 while read ONELINE
 do
  [ "`echo "$ONELINE" | cut -c 1`" == "." ] && continue #catch ex: ../packages-qrky/abiword
  if [ -d "rootfs-complete${ONELINE}" ];then
   #120925 ignore debian/ubuntu multiarch circular symlink (these are create by 2createpackages)...
   if [ -h "rootfs-complete${ONELINE}" ];then
    if [ "$(readlink "rootfs-complete${ONELINE}")" = "./" ];then
     PREVPATH0="$(dirname "$ONELINE")" #121010 fix, missing some files.
     [ "$PREVPATH0" != "$PREVPATH" ] && echo "$PREVPATH0" >> 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/root/.packages/builtin_files/${ONEGENNAME} #121010
     continue
    fi
   fi
   PREVPATH="$ONELINE"
   echo "$ONELINE" >> 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/root/.packages/builtin_files/${ONEGENNAME}
  else
   NEWPATH="`dirname "$ONELINE"`"
   [ "$NEWPATH" == "/" ] && continue #ignore top-level files.
   NEWFILE="`basename "$ONELINE"`"
   if [ -e "rootfs-complete${ONELINE}" ];then #sanity check.
    if [ "$PREVPATH" == "$NEWPATH" -o "$PREVPATH0" == "$NEWPATH" ];then #sanity check. 121010
     echo " ${NEWFILE}" >> 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/root/.packages/builtin_files/${ONEGENNAME}
    fi
   fi
  fi
 done
done

echo "0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}|0builtin_files_${DISTRO_FILE_PREFIX}|${DISTRO_VERSION}||BuildingBlock|||0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.pet||Lists of files built-in to the SFS file||||
" > 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/pet.specs
rm -f 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.pet 2>/dev/null

dir2tgz 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}
tgz2pet 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.tar.gz
rm -rf /tmp/0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}
echo
echo "installing pkg lists into rootfs-complete/root/.packages/builtin_files..."
cp -a -f 0builtin_files_${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}/root/.packages/builtin_files rootfs-complete/root/.packages/builtin_files
echo '...done'

#170325 /usr/local/petget/0setup wants this...
[ -f ../build-choices ] && cp -a -f ../build-choices rootfs-complete/root/.packages/

#100613 create font cache for fontconfig (in /var/cache/fontconfig)...
echo
echo "Creating Fontconfig cache files..."
rm -rf rootfs-complete/var/cache/fontconfig
mkdir -p rootfs-complete/var/cache/fontconfig
#111123 ***NOTICE*** cross-build, this will have to be executed at first boot...
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 chroot rootfs-complete /usr/bin/fc-cache -s -v
fi

if [ ! -e rootfs-complete/usr/bin/pango-querymodules ];then #110517 debian squeeze hack
 #cp -f devx/usr/bin/pango-querymodules rootfs-complete/usr/bin/
 if [ -e ../packages-${DISTRO_FILE_PREFIX}/pango_DEV/usr/bin/pango-querymodules ];then #160321
  cp -f ../packages-${DISTRO_FILE_PREFIX}/pango_DEV/usr/bin/pango-querymodules rootfs-complete/usr/bin/
 fi
fi

#100622 slackware 13.1: this file is zero bytes...
#111123 ***NOTICE*** cross-build, this will have to be executed at first boot...
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 mkdir -p rootfs-complete/etc/pango #141118
 PANGOMODULES="`find rootfs-complete/etc/pango -type f -name pango.modules | sed -e 's%rootfs-complete%%'`"
 [ "$PANGOMODULES" = "" ] && PANGOMODULES='/etc/pango/pango.modules'
 if [ ! -s rootfs-complete${PANGOMODULES} ];then
  if [ -e rootfs-complete/usr/bin/pango-querymodules ];then #160321
   echo "/usr/bin/pango-querymodules > ${PANGOMODULES}"  > rootfs-complete/zz
   chroot rootfs-complete /bin/ash zz
   rm -f rootfs-complete/zz
  fi
 fi
fi

#110622 hack for mageia 1 (otherwise can't find pango.modules)...
if [ -d rootfs-complete/etc/pango/i386 ];then
 cp -a -f rootfs-complete/etc/pango/pango.modules rootfs-complete/etc/pango/i386/
 [ -f rootfs-complete/etc/pango/pangox.aliases ] && cp -a -f rootfs-complete/etc/pango/pangox.aliases rootfs-complete/etc/pango/i386/
fi

#110622 /etc/rc.d/rc.update executes:  gdk-pixbuf-query-loaders > /etc/gtk-2.0/gdk-pixbuf.loaders  131229 now done below.
#however, mageia1 requires above file to be at /usr/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache
#create a symlink...
VERDIR=''
if [ -d rootfs-complete/usr/lib${xARCHDIR}/gdk-pixbuf-2.0 ];then
 [ ! -f rootfs-complete/etc/gtk-2.0/gdk-pixbuf.loaders ] && touch rootfs-complete/etc/gtk-2.0/gdk-pixbuf.loaders
 PIXBUFLOADERSDIR="`find rootfs-complete/usr/lib${xARCHDIR}/gdk-pixbuf-2.0 -maxdepth 2 -mindepth 2 -type d -name loaders | head -n 1`"
 if [ "$PIXBUFLOADERSDIR" ];then
  PIXBUFCACHEDIR="`dirname $PIXBUFLOADERSDIR`"
  VERDIR="`basename $PIXBUFCACHEDIR`" #2.10.0
  if [ "$(echo -n "$xARCHDIR" | cut -c 1)" == "/" ];then #150102
   ln -snf ../../../../../etc/gtk-2.0/gdk-pixbuf.loaders ${PIXBUFCACHEDIR}/loaders.cache #110903 change -s to -snf
  else
   ln -snf ../../../../etc/gtk-2.0/gdk-pixbuf.loaders ${PIXBUFCACHEDIR}/loaders.cache #110903 change -s to -snf
  fi
  #there may be some loaders in wrong place...
  [ -d rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/loaders ] && mv -f rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/loaders/*.so ${PIXBUFLOADERSDIR}/ 2>/dev/null
  if [ -d rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders ];then
   #mv -f rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders/*.so ${PIXBUFLOADERSDIR}/ 2>/dev/null
   #150726 with devx merged, have a .la file also in here...
   mv -f rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders/* ${PIXBUFLOADERSDIR}/ 2>/dev/null #150726
   rmdir rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders #111114
  fi
  if [ "$(echo -n "$xARCHDIR" | cut -c 1)" == "/" ];then #150102
   ln -s ../../../${ARCHDIR}/gdk-pixbuf-2.0/${VERDIR}/loaders rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders
  else #161230
   ln -s ../../gdk-pixbuf-2.0/${VERDIR}/loaders rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/loaders #111114
  fi
 fi
fi

#131229 didn't work just appending this...
#131217 librsvg compiled in T2 does not have file 'gdk-pixbuf.loaders', need to insert...
#if [ "`grep 'svg' rootfs-complete/etc/gtk-2.0/gdk-pixbuf.loaders`" = "" ];then
# echo '
#"/usr/lib/gtk-2.0/2.10.0/loaders/libpixbufloader-svg.so"
#"svg" 2 "gtk20" "Scalable Vector Graphics" "LGPL"
#"image/svg+xml" "image/svg" "image/svg-xml" "image/vnd.adobe.svg+xml" "text/xml-svg" ""
#"svg" ""
#" <svg" "*    " 100
#" <!DOCTYPE svg" "*             " 100' >> rootfs-complete/etc/gtk-2.0/gdk-pixbuf.loaders
#fi
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #131229
 #chroot rootfs-complete gdk-pixbuf-query-loaders > /etc/gtk-2.0/gdk-pixbuf.loaders
 #...does not work, do to the redirection, have to do it this way...
 chroot rootfs-complete gdk-pixbuf-query-loaders > /tmp/gdk-pixbuf.loaders
 cp -a -f /tmp/gdk-pixbuf.loaders rootfs-complete/etc/gtk-2.0/gdk-pixbuf.loaders
fi

if [ ! -e rootfs-complete/usr/bin/gtk-update-icon-cache ];then #170429
 if [ -e rootfs-complete/usr/bin/gtk-update-icon-cache-2.0 ];then
  ln -s gtk-update-icon-cache-2.0 rootfs-complete/usr/bin/gtk-update-icon-cache
 elif [ -e rootfs-complete/usr/bin/gtk-update-icon-cache-3.0 ];then
  ln -s gtk-update-icon-cache-3.0 rootfs-complete/usr/bin/gtk-update-icon-cache
 fi
fi
#131217 was doing this at first bootup in rc.update, but no longer in quirky6...
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then
 #note, can use  --ignore-theme-index if want to...
 chroot rootfs-complete /usr/bin/gtk-update-icon-cache -f /usr/share/icons/hicolor/
 #200109 fix...
 #if [ -f rootfs-complete/usr/bin/gtk-update-icon-cache-3.0 ];then #180402 for gtk3
 # chroot rootfs-complete /usr/bin/gtk-update-icon-cache-3.0 -f /usr/share/icons/Adwaita/
 #fi
 chroot rootfs-complete /usr/bin/gtk-update-icon-cache -f /usr/share/icons/Adwaita/
fi

#120605 shinobar ref: http://murga-linux.com/puppy/viewtopic.php?t=76961&start=195
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then
 chroot rootfs-complete /usr/bin/gtk-query-immodules-2.0 > /tmp/gtk.immodulesTEMP
 cp -a -f /tmp/gtk.immodulesTEMP rootfs-complete/etc/gtk-2.0/gtk.immodules
else
 touch rootfs-complete/etc/gtk-2.0/gtk.immodules
fi
if [ "$VERDIR" ];then #161230
 if [ "$(echo -n "$xARCHDIR" | cut -c 1)" == "/" ];then #150102
  ln -snf ../../../../../etc/gtk-2.0/gtk.immodules rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/gtk.immodules
 else
  ln -snf ../../../../etc/gtk-2.0/gtk.immodules rootfs-complete/usr/lib${xARCHDIR}/gtk-2.0/${VERDIR}/gtk.immodules
 fi
fi

#100627 recent versions of xorg server, turn modesetting on... 110822 improve...
mkdir -p rootfs-complete/etc/modprobe.d
#110621 need to chroot...
if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
 XORGINFO="`chroot rootfs-complete /usr/bin/Xorg -version 2>&1`"
 XORGVER="`echo "$XORGINFO" | grep '^X\.Org' | rev | cut -f 1 -d ' ' | rev`"
else
 #cross-build, assume recent xorg...
 XORGVER='1.7.7'
fi
[ "$XORGVER" = "" ] && XORGVER="`echo "$XORGINFO" | grep '^X Window System Version' | rev | cut -f 1 -d ' ' | rev`" #xorg 7.3
[ "$XORGVER" = "" ] && XORGVER="1.3.0" #precaution. version used in original Xorg 7.3.
if vercmp "$XORGVER" gt "1.7.6";then
 
 #180410 offer to preselect xorg modesetting or vesa drivers...
 if [ "$BUILD_CHOICE_XORG_DRIVER_DEF" ];then #191218
  case "$BUILD_CHOICE_XORG_DRIVER_DEF" in
   modesetting) morvora='1' ;;
   vesa)        morvora='2' ;;
   *)           morvora='' ;; #automatic.
  esac
 else
  echo
  echo -n '1 Modesetting
2 vesa
* automatic

Press ENTER for Xorg automatic detection of driver, or
press 1 to preselect the Xorg modesetting driver, or
press 2 to preselect the Xorg vesa driver: '
  read morvora
  case "$morvora" in
   1)
    echo '...chose modesetting driver'
   ;;
   2)
    echo '...chose vesa driver'
   ;;
   *)
    echo '...chose automatic'
   ;;
  esac
 fi
 
 #120616 no, don't do this...
 ##120516 check that these drivers exist...
 #EXTRADRVPTH=''
 #[ -d rootfs-complete/usr/X11R7/lib/dri ] && EXTRADRVPTH='rootfs-complete/usr/X11R7/lib/dri'
 #[ -d rootfs-complete/usr/lib/dri ] && EXTRADRVPTH="${EXTRADRVPTH} rootfs-complete/usr/lib/dri"
 #[ ! "$EXTRADRVPTH" ] && EXTRADRVPTH='/usr/lib'
 #DRILIST=''
 #for AXDRI in i915_dri.so radeon_dri.so nouveau_dri.so
 #do
 # if find ${EXTRADRVPTH} -mindepth 1 -maxdepth 1 -name ${AXDRI}; then
 #  ADRI="`echo -n "$AXDRI" | cut -f 1 -d '_'`"
 #  DRILIST="${DRILIST}${ADRI} "
 # fi
 #done
 #120616 do this...
 DRILIST='i915 radeon nouveau'
 
 #180410
 case "$morvora" in
  1) #modesetting
   mv -f rootfs-complete/etc/X11/xorg.conf-auto-pc-modesetting rootfs-complete/etc/X11/xorg.conf-auto-pc
   rm -f rootfs-complete/etc/X11/xorg.conf-auto-pc-vesa
   for XDRIVER in $DRILIST #i915 radeon nouveau
   do
    echo "options ${XDRIVER} modeset=1"  > rootfs-complete/etc/modprobe.d/${XDRIVER}.conf
   done
  ;;
  2) #vesa
   mv -f rootfs-complete/etc/X11/xorg.conf-auto-pc-vesa rootfs-complete/etc/X11/xorg.conf-auto-pc
   rm -f rootfs-complete/etc/X11/xorg.conf-auto-pc-modesetting
   for XDRIVER in $DRILIST #i915 radeon nouveau
   do
    echo "options ${XDRIVER} modeset=0"  > rootfs-complete/etc/modprobe.d/${XDRIVER}.conf
   done
  ;;
  *) #automatic
   rm -f rootfs-complete/etc/X11/xorg.conf-auto-pc-modesetting
   rm -f rootfs-complete/etc/X11/xorg.conf-auto-pc-vesa
   [ "$BOOT_BOARD" != "pc" ] && DRILIST='' #assume not using kms at all when boot from sd card (arm arch).
   if [ "$DRILIST" != "" ];then
    #191218 do not ask anymore...
    #echo
    #echo "Certain Xorg drivers require KMS (Kernel ModeSetting)"
    #echo "A value of '1' means on, '0' means off."
    #echo "Press ENTER key only to accept the default, any other char to flip:"
    for XDRIVER in $DRILIST #i915 radeon nouveau
    do
     KMSFLG='1'
     #echo -n "${XDRIVER} [${KMSFLG}]: "
     #read KMSREPLY
     #if [ "$KMSREPLY" ];then #110906 fix syntax error.
     # #not the default...
     # case $KMSFLG in
     #  0) echo "options ${XDRIVER} modeset=1"  > rootfs-complete/etc/modprobe.d/${XDRIVER}.conf ;;
     #  1) echo "options ${XDRIVER} modeset=0"  > rootfs-complete/etc/modprobe.d/${XDRIVER}.conf ;;
     # esac
     #else
      echo "options ${XDRIVER} modeset=${KMSFLG}"  > rootfs-complete/etc/modprobe.d/${XDRIVER}.conf
     #fi
    done
   fi
  ;;
 esac #end case morvora
 
fi

#110213 fix if .utf8 entries missing...
if [ "`grep 'nb_NO\.utf8' rootfs-complete/usr/share/X11/locale/locale.alias`" = "" ];then
 echo 'nb_NO.utf8:					nb_NO.UTF-8' >> rootfs-complete/usr/share/X11/locale/locale.alias
fi
if [ "`grep 'nn_NO\.utf8' rootfs-complete/usr/share/X11/locale/locale.alias`" = "" ];then
 echo 'nn_NO.utf8:					nn_NO.UTF-8' >> rootfs-complete/usr/share/X11/locale/locale.alias
fi
if [ "`grep 'ru_UA\.utf8' rootfs-complete/usr/share/X11/locale/locale.alias`" = "" ];then
 echo 'ru_UA.utf8:					ru_UA.UTF-8' >> rootfs-complete/usr/share/X11/locale/locale.alias
fi
if [ "`grep 'ru_RU\.utf8' rootfs-complete/usr/share/X11/locale/locale.alias`" = "" ];then
 echo 'ru_RU.utf8:					ru_RU.UTF-8' >> rootfs-complete/usr/share/X11/locale/locale.alias
fi

#110329 some python files, move to 'devx'...
#121022 but only if python is supposed to be in devx...
if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python-tiny|')" == "" ];then #170517 python-tiny stays in main f.s.
 if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python|' | grep 'exe>dev')" != "" ];then
  PYTHONDIR=''
  [ -d rootfs-complete/usr/lib/python2.5 ] && PYTHONDIR='python2.5'
  [ -d rootfs-complete/usr/lib/python2.6 ] && PYTHONDIR='python2.6'
  [ -d rootfs-complete/usr/lib/python2.7 ] && PYTHONDIR='python2.7'
  if [ "$PYTHONDIR" ];then
   mkdir -p devx/usr/lib/${PYTHONDIR}
   cp -a -f --remove-destination rootfs-complete/usr/lib/${PYTHONDIR}/* devx/usr/lib/${PYTHONDIR}/
   rm -rf rootfs-complete/usr/lib/${PYTHONDIR}
  fi
 fi
fi

#110412 move all .bac, .pot and .pupdev files to 'devx'...
if [ "$BUILD_CHOICE_MERGE_DEVX" != "yes" ];then #150726
 echo "Moving .pot, .pupdev, .bac files to devx..."
 find rootfs-complete/usr -type f -name '*.pot' -o -name '*.pupdev' -o -name '*.bac' |
 while read ONEPD
 do
  DESTDIR="`dirname "$ONEPD" | sed -e 's%rootfs\-complete%%'`"
  mkdir -p "devx${DESTDIR}"
  mv -f "$ONEPD" "devx${DESTDIR}/"
  POTNAME="$(basename "$ONEPD")"
  touch -c "devx${DESTDIR}/${POTNAME}" #coz of the cp -u below.
 done
 #120224 move rootfs-complete/usr/share/doc/nls to 'devx'...
 mkdir -p devx/usr/share/doc/nls
 cp -a -f rootfs-complete/usr/share/doc/nls/* devx/usr/share/doc/nls/
 rm -r -f rootfs-complete/usr/share/doc/nls
 
 #150308 there are other .pot files scattered around...
 find ../packages-${DISTRO_FILE_PREFIX} -mindepth 5 -maxdepth 7 -type f -name '*.pot' |
 while read ONEPOT
 do
  DESTDIR="$(dirname "$ONEPOT" | cut -f 4- -d '/')" #ex: ../packages-april64/xarchive_NLS/usr/share/doc/nls/xarchive becomes usr/share/doc/nls/xarchive
  mkdir -p "devx/${DESTDIR}"
  cp -a -u "$ONEPOT" "devx/${DESTDIR}/"
 done
 sync
 
 #150308 momanager is supposed to work without devx, so copy the .pot files back...
 cp -a -f devx/usr/share/doc/nls rootfs-complete/usr/share/doc/
fi

#110417 this may be helpful for more apps than Thunar...
#this will make Thunar use ROX-Filer's icons for files...
if [ -d rootfs-complete/usr/local/apps/ROX-Filer/ROX/MIME ];then
 if [ ! -e rootfs-complete/usr/share/icons/hicolor/48x48/mimetypes ];then
  ln -s ../../../../local/apps/ROX-Filer/ROX/MIME rootfs-complete/usr/share/icons/hicolor/48x48/mimetypes
 fi
fi

#110421 get version compare utility... 140119... 180903 already have it in pup-tools
#cp -f ../boot/vercmp rootfs-complete/bin/

#110429 fix just in case...
busybox chown -h -R spot:spot rootfs-complete/root/spot

#110429 this is difficult. may need a fix, think want glibc scsi headers in usr/include/scsi...
mkdir -p devx/usr/include
if [ -d ../packages-${DISTRO_FILE_PREFIX}/linux_headers_DEV/usr/include/scsi ];then
 cp -a ../packages-${DISTRO_FILE_PREFIX}/linux_headers_DEV/usr/include/scsi devx/usr/include/scsi-KERNEL
fi
if [ -d ../packages-${DISTRO_FILE_PREFIX}/linux-header_DEV/usr/include/scsi ];then
 cp -a ../packages-${DISTRO_FILE_PREFIX}/linux-header_DEV/usr/include/scsi devx/usr/include/scsi-KERNEL
fi
if [ -d ../packages-${DISTRO_FILE_PREFIX}/glibc_DEV/usr/include/scsi ];then
 cp -a ../packages-${DISTRO_FILE_PREFIX}/glibc_DEV/usr/include/scsi devx/usr/include/scsi-GLIBC
fi
#also see further down, when building devx.

##110517 kms may need to be turned on... ALREADY DONE, SEE 110621 ABOVE
#XINTELMINOR=`grep '^xserver-xorg-video-intel' rootfs-complete/root/.packages/woof-installed-packages | cut -f 3 -d '|' | cut -f 2 -d '.'` #110517 ex: xserver-xorg-video-intel_2.13.0-6_i386.deb extract 13.
#[ ! $XINTELMINOR ] && XINTELMINOR=`grep '^xf86-video-intel' rootfs-complete/root/.packages/woof-installed-packages | cut -f 3 -d '|' | cut -f 2 -d '.'`
#[ ! $XINTELMINOR ] && XINTELMINOR=0
#if [ $XINTELMINOR -gt 9 ];then
# echo 'options i915 modeset=1' > rootfs-complete/etc/modprobe.d/i915.conf
# [ "`grep '^xserver-xorg-video-nouveau' rootfs-complete/root/.packages/woof-installed-packages`" != "" ] && echo 'options nouveau modeset=1' > rootfs-complete/etc/modprobe.d/nvidia.conf
# [ "`grep '^xf86-video-nouveau' rootfs-complete/root/.packages/woof-installed-packages`" != "" ] && echo 'options nouveau modeset=1' > rootfs-complete/etc/modprobe.d/nvidia.conf
# [ "`grep '^xserver-xorg-video-radeon' rootfs-complete/root/.packages/woof-installed-packages`" != "" ] && echo 'options radeon modeset=1' > rootfs-complete/etc/modprobe.d/radeon.conf
# [ "`grep '^xf86-video-radeon' rootfs-complete/root/.packages/woof-installed-packages`" != "" ] && echo 'options radeon modeset=1' > rootfs-complete/etc/modprobe.d/radeon.conf
#fi

#110523 override files from rootfs-skeleton/root/Choices/MIME-types, if rox pkg has older files...
cp -a -f ../rootfs-skeleton/root/Choices/MIME-types/* rootfs-complete/root/Choices/MIME-types/
#110620 do same for mime icons...
cp -a -f --remove-destination ../rootfs-skeleton/usr/local/apps/ROX-Filer/ROX/MIME/* rootfs-complete/usr/local/apps/ROX-Filer/ROX/MIME/

#200711 override mime files from rootfs-skeleton...
cp -a -u ../rootfs-skeleton/usr/share/mime/* rootfs-complete/usr/share/mime/

#130320 these days, i think give util-linux the preference. note, should really fix in e2fsprogs template.
##110701 possible lib clash between e2fsprogs and util-linux (i might use old util-linux pet). hack...
#if [ -e ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs/lib/libblkid.so.1 ];then
# if [ -e ../packages-${DISTRO_FILE_PREFIX}/util-linux/lib/libblkid.so.1 ];then
#  #give e2fsprogs libs preference...
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs/lib/libblkid.so* rootfs-complete/lib/
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs/lib/libuuid.so* rootfs-complete/lib/
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/util-linux_DEV/lib/lib*
# fi
#fi
#130320 i don't think any of this is required, as util-linux is later in the pkg-list so will override anyway.
# so, comment this out also!...
#if [ -e ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs/lib/libblkid.so.1 ];then
# if [ -e ../packages-${DISTRO_FILE_PREFIX}/util-linux/lib/libblkid.so.1 ];then
#  #give util-linux libs preference...
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/util-linux/lib/libblkid.so* rootfs-complete/lib/
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/util-linux/lib/libuuid.so* rootfs-complete/lib/
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/util-linux/usr/lib/libblkid.so* rootfs-complete/lib/ 2>/dev/null
#  cp -a -f --remove-destination ../packages-${DISTRO_FILE_PREFIX}/util-linux/usr/lib/libuuid.so* rootfs-complete/lib/ 2>/dev/null
#  #so that the 'devx' will build ok...
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/lib/libblkid.so* 2>/dev/null
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/lib/libuuid.so* 2>/dev/null
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/usr/lib/libblkid.so* 2>/dev/null
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/usr/lib/libuuid.so* 2>/dev/null
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/usr/lib/pkgconfig/blkid.pc
#  rm -f ../packages-${DISTRO_FILE_PREFIX}/e2fsprogs_DEV/usr/lib/pkgconfig/uuid.pc
# fi
#fi

#130111 fixed in 2createpackages...
##110726 mageia does something weird, puts all these in wrong place (see also devx further down)...
#if [ -d rootfs-complete/usr/bin/multiarch-i386-linux ];then
# cp -a -f --remove-destination rootfs-complete/usr/bin/multiarch-i386-linux/* devx/usr/bin/
# rm -rf rootfs-complete/usr/bin/multiarch-i386-linux
#fi

#110806 if yad installed, no zenity, make sure zenity is symlink to yad...
YAD="`find ./rootfs-complete/bin ./rootfs-complete/sbin ./rootfs-complete/usr/bin ./rootfs-complete/usr/sbin ./rootfs-complete/usr/local/bin -type f -name yad`"
if [ "$YAD" ];then
 ZENITY="`find ./rootfs-complete/bin ./rootfs-complete/sbin ./rootfs-complete/usr/bin ./rootfs-complete/usr/sbin ./rootfs-complete/usr/local/bin -name zenity`"
 if [ ! "$ZENITY"  ];then
  YADDIR="`dirname $YAD`"
  ln -s yad ${YADDIR}/zenity
 fi
fi

#110904 no, now done in pet pkg 'zz_wary52_fixup'...
##110901 i have experimented with building a wary "5.2pre" without libxcb.
##however, many existing apps want it, even though don't use it.
##this is a trick that satisfies them...
#if [ "`grep '^libxcb' rootfs-complete/root/.packages/woof-installed-packages`" = "" ];then
# if [ -e rootfs-complete/usr/X11R7/lib/libX11.so.6 ];then
#  ln -s libX11.so.6 rootfs-complete/usr/X11R7/lib/libxcb-xlib.so.0
#  ln -s libX11.so.6 rootfs-complete/usr/X11R7/lib/libxcb.so.1
# fi
#fi

#141207 make gtkdialog links more logical: 141213 fixed:
DLGFLGX=''; DLGFLG3=''; DLGFLG4=''
GTKDLGX="$(find rootfs-complete/usr/bin rootfs-complete/usr/sbin -maxdepth 1 -name gtkdialog | head -n 1)"
GTKDLG3="$(find rootfs-complete/usr/bin rootfs-complete/usr/sbin -maxdepth 1 -name gtkdialog3 | head -n 1)"
GTKDLG4="$(find rootfs-complete/usr/bin rootfs-complete/usr/sbin -maxdepth 1 -name gtkdialog4 | head -n 1)"
[ "$GTKDLGX" ] && DLGFLGX='X'
[ "$GTKDLG3" ] && DLGFLG3='3'
[ "$GTKDLG4" ] && DLGFLG4='4'
DLGFLGS="${DLGFLGX}${DLGFLG3}${DLGFLG4}"
case $DLGFLGS in
 X) #only have gtkdialog
  DLGPATH="$(dirname $GTKDLGX)"
  ln -s gtkdialog ${DLGPATH}/gtkdialog3
  ln -s gtkdialog ${DLGPATH}/gtkdialog4
 ;;
 X3)
  DLGPATH="$(dirname $GTKDLGX)"
  ln -s gtkdialog ${DLGPATH}/gtkdialog4
 ;;
 X4)
  DLGPATH="$(dirname $GTKDLGX)"
  ln -s gtkdialog ${DLGPATH}/gtkdialog3
 ;;
esac

#110822 some customisations provided by 01micko for Slacko...
#if [ "$DISTRO_BINARY_COMPAT" = "slackware" ];then
if [ "$DISTRO_FILE_PREFIX" = "slacko" ];then #130321
 if [ -f ../support/slacko/woof_base_hack  ];then
  echo "Running Slacko customization script ../support/slacko/woof_base_hack..."
  ../support/slacko/woof_base_hack
 fi
fi

#111123 put this into target, want to know if cross-build at 1st boot (see rc.update)...
[ -f ../WOOFMERGEVARS ] && cp -f ../WOOFMERGEVARS rootfs-complete/etc/rc.d/

#140127 multiarch fix for glib-compile-schemas...
#120522 precise puppy, seamonkey was crashing. needed /usr/share/glib-2.0/schemas/apps.gecko-mediaplayer.preferences,
# but also needs this compile operation...
# ***NOTICE*** cross-build, this will have to be executed at first boot...
#160927 always create the symlinks...
#if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then
 if [ -d rootfs-complete/usr/share/glib-2.0/schemas ];then
  [ -e rootfs-complete/usr/lib${xARCHDIR}/glib-2.0/glib-compile-schemas ] && ln -s ../lib${xARCHDIR}/glib-2.0/glib-compile-schemas rootfs-complete/usr/bin/glib-compile-schemas #140127
  [ -e rootfs-complete/usr/lib${xARCHDIR}/glib-2.0/glib-compile-resources ] && ln -s ../lib${xARCHDIR}/glib-2.0/glib-compile-resources rootfs-complete/usr/bin/glib-compile-resources #160927
  [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ] && [ -e rootfs-complete/usr/bin/glib-compile-schemas ] && chroot rootfs-complete /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
 fi
 #120523 seems need this too... 140125...
 if [ -d rootfs-complete/usr/lib${xARCHDIR}/gio/modules ];then
  [ -e rootfs-complete/usr/lib${xARCHDIR}/glib-2.0/gio-querymodules ] && ln -s ../lib${xARCHDIR}/glib-2.0/gio-querymodules rootfs-complete/usr/bin/gio-querymodules #140127
  [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ] && [ -e rootfs-complete/usr/bin/gio-querymodules ] && chroot rootfs-complete /usr/bin/gio-querymodules /usr/lib${xARCHDIR}/gio/modules
 fi
#fi

#120618 raspi debian squeeze, links as main browser, helpsurfer html viewer, gtkmoz missing...
#120620 problem, helpsurfer cannot display /usr/share/doc/index.html, so do not point gtkmoz at basichtmlviewer...
if [ ! -e rootfs-complete/usr/local/bin/gtkmoz ];then
 ln -s defaultbrowser rootfs-complete/usr/local/bin/gtkmoz
fi

#120704 some constraints in a small system...
#ask if want to load swap partition/file... 200110...
if [ "$BUILD_CHOICE_LOAD_SWAP_BOOTUP" == "yes" ];then
 wantswap=''
elif [ "$BUILD_CHOICE_LOAD_SWAP_BOOTUP" == "no" ];then
 wantswap='no'
else
 echo
 echo "Puppy will normally load a swap partition or swap file if it/they exist,
however you can choose to ignore them and not load them at bootup."
 echo -n "Press ENTER key to load swap at bootup, any key otherwise: "
 read wantswap
fi
if [ "$wantswap" != "" ];then
 echo "BOOT_DISABLESWAP='yes'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #read by /etc/rc.d/rc.sysinit
 echo "...BOOT_DISABLESWAP='yes' in /etc/rc.d/BOOTCONSTRAINED, read by rc.sysinit."
fi
#this also reduces writes to flash card... um, relatime seems to be the default anyway... 120707 change to noatime...
echo "BOOT_ATIME='noatime'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #rc.sysinit will remount / with 'relatime' (constrains updating access time). 120707 change to noatime.
#this file in rootfs-skeleton, overwrite...
echo 'none          /proc        proc     defaults,noatime               0 0
none          /sys         sysfs    defaults,noatime               0 0
none          /dev/pts     devpts   gid=2,mode=620,noatime         0 0
shmfs         /dev/shm     tmpfs    defaults,noatime      0 0' > rootfs-complete/etc/fstab
 #180108 echo "BOOT_DIRTYWRITE='1500'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #defer writing to disk. refer: http://www.lesswatts.org/tips/disks.php
 echo "BOOT_SCHEDULER='deadline'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #my kernel defaults to 'cfq', change to 'deadline'. refer: http://tombuntu.com/index.php/2008/09/04/four-tweaks-for-using-linux-with-solid-state-drives/
 #echo "BOOT_QUICKSETUP='quickarm'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120708 leaves out X config frame. 120714 removed.
#200126 echo "BOOT_UDEVDCHILDREN='1'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120709 is this a good idea? append --children-max=1 to udevd in rc.sysinit.
 echo "BOOT_BOARD='${BOOT_BOARD}'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120714 read by quicksetup.

if [ "$BOOT_BOARD" != "pc" ];then #171221
 echo "BOOT_DISABLEXORGWIZARD='yes'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120723 read in xwin, also xorgwizard. also see below.
 echo "BOOT_DISABLEALSACONF='yes'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120724 'alsaconf' does not work on arm boards.
else
 echo "BOOT_DISABLEXORGWIZARD='no'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120723 read in xwin, also xorgwizard. also see below.
 echo "BOOT_DISABLEALSACONF='no'" >> rootfs-complete/etc/rc.d/BOOTCONSTRAINED #120724 'alsaconf' does not work on arm boards.
fi

#120723 code moved down, add BOOT_DISABLEXORGWIZARD test...
#110413 variable DISTRO_XORG_AUTO in /etc/DISTRO_SPECS, see also /usr/bin/xwin
autoflag='no'
if [ "$BOOT_DISABLEXORGWIZARD" != "yes" ];then
 if [ "$DISTRO_XORG_AUTO" ];then
  autoflag="$DISTRO_XORG_AUTO"
 else
  if vercmp "$XORGVER" ge "1.7.0";then #110621
   echo
   echo "Do you want Xorg to start automatically at first boot (or at 'pfix=ram'"
   echo "kernel boot param) or run Xorg Wizard? The latter has been the case for"
   echo "earlier puppies. Automatic startup of X usually works, though in some"
   echo "cases may choose the wrong monitor resolution or driver -- which can be"
   echo "fixed by running Xorg Wizard afterward."
   echo -n "Press ENTER only for automatic Xorg: "
   read xorgauto
   [ "$xorgauto" = "" ] && autoflag='yes'
  fi
 fi
fi
if [ "`grep '^DISTRO_XORG_AUTO' rootfs-complete/etc/DISTRO_SPECS`" = "" ];then #110621
 echo "DISTRO_XORG_AUTO='${autoflag}'" >> rootfs-complete/etc/DISTRO_SPECS
else
 REGEXauto="s%^DISTRO_XORG_AUTO.*%DISTRO_XORG_AUTO='${autoflag}'%"
 sed -i -e "$REGEXauto" rootfs-complete/etc/DISTRO_SPECS
fi


#120709 debian squeeze has /usr/share/misc/pci.ids, usb.ids, which confuses some apps, create symlinks...
if [ ! -e rootfs-complete/usr/share/pci.ids ];then
 if [ -e rootfs-complete/usr/share/misc/pci.ids ];then
  ln -s misc/pci.ids rootfs-complete/usr/share/pci.ids
 fi
fi
if [ ! -e rootfs-complete/usr/share/usb.ids ];then
 if [ -e rootfs-complete/usr/share/misc/usb.ids ];then
  ln -s misc/usb.ids rootfs-complete/usr/share/usb.ids
 fi
fi

#120830 my hunspell-en-us pet has pinstall.sh that creates symlinks of en_US.aff and en_US.dic
#from seamonkey and firefox. however, need to do this thoroughly...
#note: see also woof rootfs-skeleton/usr/share/doc/langpack-template (used by momanager).
if [ -d rootfs-complete/usr/share/hunspell ];then
 for ONEHUN in `find rootfs-complete/usr/share/hunspell -mindepth 1 -maxdepth 1 -type f -name '*.dic' -o -name '*.aff' | tr '\n' ' '`
 do
  HUNBASE="`basename $ONEHUN`"
  DICTDIRS="`find rootfs-complete/usr/lib -mindepth 2 -maxdepth 2 -type d -name dictionaries | tr '\n' ' '`"
  for ONEDICTDIR in $DICTDIRS
  do
   [ ! -e ${ONEDICTDIR}/${HUNBASE} ] && ln -s ../../../share/hunspell/${HUNBASE} ${ONEDICTDIR}/${HUNBASE}
  done
 done
fi

#121022 may need this (see below similar code if python in devx)...
if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python|' | grep 'exe>dev')" = "" ];then
 [ -e rootfs-complete/usr/bin/python2.5 ] && ln -s python2.5 rootfs-complete/usr/bin/python 2>/dev/null
 [ -e rootfs-complete/usr/bin/python2.6 ] && ln -s python2.6 rootfs-complete/usr/bin/python 2>/dev/null
 [ -e rootfs-complete/usr/bin/python2.7 ] && ln -s python2.7 rootfs-complete/usr/bin/python 2>/dev/null
fi

#121203 bacon hug gui apps need some .so libs, for example libgtk-x11-2.0.so,
#(refer /usr/sbin/welcome1stboot.bac), however these are only in the devx.
#so need to create them... 161231 fix lib path...
#note, i think this problem only in wary/racy, as gtk template creates these symlinks.
if [ ! -e rootfs-complete/usr/lib${xARCHDIR}/libgtk-x11-2.0.so ];then
 FNDGTKLIB="$(find rootfs-complete/usr/lib${xARCHDIR}/ -mindepth 1 -maxdepth 1 -name 'libgtk-x11-2.0.so.[0-9]' | head -n 1 | rev | cut -f 1 -d '/' | rev)"
 [ "$FNDGTKLIB" ] && ln -s $FNDGTKLIB rootfs-complete/usr/lib${xARCHDIR}/libgtk-x11-2.0.so #2> /dev/null
fi
#i'll do the same for libgdk-x11-2.0.so ...
if [ ! -e rootfs-complete/usr/lib${xARCHDIR}/libgdk-x11-2.0.so ];then
 FNDGDKLIB="$(find rootfs-complete/usr/lib${xARCHDIR}/ -mindepth 1 -maxdepth 1 -name 'libgdk-x11-2.0.so.[0-9]' | head -n 1 | rev | cut -f 1 -d '/' | rev)"
 [ "$FNDGTKLIB" ] && ln -s $FNDGTKLIB rootfs-complete/usr/lib${xARCHDIR}/libgdk-x11-2.0.so #2> /dev/null
fi

#121212 puinstall.sh was not getting removed...
[ -f rootfs-complete/puninstall.sh ] && rm -f rootfs-complete/puninstall.sh

#130326 now permanently 96... 130327 reintroduce a choice...
##130129 /root/.Xresources has dpi set to 78 in all prior pups. In future, might prefer 96...
#141206 now have DEFAULT_THEME_XORG_TEXT_DPI (usually =96).
if [ "$DEFAULT_THEME_XORG_TEXT_DPI" != "" ];then #141206
 dpisizeflag="$DEFAULT_THEME_XORG_TEXT_DPI"
else
 DPILINE="$(grep '^Xft\.dpi:' rootfs-complete/root/.Xresources)"
 DPIVALUE=$(echo -n "$DPILINE" | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' ')
 echo
 echo "rootfs-complete/root/.Xresources has this line:"
 echo "$DPILINE"
 echo "which sets the displayed size of fonts on the screen (but not bitmap fonts)."
 DPINEXT1=`expr $DPIVALUE + 6`
 DPINEXT2=`expr $DPINEXT1 + 6`
 echo "To accept this size, just press ENTER key."
 echo "However, if you would like fonts to display bigger on the screen, type in
a value now. The value should be in steps of 6, for example ${DPINEXT1} or ${DPINEXT2}.
The default size is ${DPIVALUE}, you might try the next-up, ${DPINEXT1}."
 echo -n "Press ENTER key for '${DPIVALUE}' dpi, or type a value: "
 read dpisizeflag
fi
if [ "$dpisizeflag" ];then #130512 scsijon: fix size...
 fsPTN='s%^Xft\.dpi:.*%Xft.dpi: '"${dpisizeflag}%"
 sed -i -e "$fsPTN" rootfs-complete/root/.Xresources
 echo "...ok, dpi now ${dpisizeflag}"
fi

#130226 wary: /usr/bin/X was missing...
if [ ! -e rootfs-complete/usr/bin/X ];then
 if [ -e rootfs-complete/usr/bin/Xorg -o -h rootfs-complete/usr/bin/Xorg ];then
  ln -s Xorg rootfs-complete/usr/bin/X
 fi
fi

#130601 optional, run internet apps as user 'spot'...
echo
echo "Puppy is normally run as the 'administrator' (root) user, though there is
also 'fido' which is not currently very mature.
The structure of Puppy is such that we consider root to be safe (with a full
disclaimer of any responsibility if anything does go wrong), but there is a
compromise, to run as root but to run Internet apps as user 'spot'."
if [ -e rootfs-complete/usr/bin/seamonkey ];then #161231
 echo
 echo "Type any character then ENTER if you want SeaMonkey to run as spot,
or just ENTER not to. Note, in a running 'Puppy Menu->System->Login & Security
Manager' can be used to enable or disable running as spot."
 echo
 echo -n "ENTER only to not run SeaMonkey as spot: "
 read SPOTAPPS
 if [ "$SPOTAPPS" ];then
  ../support/setup-spot 'seamonkey=true' #130604
  echo '...ok, SeaMonkey will run as spot.'
 else
  echo 'seamonkey=false' > rootfs-complete/root/.spot-status #130604 so that an unticked checkbox will display in loginmanager.
  echo '...ok, SeaMonkey will not run as spot.'
 fi
fi
#130720 add QtWeb... 130723 add opera... 130821 add firefox... 140215 chromium...
for AINTERNETAPP in chromium QtWeb opera firefox
do
 [ ! -e rootfs-complete/usr/bin/${AINTERNETAPP} ] && continue
 echo
 echo "Type any character then ENTER if you want ${AINTERNETAPP} to run as spot,
or just ENTER not to. Note, in a running Puppy 'Menu->System->Login & Security
Manager' can be used to enable or disable running as spot."
 echo
 echo -n "ENTER only to not run ${AINTERNETAPP} as spot: "
 read SPOTAPPS
 if [ "$SPOTAPPS" ];then
  ../support/setup-spot "${AINTERNETAPP}=true"
  echo "...ok, ${AINTERNETAPP} will run as spot."
 else
  echo "${AINTERNETAPP}=false" >> rootfs-complete/root/.spot-status #so that an unticked checkbox will display in loginmanager.
  echo "...ok, ${AINTERNETAPP} will not run as spot."
 fi
done
#setup-spot is also called by the Login & Security Manager in running Puppy...
cp -f ../support/setup-spot rootfs-complete/usr/sbin/

#130618 code above sets DEVTMPFSFLG...
#130612 if kernel has CONFIG_DEVTMPFS=y (and CONFIG_DEVTMPFS_MOUNT=y) then empty /dev...
if [ $DEVTMPFSFLG -ne 0 ];then
 rm -rf rootfs-complete/dev/*
 sed -i -e 's%^DEVTMPFSFLG=.*%DEVTMPFSFLG=2%' rootfs-complete/etc/rc.d/rc.sysinit
fi

#130725 want Menu -> Help to use secondary browser... 130726 fix...
#code to detect dual browsers, taken out of /usr/sbin/delayedrun...
ALTBROWSER=''
#the pinstall.sh script in qtweb and opera pets create separate desktop icon if there is another major browser...
[ "`grep 'QtWeb' rootfs-complete/root/Choices/ROX-Filer/PuppyPin`" != "" ] && ALTBROWSER='QtWeb'
[ "`grep 'opera' rootfs-complete/root/Choices/ROX-Filer/PuppyPin`" != "" ] && ALTBROWSER='opera'
if [ "$ALTBROWSER" != "" ];then
 MAINBROWSER="`grep '^exec' rootfs-complete/usr/local/bin/defaultbrowser | tr '\t' ' ' | tr -s ' ' | cut -f 2 -d ' '`"
 if [ "$MAINBROWSER" != "$ALTBROWSER" ];then
  echo '#!/bin/sh' > rootfs-complete/usr/local/bin/defaulthtmlviewer
  echo "exec ${ALTBROWSER} \"\$@\"" >> rootfs-complete/usr/local/bin/defaulthtmlviewer
  chmod 755 rootfs-complete/usr/local/bin/defaulthtmlviewer
 fi
fi

#171008 this was in 3builddistro, bring back...
echo "Searching rootfs-complete for *QNEW files..."
for AQ6 in `find rootfs-complete -maxdepth 5 -type f -name '*QNEW' | tr '\n' ' '`
do
 QNAME="`basename $AQ6 QNEW`"
 QPATH="`dirname $AQ6`"
 [ -e ${QPATH}/${QNAME} ] && rm -f ${QPATH}/${QNAME}
 echo "executing: mv -f ${AQ6} ${QPATH}/${QNAME}"
 mv -f ${AQ6} ${QPATH}/${QNAME} #ex: cpQNEW renamed to cp.
done

if [ "$BUILD_CHOICE_MERGE_DEVX" != "yes" ];then #150814
 #140124 there may be some stray .a files, move them to devx... 161231 fix...
 [ "$xARCHDIR" == "64" ] && EXTRALIBS="rootfs-complete/lib${xARCHDIR} rootfs-complete/usr/lib${xARCHDIR}"
 for ASO in `find rootfs-complete/usr/lib rootfs-complete/lib ${EXTRALIBS} -name '*.a' | sed -e 's%rootfs-complete/%%' | tr ' ' 'x' | tr '\n' ' '`
 do
  ADIR="`dirname $ASO`"
  ANAME="`basename $ASO`"
  if [ -e rootfs-complete/${ADIR}/${ANAME} ];then
   mkdir -p devx/${ADIR}
   mv -f rootfs-complete/${ADIR}/${ANAME} devx/${ADIR}/
  fi
 done
fi
sync

#140125 disable gtk dependency on a stupid gnome daemon... do always, in case future install gtk3...
#ref: http://forums.gentoo.org/viewtopic-t-947210-start-0.html
#if [ -d rootfs-complete/usr/lib${xARCHDIR}/gtk-3.0 ];then
 mkdir -p rootfs-complete/etc/profile.d
 echo 'export NO_AT_BRIDGE=1' > rootfs-complete/etc/profile.d/gtk3
#fi

#140202 set default dirs into /file... 170221 "home" is now /mnt/wkg/home, where wkg is a symlink.
###WORK IN PROGRESS###
#hmmm, rox cannot change "home directory", but, can do this... 170215 /file to /mnt/home 170221 now /mnt/wkg/home 190829 now /home
#190829 /mnt/wkg/home now /home 190904 "file" changed to "home"...
sed -i -e 's%label="home"%label="home" args="--dir=/home"%' rootfs-complete/root/Choices/ROX-Filer/PuppyPin
if [ -d rootfs-complete/root/.mozilla/seamonkey ];then
 SMPREFS="$(find rootfs-complete/root/.mozilla/seamonkey -type f -name 'prefs.js' | head -n 1)"
 [ "$SMPREFS" ] && sed -i -e 's%/root/my-documents%/home/downloads%' -e 's%/root/Downloads%/home/downloads%' ${SMPREFS} #190829 190904
 [ "$SMPREFS" ] && sed -i -e 's%/mnt/wkg/home%/home%' ${SMPREFS} #190904
fi
#170221 would rather the "file" icon opened at the actual path, /mnt/$WKG_DEV/${WKG_DIR}home, so doing this every bootup in rc.sysinit

#140215 chromium needs some libs that are in seamonkey, make sure all symlinks exist. 161231 fix...
#191009 do not create symlinks if already exist system libs...
SMPATH=""
[ -e rootfs-complete/usr/lib/seamonkey ] && SMPATH='usr/lib'
[ ! "$SMPATH" ] && [ -e rootfs-complete/usr/lib64/seamonkey ] && SMPATH='usr/lib64' #slackware pkg.
if [ "$SMPATH" ];then
 for ALIBLINK in libmozsqlite3.so libnspr4.so libnss3.so  libnssckbi.so libnssutil3.so libplc4.so libplds4.so libsmime3.so libsoftokn3.so libssl3.so
 do
  [ -e rootfs-complete/usr/lib/${ALIBLINK} ] && continue #191009
  [ -e rootfs-complete/usr/lib64/${ALIBLINK} ] && continue #191009 note, lib64 is a symlink in debian/buster.
  #if [ ! -e rootfs-complete/${SMPATH}/${ALIBLINK} ];then
   ln -s seamonkey/${ALIBLINK} rootfs-complete/${SMPATH}/${ALIBLINK}
  #fi
 done
fi

#190113 download and install seamonkey language-pack...
mkdir -p seamonkey-langpacks
if [ "$SMPATH" ];then
 #200220 problem have 2.53.1b1 but folder is 2.53.1...
 #SMVER="$(find rootfs-complete/${SMPATH} -mindepth 1 -maxdepth 1 -type d -name 'seamonkey-*' | head -n 1 | rev | cut -f 1 -d '-' | rev)"
 SMVER="$(grep '|seamonkey|' ../woof-installed-packages | head -n 1 | cut -f 3 -d '|' | cut -f 1 -d '-')"
 SMDL=""
 case "$DEFAULTLANG1" in
  cs|de|fr|hu|it|ja|lt|nl|pl|ru|sk) SMDL="${DEFAULTLANG1}" ;;
  en) SMDL='en-GB' ;;
  es) SMDL='es-AR es-ES' ;;
  pt) SMDL='pt-PT' ;;
  sv) SMDL='sv-SE' ;;
  zh) SMDL='zh-CN zh-TW' ;;
 esac
 for aSMDL in $SMDL
 do
  if [ ! -f seamonkey-langpacks/seamonkey-${SMVER}.${aSMDL}.langpack.xpi ];then
   echo
   echo "Do you want to download a ${aSMDL} langpack for SeaMonkey?"
   echo "Requires Internet access."
   echo -n "Press ENTER only for yes: "
   read smdlflg
   if [ "$smdlflg" == "" ];then
    cd seamonkey-langpacks
    #190912 path has changed... 200220 fix...
    #case "$SMVER" in
    # 2.49.4)
      download_file https://archive.mozilla.org/pub/seamonkey/releases/${SMVER}/langpack/seamonkey-${SMVER}.${aSMDL}.langpack.xpi
    # ;;
    # *) #2.49.5
    #  download_file https://archive.mozilla.org/pub/seamonkey/releases/${SMVER}/langpacks/linux-i686/seamonkey-${SMVER}.${aSMDL}.langpack.xpi
    # ;;
    #esac
    cd .. 
   fi
  fi
  if [ -f seamonkey-langpacks/seamonkey-${SMVER}.${aSMDL}.langpack.xpi ];then
   #echo "  installing SM ${aSMDL} langpack to rootfs-complete/${SMPATH}/seamonkey-${SMVER}/extensions"
   #the name needs to be in this format: langpack-en-GB@seamonkey.mozilla.org.xpi
   #cp -a -f seamonkey-langpacks/seamonkey-${SMVER}.${aSMDL}.langpack.xpi rootfs-complete/${SMPATH}/seamonkey-${SMVER}/extensions/langpack-${aSMDL}@seamonkey.mozilla.org.xpi
   #...no, global install, it is disabled at startup. install here, it is enabled at startup...
   SMPREFDIR="$(dirname $SMPREFS)"
   echo "Installing SM ${aSMDL} langpack to ${SMPREFDIR}/extensions"
   mkdir -p ${SMPREFDIR}/extensions #ex: rootfs-complete/root/.mozilla/seamonkey/3o1ptd5r.default/extensions
   cp -a -f seamonkey-langpacks/seamonkey-${SMVER}.${aSMDL}.langpack.xpi ${SMPREFDIR}/extensions/langpack-${aSMDL}@seamonkey.mozilla.org.xpi
   #activate it... 
   if ! grep 'extensions\.ui\.locale' ${SMPREFS} >/dev/null;then
    echo "user_pref(\"general.useragent.locale\", \"${aSMDL}\");
user_pref(\"extensions.ui.dictionary.hidden\", true);
user_pref(\"extensions.ui.lastCategory\", \"addons://list/locale\");
user_pref(\"extensions.ui.locale.hidden\", false);" >> ${SMPREFS} #prefs.js
    #getting addon to be enabled at first startup is tricky, this works...
    #note, it may also be possible to preload user_pref("extensions.bootstrappedAddons", "{}");
    echo "user_pref(\"extensions.autoDisableScopes\", 0);" >> ${SMPREFS}
   fi
  fi
 done
fi

#190804 grab all the debs with translations...
if [ "$DEFAULTLANG1" != "en" ];then
 echo "Do you want to find extra '${DEFAULTLANG1}' translation pkgs? Requires Internet connect."
 echo -n "ENTER only for yes: "
 read yeslangpkgs
 if [ "$yeslangpkgs" == "" ];then
  [ -d temp2 ] && rm -rf temp2
  mkdir temp2
  mkdir -p pkgs-${DEFAULTLANG1}
  case "$DISTRO_BINARY_COMPAT" in
   debian|ubuntu|devuan|raspbian)
    repoSPEC="${REPOS_DISTRO_COMPAT/ */}" #get 1st entry, ex: http.us.debian.org|http://http.us.debian.org/debian|Packages-debian-${DISTRO_COMPAT_VERSION}-*
    repoURL="$(echo -n "$repoSPEC" | cut -f 2 -d '|')"
    repoDB="Packages-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}-main"
    fndDBentries="$(grep "\-${DEFAULTLANG1}_" ../${repoDB} | grep -v -E '\-help-|\-doc-' | cut -f 7,8 -d '|')" #ex: pool/main/a/abe|abe_1.1+dfsg-3_amd64.deb
    for aENTRY in ${fndDBentries}
    do
     [ "$aENTRY" == "" ] && continue
     aPATH="${aENTRY/|*/}"
     aDEB="${aENTRY/*|/}"
     aNAME="${aDEB/_*/}" #200210 ex: libreoffice-l10n-de_6.1.5-3_all.deb, extract libreoffice-l10n-de
     if [ ! -f pkgs-${DEFAULTLANG1}/${aDEB} ];then
      cd pkgs-${DEFAULTLANG1}
      rm -f ${aNAME}_*deb #200210 remove old debs.
      download_file ${repoURL}/${aPATH}/${aDEB}
      cd ..
     fi
    done
    for aDEB in pkgs-${DEFAULTLANG1}/*
    do
     case "$aDEB" in #190821 restrict choices, ex: pkgs-de/firefox-esr-l10n-de_60.7.2esr-1_all.deb
      *firefox*|*hunspell*|*libreoffice*) true ;;
      *) continue ;;
     esac
     echo "  installing ${aDEB}..."
     dpkg-deb -x ${aDEB} temp2/
     rm -rf temp2/DEBIAN*
     cp -a -f --remove-destination temp2/* rootfs-complete/
     sync
     rm -rf temp2/*
    done
   ;;
  esac
 fi
fi

#140215 chromium looks for executable 'lsb_release' but this is a python3 script,
#so have created my own script, see rootfs-skeleton/usr/bin
#also create this, maybe debian/ubuntu apps want it...
echo "LSB_VERSION=n/a
DISTRIB_ID=Quirky
DISTRIB_RELEASE=${DISTRO_VERSION}
DISTRIB_CODENAME=${DISTRO_FILE_PREFIX}
DISTRIB_DESCRIPTION=\"${DISTRO_NAME}\"" > rootfs-complete/etc/lsb-release

#141207 'planner' pet installs /var/scrollkeeper, but 'scrollkeeper' pkg has same stuff in /var/lib
#(which I have put into the devx). hope not really needed at runtime...
if [ -d rootfs-complete/var/scrollkeeper ];then
 SKFND=0
 [ -d ../packages-${DISTRO_FILE_PREFIX}/scrollkeeper/var/scrollkeeper ] && SKFND=1
 [ -d ../packages-${DISTRO_FILE_PREFIX}/scrollkeeper_DEV/var/scrollkeeper ] && SKFND=1
 if [ $SKFND -eq 0 ];then
  #so, scrollkeeper has that info elsewhere, so delete this planner stuff
  rm -rf rootfs-complete/var/scrollkeeper
 fi
fi

#150224 moved up... 170731 removed...
##maybe need link to release notes...
##note, removed some code from rootfs-skeleton/pinstall.sh
#if [ ! -f rootfs-complete/usr/share/doc/release-${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.htm ];then
# RELNOTE="$(ls -1 rootfs-complete/usr/share/doc/release-${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}*.htm 2>/dev/null | rev | cut -f 1 -d '/' | rev | sort --key=3 --field-separator='-' --version-sort | tail -n 1)" #161022
# [ ! "$RELNOTE" ] && RELNOTE="$(ls -1 rootfs-complete/usr/share/doc/release-${DISTRO_FILE_PREFIX}*.htm 2>/dev/null | rev | cut -f 1 -d '/' | rev | sort --key=3 --field-separator='-' --version-sort | tail -n 1)"
# [ ! "$RELNOTE" ] && RELNOTE="$(ls -1 rootfs-complete/usr/share/doc/release-Quirky*.htm | rev | cut -f 1 -d '/' | rev | sort --key=3 --field-separator='-' --version-sort | tail -n 1)"
# RELNOTEVER="$(echo -n "$RELNOTE" | cut -f 3 -d '-' | rev | cut -f 2- -d '.' | rev)"
# ln -s ${RELNOTE} rootfs-complete/usr/share/doc/release-${DISTRO_FILE_PREFIX}-${DISTRO_VERSION}.htm
#fi

if [ -d rootfs-complete/defaults ];then #150725 left behind by busybox.
 rm -rf rootfs-complete/defaults
fi

if [ "$BUILD_CHOICE_MERGE_DEVX" == "yes" ];then #150725
 #there is some stuff did down when building devx, now do it here...
 if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python|')" != "" ];then
  [ -e rootfs-complete/usr/bin/python2.7 ] && ln -s python2.7 rootfs-complete/usr/bin/python 2>/dev/null
  [ -e rootfs-complete/usr/bin/python2.6 ] && ln -s python2.6 rootfs-complete/usr/bin/python 2>/dev/null
  [ -e rootfs-complete/usr/bin/python2.5 ] && ln -s python2.5 rootfs-complete/usr/bin/python 2>/dev/null
 fi

 rm -f rootfs-complete/usr/lib/mozilla/plugins/*.a 2>/dev/null #maybe .a, .la files in here.
 rm -f rootfs-complete/usr/lib/mozilla/plugins/*.la 2>/dev/null

 #there's unwanted docs here, move them out...
 rm -rf ../packages-${DISTRO_FILE_PREFIX}/leftovers_DOC 2>/dev/null
 mkdir -p ../packages-${DISTRO_FILE_PREFIX}/leftovers_DOC/usr/share
 mv rootfs-complete/usr/share/doc-base ../packages-${DISTRO_FILE_PREFIX}/leftovers_DOC/usr/share/ 2>/dev/null
 mv rootfs-complete/usr/share/man ../packages-${DISTRO_FILE_PREFIX}/leftovers_DOC/usr/share/ 2>/dev/null
 
 ##hack, this symlink needed...
 #if [ -d rootfs-complete/usr/X11R7/include/xorg ];then
 # [ ! -e rootfs-complete/usr/include/xorg ] && ln -s ../X11/include/xorg rootfs-complete/usr/include/xorg
 #fi
 
 #remove overhead of this script running every bootup...
 mkdir -p rootfs-complete/etc/profile.d
 rm -f rootfs-complete/etc/profile.d/pkgconfig* 2>/dev/null #improve...
 DEVXLIBnorm=''; DEVXLIB64=''; DEVXUSRLIB64=''
 [ -d rootfs-complete/lib ] && DEVXLIBnorm='rootfs-complete/lib'
 [ -d rootfs-complete/lib64 ] && [ ! -h rootfs-complete/lib64 ] && DEVXLIB64='rootfs-complete/lib64'
 [ -d rootfs-complete/usr/lib64 ] && [ ! -h rootfs-complete/usr/lib64 ] && DEVXUSRLIB64='rootfs-complete/usr/lib64'
 PKG_CONFIG_PATH="`find ${DEVXLIBnorm} ${DEVXLIB64} ${DEVXUSRLIB64} rootfs-complete/usr/share rootfs-complete/usr/lib rootfs-complete/opt rootfs-complete/usr/local/lib -type d -name pkgconfig | sed -e 's%rootfs\-complete%%' | tr '\n' ':' | sed -e 's%:$%%'`"
 echo "export PKG_CONFIG_PATH='${PKG_CONFIG_PATH}'" > rootfs-complete/etc/profile.d/pkgconfig
 
 #maybe stray /install dir from slackware pkgs...
 rm -rf rootfs-complete/install 2>/dev/null
 [ -f rootfs-complete/pet.specs ] && rm -f rootfs-complete/pet.specs
 
 #think want glibc scsi headers in usr/include/scsi...
 if [ -d rootfs-complete/usr/include/scsi-GLIBC ];then
  #probably have kernel scsi headers in usr/include/scsi, fix...
  cp -a -f rootfs-complete/usr/include/scsi-GLIBC/* rootfs-complete/usr/include/scsi/
 fi
 
 #mageia1 python puts 30python.csh here...
 rm -f rootfs-complete/etc/profile.d/*.csh
 
 #140122 not sure about this...
 if [ "$(echo -n "$xARCHDIR" | cut -c 1)" == "/" ];then #150102
  #CPATH works any language, replaces C_INCLUDE_PATH and CPLUS_INCLUDE_PATH
  echo "export CPATH=/usr/include/${ARCHDIR}" > rootfs-complete/etc/profile.d/archinc
 fi
 
 #140123 'man-1.6f' binary pkg from T2 has bug, everything in /usr/usr...
 if [ -d rootfs-complete/usr/usr ];then
  cp -a -f --remove-destination rootfs-complete/usr/usr/bin/* rootfs-complete/usr/bin/ 2>/dev/null
  cp -a -f --remove-destination rootfs-complete/usr/usr/sbin/* rootfs-complete/usr/sbin/ 2>/dev/null
  cp -a -f --remove-destination rootfs-complete/usr/usr/share/* rootfs-complete/usr/share/ 2>/dev/null
  sync
  rm -rf rootfs-complete/usr/usr
 fi
 
 #140122 seamonkey compile, unable to find gdkconfig.h, glibconfig.h... (note, i actually put these in /usr/include, but this should work also...)
 if [ "$xARCHDIR" ];then #150102 fix
  for AINC in `find rootfs-complete/usr/lib${xARCHDIR} -type d -name 'include' | sed -e "s%rootfs-complete/usr/%%" | tr '\n' ' '` #ex: glib-2.0/include
  do
   mkdir -p rootfs-complete/usr/${AINC} #ex: rootfs-complete/usr/lib/glib-2.0/include
   xAINC="$(echo -n "$AINC" | sed -e 's%lib${xARCHDIR}/%%')"
   cp -a -f --remove-destination rootfs-complete/usr/${AINC}/*.h rootfs-complete/usr/lib/${xAINC}/ 2>/dev/null
  done
 fi
 
 #141017 quirky unicorn, compile seamonkey needs /usr/sbin/i686-linux-gnu-gcc, but only have ...-gcc-4.6 symlink.
 GCCLINK="$(find rootfs-complete/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-gcc-*' | head -n 1)"
 if [ "$GCCLINK" ];then
  xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
  #xxBASE="$(basename $GCCLINK)"
  #ln -s $xxBASE $xxLINK
  [ ! -e $xxLINK ] && cp -a $GCCLINK $xxLINK
 fi
 #these also...
 GCCLINK="$(find rootfs-complete/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-cpp-*' | head -n 1)"
 if [ "$GCCLINK" ];then
  xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
  [ ! -f $xxLINK ] && cp -a $GCCLINK $xxLINK
 fi
 GCCLINK="$(find rootfs-complete/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-g++-*' | head -n 1)"
 if [ "$GCCLINK" ];then
  xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
  [ ! -e $xxLINK ] && cp -a $GCCLINK $xxLINK
 fi
 
 #141019 quirky unicorn has lots of /usr/share/doc/*-dev folders...
 DOCDEVDIRS="$(find rootfs-complete/usr/share/doc -mindepth 1 -maxdepth 1 -type d -name '*-dev')"
 if [ "$DOCDEVDIRS" ];then
  echo
  echo 'Deleting rootfs-complete/usr/share/doc/*-dev folders...'
  for ADDD in $DOCDEVDIRS
  do
   [ -d $ADDD ] && rm -rf ./$ADDD
  done
 fi
 #also clean out more files...
 DOCDEVFILES="$(find rootfs-complete/usr/share/doc -type f -name '*.gz')"
 if [ "$DOCDEVFILES" ];then
  echo
  echo 'Deleting rootfs-complete/usr/share/doc/*/*.gz files...'
  for ADDF in $DOCDEVFILES
  do
   [ -f $ADDF ] && rm -f ./$ADDF
  done
 fi
 DOCDEVFILES="$(find rootfs-complete/usr/share/doc -type f -name 'copyright')"
 if [ "$DOCDEVFILES" ];then
  echo
  echo 'Deleting rootfs-complete/usr/share/doc/*/copyright files...'
  for ADDF in $DOCDEVFILES
  do
   [ -f $ADDF ] && rm -f ./$ADDF
  done
 fi

 #probably a good idea. quirky devx pet 6.1 is 236MB (sfs is 135MB --xz'ed), after removing .a's is 198MB...
 for ASO in `find rootfs-complete -name '*.so' | tr ' ' 'x' | tr '\n' ' '`
 do
  [ "`echo -n "$ASO" | grep -i 'qt'`" != "" ] && continue
  [ "`echo -n "$ASO" | grep -i 'mm'`" != "" ] && continue
  ADIR="`dirname $ASO`"
  ANAME="`basename $ASO .so`"
  
  #150925 want to leave these .a's alone (from glibc)...
  [ "$ANAME" == "libc" ] && continue
  [ "$ANAME" == "libanl" ] && continue
  [ "$ANAME" == "libbrokenLocale" ] && continue
  [ "$ANAME" == "libc_nonshared" ] && continue
  [ "$ANAME" == "libcrypt" ] && continue
  [ "$ANAME" == "libdl" ] && continue
  [ "$ANAME" == "libm" ] && continue
  [ "$ANAME" == "libnsl" ] && continue
  [ "$ANAME" == "libresolv" ] && continue
  [ "$ANAME" == "librt" ] && continue
  [ "$ANAME" == "libutil" ] && continue
  [ "$ANAME" == "libpthread" ] && continue
  
  [ -e ${ADIR}/${ANAME}.a ] && rm -f ${ADIR}/${ANAME}.a
 done
 sync

 #140201 deleting the .a, leaves some broken links behind. ex in quirky tahr /lib/i386-linux-gnu/libcurses.a -> libncurses.a
 for AA in `find rootfs-complete -type l -name '*.a' | tr ' ' 'x' | tr '\n' ' '`
 do
  ALINK="`readlink $AA`"
  [ ! "$ALINK" ] && continue
  AL1="${ALINK:0:1}"
  if [ "$AL1" = "/" ];then
   ALSPEC="rootfs-complete${ALINK}"
  else
   ALDIR="`dirname $AA`"
   ALSPEC="${ALDIR}/${ALINK}"
  fi
  [ ! -e ${ALSPEC} ] && rm -f $AA 2>/dev/null
 done
 
 #140201 this is a hack...
 #quirky tahr, devx has /usr/bin/man, but main f.s. has man as a symlink to script pman...
 if [ -e rootfs-complete/usr/bin/man ];then
  rm -f rootfs-complete/usr/bin/man
  ln -s pman rootfs-complete/usr/bin/man #so as to restore symlink.
 fi
fi

#150726 want a desktop readme icon...
if [ "$BUILD_CHOICE_README_DEV_DESK_ICON" == "yes" ];then
 #see 7build-live-cd in woofQ, 'save' icon does not conflict with this one.
 #see appinventor PET, 'ai2' icon does not conflict with this one. x=768 y=224
 #see android-studio PET, 'AStudio' icon does not conflict. x=832 y=224
 #qtcreator icon using x=768 y=320
 #desktop icons vertical spacing is 96, horiz spacing is 64.
 sed -i -e 's%^</pinboard>$%  <icon x="704" y="224" label="README">/usr/sbin/app-dev-setup-readme.sh</icon>\n</pinboard>%' rootfs-complete/root/Choices/ROX-Filer/PuppyPin
 #also, put icon...
 sed -i -e 's%^</special-files>$%  <rule match="/usr/sbin/app-dev-setup-readme.sh">\n    <icon>/usr/local/lib/X11/pixmaps/info48.xpm</icon>\n  </rule>\n</special-files>%' rootfs-complete/root/Choices/ROX-Filer/globicons
fi

#190911 "easy" label desktop icon renamed to "pyro" or "buster"...
sed -i -e "s%\"easy\"%\"${DISTRO_COMPAT_VERSION}\"%" rootfs-complete/root/Choices/ROX-Filer/PuppyPin
sed -i -e "s%ec\-chroot\-easy%ec-chroot-${DISTRO_COMPAT_VERSION}%" rootfs-complete/root/Choices/ROX-Filer/PuppyPin
sed -i -e "s%ec\-chroot\-easy%ec-chroot-${DISTRO_COMPAT_VERSION}%" rootfs-complete/root/Choices/ROX-Filer/globicons

#150727
#repacking .jar files with zero compression will allow them to be xz'ed smaller.
echo
echo "Do you want to repack .jar files with zero compression?"
echo -n "ENTER only for no: "
read repackjars
if [ "$repackjars" != "" ];then
 cp -a ../support/uncompress-jar-files ./
 ./uncompress-jar-files
fi

#170331 omni.ja is inside easy.sfs, avoid double compression...
#if [ "$DISTRO_NAME:0:5" == "Easy " ];then
[ -e rootfs-complete/usr/lib/seamonkey ] && MOZDIR='seamonkey' #170429
[ -e rootfs-complete/usr/lib/firefox ] && MOZDIR='firefox' #170429
 if [ -f rootfs-complete/usr/lib/${MOZDIR}/omni.ja ];then
  echo "Uncompressing rootfs-complete/usr/lib/${MOZDIR}/omni.ja..."
  mv -f rootfs-complete/usr/lib/${MOZDIR}/omni.ja ./omni.zip
  mkdir expand1
  unzip -X -K -o -b omni.zip -d expand1 > /dev/null
  cd expand1
  zip -0 -y -r ../omni.ja * > /dev/null
  cd ..
  mv -f omni.ja rootfs-complete/usr/lib/${MOZDIR}/
  sync
  rm -rf expand1
  echo " ...done"
 fi
#fi

#150928
if [ -d rootfs-complete/usr/share/X11/app-defaults ];then
 if [ ! -h rootfs-complete/usr/share/X11/app-defaults ];then
  mkdir -p rootfs-complete/etc/X11/app-defaults
  touch rootfs-complete/etc/X11/app-defaults/* 2>/dev/null
  cp -a -u rootfs-complete/usr/share/X11/app-defaults/* rootfs-complete/etc/X11/app-defaults/
  rm -rf rootfs-complete/usr/share/X11/app-defaults
  ln -s /etc/X11/app-defaults rootfs-complete/usr/share/X11/app-defaults
 fi
fi

if [ "$BUILD_CHOICE_MERGE_DEVX" != "yes" ];then #151113 werewolf, some stray files here
 if [ -d rootfs-complete/usr/include ];then
  mkdir -p devx/include
  cp -a -f --remove-destination rootfs-complete/usr/include/* devx/include/
  sync
  rm -rf rootfs-complete/usr/include
 fi
fi

#161012 raspberry pi hardware acceleration. note, /opt/vc may be in sd image file. 161020 moved down.
[ "$BUILD_CHOICE_BOARD" == "raspi" ] && echo 'export PATH=${PATH}:/opt/vc/bin' > rootfs-complete/etc/profile.d/vc

#161230 offer to dump llvm_DEV
if [ -d ../packages-${DISTRO_FILE_PREFIX}/llvm_DEV/usr ];then
 echo
 echo 'Do you want to delete llvm_DEV?'
 echo -n 'Enter only to keep it: '
 read keepit
 if [ "$keepit" == "" ];then
  echo '...keeping llvm_DEV'
 else
  rm -rf ../packages-${DISTRO_FILE_PREFIX}/llvm_DEV
  mkdir ../packages-${DISTRO_FILE_PREFIX}/llvm_DEV
  echo '...dumped llvm_DEV'
 fi
fi

#170107 offer to disable entries in rootfs-complete/root/Startup
echo
echo 'If you would like to disable any tray applets in rootfs-complete/root/Startup.
do so now. Maybe for testing, disable bluepup_tray for now.
If you would like to disable any daemons in /etc/init.d, do so now.'
echo -n 'Then press ENTER to continue: '
read keepgoing

#170224 for security reasons, do not turn on these daemons by default.
if [ "$BUILD_CHOICE_INITD_DAEMON_DEFAULT_OFF" ];then
 for aDAEMON in ${BUILD_CHOICE_INITD_DAEMON_DEFAULT_OFF}
 do
  [ -x rootfs-complete/etc/init.d/${aDAEMON} ] && chmod 644 rootfs-complete/etc/init.d/${aDAEMON}
 done
fi

#170511 'ca-certificates' package...
if [ -f rootfs-complete/usr/sbin/update-ca-certificates ];then
 #191007 pyro: p11-kit pet has this, remove...
 [ -e rootfs-complete/usr/bin/update-ca-certificates ] && rm -f rootfs-complete/usr/bin/update-ca-certificates
 if [ "$WOOF_HOSTARCH" == "$WOOF_TARGETARCH" ];then
  chroot rootfs-complete /usr/sbin/update-ca-certificates
 else
  echo "Note, need to run /usr/sbin/update-ca-certificates in rc.sysinit at first bootup."
 fi
fi

#170515 oe, usr/lib/gconv/gconv-modules.cache is missing...
if [ ! -f rootfs-complete/usr/lib${xARCHDIR}/gconv/gconv-modules.cache ];then
 if [ "$WOOF_HOSTARCH" == "$WOOF_TARGETARCH" ];then
  chroot rootfs-complete /usr/sbin/iconvconfig
 else
  echo "Note, rootfs-complete/usr/lib${xARCHDIR}/gconv/gconv-modules.cache missing
need to create it rc.sysinit at first bootup."
 fi
fi

#171109 ref: http://murga-linux.com/puppy/viewtopic.php?p=972909#972909
if [ "$WOOF_HOSTARCH" == "$WOOF_TARGETARCH" ];then
 chroot rootfs-complete /usr/bin/update-desktop-database
else
 echo "Note, need to run update-desktop-database in rc.sysinit at first bootup."
fi

#170305 seamonkey container is pre-created, but remove if have not built with sm...
#170521 if symlink is broken, the "-e" test fails, so add "-h"...
SMflg='no'
[ -e rootfs-complete/usr/bin/seamonkey ] && SMflg='yes'
[ -h rootfs-complete/usr/bin/seamonkey ] && SMflg='yes'
[ "$SMflg" == "no" ] && rm -f rootfs-complete/usr/share/applications/ec-seamonkey.desktop

#180407 create some containerized desktop icons...
#intention, containerized window-manager menu entries will also be icons on desktop.
#doing the pre-created ones here (refer initrd-tree). runtime-created, refer /usr/local/easy_containers/easy-containers
#get pngoverlay from host, in case of cross-build...
cp -f /usr/sbin/pngoverlay rootfs-complete/usr/local/lib/X11/pixmaps/ #dumb, but needs to be in same folder.
cp -f rootfs-complete/usr/share/doc/logo48.png rootfs-complete/usr/local/lib/X11/pixmaps/easy48.png #180720 181122
cd rootfs-complete/usr/local/lib/X11/pixmaps
for ONEICON in www console pet easy #desk #180630 180720 181122
do
 ./pngoverlay ${ONEICON}48.png ec-overlay48.png ec-${ONEICON}48.png #background foreground output.
# #181012 backup the icon in the container folder, in case .session gets erased (ref: ec-fix-desktop)...
# if [ -d ../../../../../../../boot/initrd-tree/skeleton/containers/${ONEICON} ];then
#  cp -f ec-${ONEICON}48.png ../../../../../../../boot/initrd-tree/skeleton/containers/${ONEICON}/
# fi
done
cd ../../../../../../
rm -f rootfs-complete/usr/local/lib/X11/pixmaps/pngoverlay
rm -f rootfs-complete/usr/local/lib/X11/pixmaps/easy48.png #180720 181122


#170826 do this for rootfs-complete also...
#see:170813 there is a lot of stuff in devx/usr/share/doc...
#delete empty folders...
find rootfs-complete/usr/share/doc -mindepth 1 -type d -empty -delete
#...this will cause some broken symlinks, delete symlinks...
for ALINK in `find rootfs-complete/usr/share/doc -mindepth 1 -type l | tr '\n' ' '`
do
 [ ! -e ./$ALINK ] && continue
 if ! readlink -e "$ALINK" >/dev/null ;then rm -f ./"$ALINK" ; fi
done

#171022
if [ "$DISTRO_BINARY_COMPAT" == "oe" ];then
 if [[ $DISTRO_TARGETARCH == *64 ]] ;then
  if [ -d rootfs-complete/lib64 ];then
   if [ ! -h rootfs-complete/lib64 ];then
    cp -a -f --remove-destination rootfs-complete/lib64/* rootfs-complete/lib/
    rm -rf rootfs-complete/lib64
   fi
  fi
  if [ -d rootfs-complete/usr/lib64 ];then
   if [ ! -h rootfs-complete/usr/lib64 ];then
    cp -a -f --remove-destination rootfs-complete/usr/lib64/* rootfs-complete/usr/lib/
    rm -rf rootfs-complete/usr/lib64
   fi
  fi
  ln -s lib rootfs-complete/lib64
  ln -s lib rootfs-complete/usr/lib64
 fi
fi

#171105 32-bit i686, intel needs uxa
if [ "$WOOF_TARGETARCH" == "x86" ];then
 mv -f rootfs-complete/etc/X11/xorg.conf.d/20-intel-uxa.confDISABLED rootfs-complete/etc/X11/xorg.conf.d/20-intel-uxa.conf
fi

#180518 new script 'build-rox-sendto'
[ ! -f /usr/sbin/build-rox-sendto ] && cp -a rootfs-complete/usr/sbin/build-rox-sendto /usr/sbin/
cd rootfs-complete
echo "Building rox right-click menu in rootfs-complete/etc/xdg/rox.sourceforge.net"
build-rox-sendto
echo " ...done"
cd ..

#190919 previously had manually-created files in /root/Choices/MIME-types
#a rox-filer pet may have brought stuff with it...
mkdir -p rootfs-complete/etc/xdg/rox.sourceforge.net/MIME-types
rm -f rootfs-complete/etc/xdg/rox.sourceforge.net/MIME-types/* 2>/dev/null
[ -d rootfs-complete/root/Choices/MIME-types ] && rm -f rootfs-complete/root/Choices/MIME-types/* 2>/dev/null
#repopulate...
cp -a ../rootfs-skeleton/etc/xdg/rox.sourceforge.net/MIME-types/* rootfs-complete/etc/xdg/rox.sourceforge.net/MIME-types/

#190923 gnome-keyring is used by networkmanager and nm-applet to encrypt passwords.
# gnome-keyring-daemon with "--login" option, may read this, we don't want it...
[ -f rootfs-complete/etc/pam.d/login ] && rm -f rootfs-complete/etc/pam.d/login

#180523 trying to reduce size by moving gobject-introspection to devx (see pkg-list)
if [ ! -f rootfs-complete/usr/bin/g-ir-inspect  ];then #test if pkg moved.
 if [ -d rootfs-complete/usr/share/gir-1.0 ];then
  mkdir -p devx/usr/share/gir-1.0
  cp -a -f rootfs-complete/usr/share/gir-1.0/* devx/usr/share/gir-1.0/
  sync
  rm -f rootfs-complete/usr/share/gir-1.0/*
 fi
fi

#180523 offer to rebuild all png files without compression... 
if [ "$BUILD_CHOICE_PNG_NOCOMPRESSION" ];then #200108
 case "$BUILD_CHOICE_PNG_NOCOMPRESSION" in
  yes) rebuildpngflg='yes' ;;
  *) rebuildpngflg='' ;;
 esac
else
 echo
 echo 'Would you like to rebuild all png files without compression?'
 echo -n 'ENTER only not to: '
 read rebuildpngflg
fi
if [ "$rebuildpngflg" ];then
 echo '  finding png files...'
 for aPNG in `find rootfs-complete/usr -type f -name '*.png' | grep -v ' '`
 do
  #echo -n "."
  echo "  ${aPNG}"
  pngtopnm $aPNG > /tmp/tmp-image.pnm
  pngtopnm -alpha ${aPNG} > /tmp/tmp-alpha.pnm
  pnmtopng -alpha=/tmp/tmp-alpha.pnm -compression=0 /tmp/tmp-image.pnm > $aPNG
 done
fi
echo

#180628 busybox or coreutils may have installed 'df' applet as a symlink (symlink
# or shebang in case of coreutils, depending on precompile configure). keep our script...
if [ -f ../roofs-skeleton/bin/df ];then
 cp -a -f --remove-destination ../roofs-skeleton/bin/df rootfs-complete/bin/
fi
#note, /bin/mount and ps are same situation, but these are preserved ok.

#190926 jwm does not use these (easy uses /root/Startup), avoid the confusion...
rm -f rootfs-complete/etc/xdg/autostart/*.desktop 2>/dev/null

#200930 oe dunfell some pkgs have 'ptest' folder, delete...
find rootfs-complete -type d -name ptest -execdir rm -rf ptest \; > /dev/null 2>&1

#201012 need these symlinks for multiarch foreign pkgs to work in oe build...
if [ ! -e rootfs-complete/lib64 ];then
 ln -s lib rootfs-complete/lib64
fi
if [ ! -e rootfs-complete/usr/lib64 ];then
 ln -s lib rootfs-complete/usr/lib64
fi
case "$WOOF_TARGETARCH" in
 amd64) #this is for debian/ubuntu pkgs...
  if [ ! -e rootfs-complete/lib/x86_64-linux-gnu ];then
   ln -s . rootfs-complete/lib/x86_64-linux-gnu
  fi
  if [ ! -e rootfs-complete/usr/lib/x86_64-linux-gnu ];then
   ln -s . rootfs-complete/usr/lib/x86_64-linux-gnu
  fi
 ;;
esac


#200209 remove...
rm -rf rootfs-complete/etc/rc[0-6].d 2>/dev/null
rm -rf rootfs-complete/etc/rcS.d 2>/dev/null

#161210 now have boot/easyinit 170128 'easyinit' now 'initrd-tree'
cd ../boot

[ -d initrd-tree-populated ] && rm -rf initrd-tree-populated
cp -a initrd-tree initrd-tree-populated
#currently don't need some of the binaries (that i compiled in buildroot)...
[ -f initrd-tree-populated/bin/coreutils ] && rm -f initrd-tree-populated/bin/coreutils
#[ -f initrd-tree-populated/bin/mksquashfs ] && rm -f initrd-tree-populated/bin/mksquashfs
[ -f initrd-tree-populated/bin/unsquashfs ] && rm -f initrd-tree-populated/bin/unsquashfs
[ -f initrd-tree-populated/bin/ntfs-3g ] && rm -f initrd-tree-populated/bin/ntfs-3g
[ -f initrd-tree-populated/bin/resize2fs ] && rm -f initrd-tree-populated/bin/resize2fs
[ -f initrd-tree-populated/bin/gdisk ] && rm -f initrd-tree-populated/bin/gdisk #170730 now have mbr, only need fdisk.
[ "$BOOT_BOARD" != "pc" ] && [ -f initrd-tree-populated/bin/ntfs-3g ] && rm -f initrd-tree-populated/bin/ntfs-3g
./populate-initrd-tree
cd initrd-tree-populated
[ -f ../initrd.q ] && rm -f ../initrd.q
[ -f ../initrd ] && rm -f ../initrd #181130

#190311
if [ "${DEFAULTLANG1}" == "en" ];then
 echo -n 'no' > skeleton/sfs/settings/initrd/INITRD_X_GUI
fi

[ "$SMflg" == "no" ] && rm -rf skeleton/containers/seamonkey #170305

#190123 need easy.png here, as initrd will copy easy.sfs here at 1st bootup...
mkdir -p skeleton/sfs/easyos/${DISTRO_BINARY_COMPAT}/${DISTRO_COMPAT_VERSION}
cp -f ../../rootfs-skeleton/usr/share/doc/logo48.png skeleton/sfs/easyos/${DISTRO_BINARY_COMPAT}/${DISTRO_COMPAT_VERSION}/easy.png
#also need easy_${DISTRO_VERSION}_${DISTRO_TARGETARCH}.specs, but as that will need
#to be generated at every upgrade (update initrd etc files in boot-partition),
#it is being generated in init script, initrd (see same date 190123).

#170128 need file BOOT_SPECS... 170217 add INIT_DISTRO_VERSION 170325... 181029 add INIT_DISTRO_BINARY_COMPAT, INIT_DISTRO_COMPAT_VERSION, INIT_DISTRO_TARGETARCH
#181205 now using random disk-id...  190104 add INIT_LANG ...
#190307 new INITRD_X_GUI... 190310 no
#DISKID="$(cat ../../sd-skeleton-images/${SKELETON_NAME}-DISKID)"
#200123 change WKG_DIR from empty to "easyos/"...
if [ "$ROCK64flg" ];then #190131 190226
 echo 'Creating BOOT_SPECS in file...'
 echo "BOOT_UUID='${UUID1}'
BOOT_DIR='boot'
WKG_UUID='${UUID2}'
WKG_DIR='easyos/'" > BOOT_SPECS
else
 echo 'Creating BOOT_SPECS in file...'
 echo "BOOT_UUID='${UUID1}'
BOOT_DIR=''
WKG_UUID='${UUID2}'
WKG_DIR='easyos/'" > BOOT_SPECS
fi

#190911 change name of pre-created "easy" container, to "pyro" or "buster"...
mv -f skeleton/containers/easy skeleton/containers/${DISTRO_COMPAT_VERSION}
echo "#these variables read by ec-fix-desktop via /root/.xinitc when X starts.
#the icon is created in woofq, 3buildeasydistro.
#as this is a pre-created container, ec-chroot-${DISTRO_COMPAT_VERSION} is created in woofq by 3buildeasydistro.
EC_LABEL=${DISTRO_COMPAT_VERSION}
EC_PATH=/usr/sbin/ec-chroot-${DISTRO_COMPAT_VERSION}
EC_ICON=/usr/local/lib/X11/pixmaps/ec-easy48.png" > skeleton/containers/${DISTRO_COMPAT_VERSION}/desktop
#further down, fix ec-chroot-easy...

find . | cpio -o -H newc > ../initrd #181130
sync
mkdir -p ../../sandbox3
cp -a -f ../initrd ../../sandbox3/ #181130

#190128 create alternate initrd without BOOT_SPECS...
#EID="$(date +%Y%m%d%H%M)" #yyyymmddhhmm ex: 201901300713
#EID="${DISTRO_VERSION}" #use this rather than date.
#EID="${KERNELVER}" #190130 no, use this.
EID='gen1' #190131 no, use this!
echo
echo "sandbox3/initrd-no-boot-specs will be created, without internal BOOT_SPECS."
echo "Instead, will have internal EASY_ID file, containing ${EID}, and at"
echo "bootup init will search for external BOOT_SPECS-${EID} file."
echo "You may want to change this to match some other kernel version, or another ID."
echo -n "ENTER to accept, or type some other ID: "
read wantid
[ "$wantid" ] && EID="${wantid}"
echo "Writing ${EID} to file EASY_ID in initrd-no-boot-specs ..."
echo -n "${EID}" > EASY_ID #read at bootup, init will call /sbin/find-boot-specs
rm -f ../../sandbox3/BOOT_SPECS-*
mv -f BOOT_SPECS ../../sandbox3/BOOT_SPECS-${EID}
find . | cpio -o -H newc > ../../sandbox3/initrd-no-boot-specs
sync
cp -f ../../sandbox3/BOOT_SPECS-${EID} ./BOOT_SPECS #restore

cd ../../sandbox3

if [ "$ROCK64flg" ];then #190131
 cp -f BOOT_SPECS-${EID} img_mntpt/boot/
fi

#190128 recompile kernel with inbuilt initrd...
echo
echo "You may choose to recompile the kernel with inbuilt initrd."
echo "/usr/src must contain the kernel source, and a file /usr/src/DOTconfig"
echo "/usr/src may be a symlink to the kernel source."
echo "Must have /usr/src/linux relative symlink to actual source, ex linux-4.14.95"
echo -n "Press ENTER only not to do this, any char to do it: "
read wantcompile
if [ "$wantcompile" == "" ];then
 echo "...chose not to recompile kernel"
else
 echo "...chose to recompile kernel"
 if [ ! -f /usr/src/DOTconfig ];then
  echo "/usr/src/DOTconfig does not exist, cannot recompile"
 else
  if [ ! -d /usr/src/linux ];then
   echo "Symlink /usr/src/linux does not exist, cannot recompile"
  else
   NOWWD="$(pwd)"
   LINUXDIR="$(readlink /usr/src/linux)"
   if [ ! -d /usr/src/${LINUXDIR} ];then
    echo "No directory /usr/src/${LINUXDIR}, cannot recompile"
   else
    echo "Recompiling linux kernel with inbuilt initrd..."
    cd /usr/src/${LINUXDIR}
    make clean
    make mrproper
    cp -f ../DOTconfig .config
    sed -i -e 's%^CONFIG_INITRAMFS_SOURCE=.*%CONFIG_INITRAMFS_SOURCE="initrd.gz"%' .config
    cp -f ${NOWWD}/initrd-no-boot-specs ./initrd.cpio #190130
    gzip initrd.cpio #190130 must have extensions .cpio.gz
    case "$WOOF_TARGETARCH" in
     amd64|x86)
      make bzImage
      cp -f arch/x86/boot/bzImage ${NOWWD}/${KERNELNAME} #to sandbox3/vmlinuz
     ;;
     aarch64)
      make Image #creates an uncompressed kernel.
      cp -f arch/arm64/boot/Image ${NOWWD}/${KERNELNAME} #to sandbox3/kernel8.img
     ;;
    esac
    cd $NOWWD
   fi
  fi
 fi
fi

rm -rf rootfs-complete/tmp/* #121123 some above chroot operations may have left something behind in here.

#190817 somehow this got left behind...
rm -rf rootfs-complete/DEBIAN 2>/dev/null

###########################################################################
#140119 no longer building $PUPPYSFS from rootfs-complete.
sync
###########
#now build main f.s....

#170129 note, had non-english translation code for the early boot messages, ex help.msg. removed.
#190107 new translation code, above, and below.

########
#140119 no longer creating live-cd .iso file.
#instead, get code from script /mnt/sda10/quirky6/create-deployable-quirky...
 
#170128 creating 'q.sfs' again...
echo
echo 'Now creating easy.sfs...'

echo #190131...
#echo "Are you building with a kernel with inbuilt initrd?"
#echo "If so, press any char to decline copying initrd into img file."
#echo -n "ENTER only to copy initrd to img file: "
#read copyinitrd
#if [ "$copyinitrd" == "" ];then
if [ "$ROCK64flg" == "" ];then
 echo "copying initrd into img file..."
 cp -f ./initrd img_mntpt/${BOOTDIR} #181130
else
 echo "...declined to copy initrd"
fi

echo "copying ${KERNELNAME} into img file..."
[ -f ./${KERNELNAME} ] && cp -f ./${KERNELNAME} img_mntpt/${BOOTDIR} #190131
sync

#190107 also have to translate boot-partition, mounted at img_mntpt...
if [ "$DEFAULTLANG1" != "en" ];then
 #190712 make sure have latest script in host (fixinitrd and fixboot are symlinks to fixdesk)...
 [ -f rootfs-complete/usr/sbin/fixdesk ] && cp -a -f rootfs-complete/usr/sbin/fixdesk /usr/sbin/
 #190712 make sure have latest sss translations in host...
 cp -a -f --remove-destination rootfs-complete/usr/share/sss/* /usr/share/sss/
 echo "Translating 'initrd' in boot-partition..."
 MNTD_BP="$(realpath ./img_mntpt)"
 fixinitrd ${DEFAULTLANG1} ${DEFAULTLANG} ${MNTD_BP}
 echo "Translating boot-manager menus in boot-partition..."
 fixboot ${DEFAULTLANG1} ${DEFAULTLANG} ${MNTD_BP}
fi

#190712 for create-live-cd script... (note, $MNT_BP is realpath of img_mntpt)
cp -a -f img_mntpt/${BOOTDIR}initrd initrd-${DEFAULTLANG1}

echo 'creating easy.sfs...'
rm -rf rootfs-complete/boot/* 2>/dev/null
mkdir -p rootfs-complete/sys
 
echo "depmod..."
KERNELVER="$(find rootfs-complete/lib/modules -mindepth 1 -maxdepth 1 -type d -name '[2345].*' | head -n 1 | rev | cut -f 1 -d '/' | rev)" #190730 fix
rm -f rootfs-complete/lib/modules/$KERNELVER/modules.*
cp -a -f rootfs-complete/etc/modules/modules.builtin rootfs-complete/lib/modules/$KERNELVER/
cp -a -f rootfs-complete/etc/modules/modules.order rootfs-complete/lib/modules/$KERNELVER/
depmod -b rootfs-complete -F System.map $KERNELVER
sync

#181102 create meta-data for sfs (ref: /usr/local/sfsget/dir2sfs). 181105 fix 181122 fix.
VER="$DISTRO_VERSION"
[ -d export-sfs-${DEFAULTLANG1} ] && rm -rf export-sfs-${DEFAULTLANG1}
mkdir export-sfs-${DEFAULTLANG1}
SIZEK="$(du -s -k rootfs-complete | cut -f 1)"
echo "Creating meta-data for easy..."
#190911 change DB_install from 'terminal' to 'desk'...
echo "#generated by 3buildeasydistro:
DB_pkgname='easy_${VER}'
DB_nameonly='easy'
DB_version='${VER}'
DB_revision=''
DB_arch='${DISTRO_TARGETARCH}'
DB_categories='Utility'
DB_size='${SIZEK}'
DB_fullfilename='easy_${VER}_${DISTRO_TARGETARCH}.sfs'
DB_dependencies=''
DB_description='EasyOS base SFS'
DB_description_long='This is the complete EasyOS filesystem, the ${DISTRO_COMPAT_VERSION} series.'
DB_compileddistro='${DISTRO_BINARY_COMPAT}'
DB_compiledrelease='${DISTRO_COMPAT_VERSION}'
DB_path='easyos/${DISTRO_BINARY_COMPAT}/${DISTRO_COMPAT_VERSION}'
DB_apps='easy'
DB_icons='easy'
DB_install='desk'
DB_hash=''" > export-sfs-${DEFAULTLANG1}/easy_${VER}_${DISTRO_TARGETARCH}.specs
#icons...
mkdir -p rootfs-complete/.control
cp -a -f export-sfs-${DEFAULTLANG1}/easy_${VER}_${DISTRO_TARGETARCH}.specs rootfs-complete/.control/easy.specs
cp -a -f /usr/share/doc/easy48.png ./easy48.png
cp -a -f /usr/local/lib/X11/pixmaps/ec-overlay48.png ./
cp -f /usr/sbin/pngoverlay ./
#picscale -i easy48.png -o easy48.png 48 48 9
./pngoverlay easy48.png ec-overlay48.png ec-easy48.png
mkdir -p rootfs-complete/usr/share/pixmaps
cp -f easy48.png rootfs-complete/usr/share/pixmaps/
cp -f ec-easy48.png rootfs-complete/usr/share/pixmaps/
cp -f easy48.png export-sfs-${DEFAULTLANG1}/easy.png
#dummy .desktop...
mkdir -p rootfs-complete/usr/share/applications
#190911 change name "easy" to "pyro" or "buster"...
echo "[Desktop Entry]
NoDisplay=true
Name=${DISTRO_COMPAT_VERSION}
Exec=ec-chroot-${DISTRO_COMPAT_VERSION}
Icon=ec-easy48.png
Categories=X-Utility" > rootfs-complete/usr/share/applications/${DISTRO_COMPAT_VERSION}.desktop
#run script...  181122
#190911 note, have "easy" as a second param here, as that is script inside .control...
# (start-container creates 'ec-run' which will fallback to run .control/easy if $DISTRO_COMPAT_VERSION not in $PATH)
mkdir -p rootfs-complete/usr/sbin
echo "#!/bin/sh
empty -f ec-chroot ${DISTRO_COMPAT_VERSION} easy" > rootfs-complete/usr/sbin/ec-chroot-${DISTRO_COMPAT_VERSION}
chmod 755 rootfs-complete/usr/sbin/ec-chroot-${DISTRO_COMPAT_VERSION}
#***NOTICE*** haven't created .control/easy.configuration (190830: have /usr/local/easy_containers/templates/easy/configuration)

#200605 fix the menu entry for launching EasyOS in container...
#hmmm, forget why have created dummy buster.desktop, and below devx.desktop
mv -f rootfs-complete/usr/share/applications/ec-easy.desktop rootfs-complete/usr/share/applications/ec-${DISTRO_COMPAT_VERSION}.desktop
sed -i -e "s%\-easy%-${DISTRO_COMPAT_VERSION}%" rootfs-complete/usr/share/applications/ec-${DISTRO_COMPAT_VERSION}.desktop

#181117 scripts in /.control
[ -f rootfs-complete/.control/easy ] && rm -f rootfs-complete/.control/easy
cat << 'EOF1' >> rootfs-complete/.control/easy
#!/bin/sh
#this script generated by /usr/local/sfsget/dir2sfs
#PuppyPin backup...
if [ -f /root/Choices/ROX-Filer/PuppyPinBACKUP ];then
 touch /root/Choices/ROX-Filer/PuppyPin
 if [ "$(grep 'defaultbrowser' /root/Choices/ROX-Filer/PuppyPin)" == "" ];then
  cp -a -f /root/Choices/ROX-Filer/PuppyPinBACKUP /root/Choices/ROX-Filer/PuppyPin
 fi
fi
cp -a -f /root/Choices/ROX-Filer/PuppyPin /root/Choices/ROX-Filer/PuppyPinBACKUP
#181115 xenialpup puppy package manager needs this...
FREEM="$(df -m / | tail -n 1 | tr -s ' ' | cut -f 4 -d ' ')"
echo -n "${FREEM}" > /tmp/pup_event_sizefreem
#unexpected change of screen dimensions may cause desktop drive icons to be displaced...
SCRNXY="`xwininfo -root | grep -o '\-geometry .*' | tr -s ' ' | cut -f 2 -d ' ' | cut -f 1 -d '+'`"
SCRN_X="`echo -n "$SCRNXY" | cut -f 1 -d 'x'`"
SCRN_Y="`echo -n "$SCRNXY" | cut -f 2 -d 'x'`"
echo -n "$SCRN_X" > /tmp/pup_event_frontend_scrn_x #read by frontend_change.
echo -n "$SCRN_Y" > /tmp/pup_event_frontend_scrn_y #read by frontend_change.
if [ -f /var/local/pup_event_frontend_scrn_x ];then
 oldSCRNX="$(cat /var/local/pup_event_frontend_scrn_x)"
 oldSCRNY="$(cat /var/local/pup_event_frontend_scrn_y)"
 [ "$SCRN_X" != "$oldSCRNX" ] && echo "ICONWIPE" > /var/local/pup_event_icon_change_flag
 [ "$SCRN_Y" != "$oldSCRNY" ] && echo "ICONWIPE" > /var/local/pup_event_icon_change_flag
 #.../var/local/pup_event_icon_change_flag is read by /sbin/clean_desk_icons (see below).
fi
echo -n "$SCRN_X" > /var/local/pup_event_frontend_scrn_x
echo -n "$SCRN_Y" > /var/local/pup_event_frontend_scrn_y
#make sure /usr/local/bin in path:
[ "$(echo -n "$PATH" | grep '/usr/local/bin')" == "" ] && export PATH="/usr/local/bin:${PATH}"
/usr/bin/desk-delayedrun & #this will launch tray applets.
#relocates right-side icons to actual right-side of screen...
/usr/sbin/fixPuppyPin /root/Choices/ROX-Filer/PuppyPin
CR='
'
#start rox...
#181013 don't know how, rox picks up wallpaper etc from host rox (but corrupted)...
#181105 weird, but have to start rox, start jwm, kill then restart rox...
cp -f /root/Choices/ROX-Filer/globicons /root/.config/rox.sourceforge.net/ROX-Filer/
cp -f /root/Choices/ROX-Filer/PuppyPin /root/.config/rox.sourceforge.net/ROX-Filer/
echo '<?xml version="1.0"?>
<pinboard>
</pinboard>' > /root/Choices/ROX-Filer/PuppyPin0
rox -p /root/Choices/ROX-Filer/PuppyPin0
#start jwm...
jwm &
sleep 4 #0.5 sometimes not enough. 181217 increase from 2. 190202 increase from 2.5. 190806 now 4 (see also dir2sfs).
killall ROX-Filer
#put text on background...
if [ -x /usr/sbin/popup ];then
 popup "level=bottom placement=center background=#06ee9b|<b><big><big>Containerized desk ${CR}Press Alt-F6 to flip</big></big></b>"
elif [ -x /usr/bin/gtkdialog-splash ];then
 gtkdialog-splash -close never -fontsize large -text "Containerized desk${CR}Press Alt-F6 to flip" &
fi
rox -n -p /root/Choices/ROX-Filer/PuppyPin
###end###
EOF1
chmod 755 rootfs-complete/.control/easy
chown spot:spot rootfs-complete/.control/easy
#181117 and the once-only scripts...
#(.run-once-base scripts are run in ec-chroot, before launching the container)
[ -f rootfs-complete/.control/easy.run-once-base ] && rm -f rootfs-complete/.control/easy.run-once-base
cat << 'EOF2' >> rootfs-complete/.control/easy.run-once-base
#!/bin/sh
 #this script generated by /usr/local/sfsget/dir2sfs
 #181115 xenialpup has not precreated the pixbuf cache...
 GDKPIXBUFDIR="$(find /usr/lib* -type d -name 'gdk-pixbuf-2.0' | head -n 1)"
 if [ "${GDKPIXBUFDIR}" ];then
  if [ ! -e ${GDKPIXBUFDIR}/2.10.0/loaders.cache ];then
   gdk-pixbuf-query-loaders --update-cache
  fi
 fi
 #181115 xenialpup already has the icon-theme.cache files, but just in case...
 find /usr/share/icons -mindepth 1 -maxdepth 1 -type d |
 while read ALINE
 do
  [ "${ALINE}" == "" ] && continue
  [ ! -d "${ALINE}"/16x16 ] && continue
  gtk-update-icon-cache -f "${ALINE}"
 done
 #181105 check these...
 #fc-cache -s #regenerate fontconfig caches (in /var/cache/fontconfig).
 if [ -d /usr/share/glib-2.0/schemas ];then
  if [ ! -f /usr/share/glib-2.0/schemas/gschemas.compiled ];then
   if [ -e /usr/bin/glib-compile-schemas ];then
    /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
   fi
  fi
 fi
EOF2
chmod 755 rootfs-complete/.control/easy.run-once-base
chown spot:spot rootfs-complete/.control/easy.run-once-base
[ -f rootfs-complete/.control/easy.run-once-top ] && rm -f rootfs-complete/.control/easy.run-once-top
cat << 'EOF3' >> rootfs-complete/.control/easy.run-once-top
#!/bin/sh
 #this script generated by /usr/local/sfsget/dir2sfs
 #take out the pre-created "www", "console", "easy" container desktop icons...
 sed -i '/ec\-chroot\-/d' /root/Choices/ROX-Filer/PuppyPin
 #take out these desktop icons also...
 sed -i '/Connect/d' /root/Choices/ROX-Filer/PuppyPin
 sed -i '/EasyShare/d' /root/Choices/ROX-Filer/PuppyPin
 #190123 must not run sfsget inside a container...
 sed -i '/sfsget/d' /root/Choices/ROX-Filer/PuppyPin
 #...that creates a gap, should close it up...
 sed -i -e 's%x="352"%x="288"%' /root/Choices/ROX-Filer/PuppyPin #setup
 sed -i -e 's%x="416"%x="352"%' /root/Choices/ROX-Filer/PuppyPin #edit
 sed -i -e 's%x="480"%x="416"%' /root/Choices/ROX-Filer/PuppyPin #console
 #missing, probably good to create it...
 touch /root/.packages/user-installed-packages
 #we need equivalent to /usr/sbin/delayedrun (which starts from /root/.xinitrc), which starts the tray applets.
 #see 'desk-delayedrun' below.
 #181115 xenialpup is launching the tray applets...
 # seems a bit weird, need to delete this...
 [ -d /root/.config/autostart ] && rm -rf /root/.config/autostart/*
 #181105 need to cutout some entries from /etc/xdg/templates/_root_.jwmrc ...
 sed -i '/puppy\-setup\.menu/d' /etc/xdg/templates/_root_.jwmrc
 sed -i '/"Shutdown"/,/^\s*$/{d}' /etc/xdg/templates/_root_.jwmrc #removed entire paragraph.
 sed -i '/label="Exit"/d' /etc/xdg/templates/_root_.jwmrc #181116 xenialpup.
 [ -f /root/.jwm/jwmrc-personal ] && sed -i '/defaultscreenshot/d' /root/.jwm/jwmrc-personal #181116 up-arrow launches screeny.
 [ -f /root/.jwm/jwmrc-personal2 ] && sed -i '/defaultscreenshot/d' /root/.jwm/jwmrc-personal2 #181116 up-arrow launches screeny.
 #have to run fixmenus, but firstly, delete some .desktop files...
 for aDT in BootManagerSTAR easy-STAR ec-STAR childproof cups Desktop-STAR easydd firewall-STAR floppy-STAR Internet-STAR loginmanager MoManagerSTAR MouseSTAR Multiple-Sound-Card-Wizard Partview Pdisk-STAR Pmount-STAR printer-STAR PuddSTAR qsync QuickSetup remove-builtin Set-STAR TopSTAR video-STAR
 do
  rm -f /usr/share/applications/${aDT/STAR/*}.desktop 2>/dev/null
 done
 #and some apps...
 for aDT in bluepup GPartedSTAR gpptp hardinfo pschedule Puppy-Event-Manager PupScanSTAR Pup-SysInfo pupXSTAR xinput_calibrator wcpufreq
 do
  rm -f /usr/share/applications/${aDT/STAR/*}.desktop 2>/dev/null
 done
 #181105 and for some old pups...
 for aDT in Floppy_Formatter Format-floppy-disk Gpptp GrubSTAR legacy_grub_2013 mtp_detect pbackup pgprs-connect PupsaveSTAR Remaster-STAR Resize-personal-storage-file
 do
  rm -f /usr/share/applications/${aDT/STAR/*}.desktop 2>/dev/null
 done
 fixmenus
 #181105 reshape the backround image...
 /usr/sbin/background_reshape
 #...ok for old pups, easyos and quirky need extra code...
 RET1=$?
 if [ $RET1 -eq 11 ];then
  if [ -s /tmp/qwallpaper_reshaped ];then
   NEWIMAGE="`cat /tmp/qwallpaper_reshaped`"
   if [ -f $NEWIMAGE ];then #sanity check.
    #truncated image created, update rox...
    iPTN="s%>.*</backdrop>%>${NEWIMAGE}</backdrop>%"
    sed -i -e "$iPTN" /root/Choices/ROX-Filer/PuppyPin
   fi
  fi
 fi
 #181115 xenialpup needs fix for desktop install icon...
 if [ -f /usr/sbin/dotpup ];then
  echo '#!/bin/sh
exec /usr/local/petget/pkg_chooser.sh' > /usr/sbin/dotpup
  chmod 755 /usr/sbin/dotpup
 fi
EOF3
chmod 755 rootfs-complete/.control/easy.run-once-top
chown spot:spot rootfs-complete/.control/easy.run-once-top
#181117 this also...
[ -f rootfs-complete/usr/bin/desk-delayedrun ] && rm -f rootfs-complete/usr/bin/desk-delayedrun
cat << 'EOF2' >> rootfs-complete/usr/bin/desk-delayedrun
#!/bin/sh
#this script generated by /usr/local/sfsget/dir2sfs
#give enough time for jwm to start...
sleep 4.5 #must be >2  181217 increase from 3. 190202 increase from 3.5. 190806 from 4.
if ! pidof jwm >/dev/null ;then sleep 2; fi
if ! pidof jwm >/dev/null ;then sleep 4; fi

if [ -x /root/Startup/pnmixer_tray ];then
 if ! pidof pnmixer >/dev/null; then
  /root/Startup/pnmixer_tray &
 fi
elif [ -x /root/Startup/retrovol_tray ];then
 if ! pidof retrovol >/dev/null; then
  /root/Startup/retrovol_tray &
 fi
elif [ -x /usr/bin/retrovol ];then #181115
 retrovol -hide &
fi
EOF2
chmod 755 rootfs-complete/usr/bin/desk-delayedrun
chown spot:spot rootfs-complete/usr/bin/desk-delayedrun

sync

[ -f easy.sfs ] && rm -f easy.sfs
../support/mksquashfs4.3 rootfs-complete ./easy.sfs -comp xz -processors 1
sync
#181102
#if [ "$DEFAULTLANG1" == "en" ];then #190107 190712 remove if
 cp -a -f easy.sfs export-sfs-${DEFAULTLANG1}/easy_${VER}_${DISTRO_TARGETARCH}.sfs
 sync
 HASH="$(sha256sum export-sfs-${DEFAULTLANG1}/easy_${VER}_${DISTRO_TARGETARCH}.sfs | cut -f 1 -d ' ')"
 sed -i -e "s%^DB_hash=.*%DB_hash='${HASH}'%" export-sfs-${DEFAULTLANG1}/easy_${VER}_${DISTRO_TARGETARCH}.specs
#fi

echo 'Copying easy.sfs into img file...'
cp -a easy.sfs img_mntpt/${BOOTDIR} #190131
sync
 
umount img_mntpt

#181205
#change the disk identifier...
echo
echo "Changing the disk identifier in ${SKELETON_NAME}.img ..."
echo -e "x\ni\n0x${RANDHEX8}\nr\nw" | fdisk ${SKELETON_NAME}.img
sync

#200929 more meaningful to change easy- to easy-${DISTRO_COMPAT_VERSION}-

[ -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img ] && rm -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img
[ -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img.gz ] && rm -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img.gz
[ -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img ] && rm -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img #190112
[ -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img.gz ] && rm -f easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img.gz #190112
if [ "$DEFAULTLANG1" == "en" ];then #190107
 mv -f ${SKELETON_NAME}.img easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img
 sync
 echo "easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img has been created, gzipping it..."
 #200727 "--rsyncable" to make downloads with rsync more efficient...
 gzip --rsyncable easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img
 sync
 echo
 echo "easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DISTRO_TARGETARCH}.img.gz has been created. this may be written to"
 echo "any flash-stick or sd-card, 2GB or greater. 4GB minimum recommended."
else
 mv -f ${SKELETON_NAME}.img easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img
 sync
 echo "easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img has been created, gzipping it..."
 gzip --rsyncable easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img #200727
 sync
 echo
 echo "easy-${DISTRO_COMPAT_VERSION}-${DISTRO_VERSION}-${DEFAULTLANG1}-${DISTRO_TARGETARCH}.img.gz has been created. this may be written to"
 echo "any flash-stick or sd-card, 2GB or greater. 4GB minimum recommended."
fi

cd $WKGDIR
###########################################################################
#now do the devx...
if [ "$BUILD_CHOICE_MERGE_DEVX" == "yes" ];then #150725
 echo
 echo "Variable BUILD_CHOICE_MERGE_DEVX in file 'build-choices' is 'yes',"
 echo "so the 'devx' is merged into rootfs-complete. There will not be"
 echo "a devx PET. Finished, exiting."
 exit
fi
echo
echo -n "Hit ENTER to build the 'devx' PET file, any other key to exit: "
read dodevx
[ "$dodevx" != "" ] && exit
echo
echo "Building 'devx' PET..."

#150928
mkdir -p sandbox3/devx/usr #actually, probably already created above.
if [ -d sandbox3/devx/usr/X11R7 ];then
 if [ ! -h sandbox3/devx/usr/X11R7 ];then
  cp -a -f --remove-destination sandbox3/devx/usr/X11R7/* sandbox3/devx/usr/
  sync
  rm -rf sandbox3/devx/usr/X11R7
 else
  rm -f sandbox3/devx/usr/X11R7
 fi
fi
[ -e sandbox3/devx/usr/X11 ] && rm -f sandbox3/devx/usr/X11
[ -e sandbox3/devx/usr/X11R6 ] && rm -f sandbox3/devx/usr/X11R6
ln -s . sandbox3/devx/usr/X11R7
ln -s . sandbox3/devx/usr/X11R6
ln -s . sandbox3/devx/usr/X11

#170801 /lib64 and /usr/lib64 may have to be symlinks...
mkdir -p sandbox3/devx/lib
mkdir -p sandbox3/devx/usr/lib
case $WOOF_TARGETARCH in #161002
 x86|armv7) #32-bit
  true
 ;;
 *) #64-bit ex: amd64
  if [ "$ARCHDIR" ];then #ex1: i386-linux-gnu  ex2: x86_64-linux-gnu
   if [ "$ARCHDIR" != "lib64" ];then #150102
    if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
     mkdir -p sandbox3/devx/lib/${ARCHDIR}
     mkdir -p sandbox3/devx/usr/lib/${ARCHDIR}
     ln -snf lib/${ARCHDIR} sandbox3/devx/lib64
     ln -snf lib/${ARCHDIR} sandbox3/devx/usr/lib64
    else
     ln -snf ./ sandbox3/devx/lib64
     ln -snf ./ sandbox3/devx/usr/lib64
    fi
   else
    if [ "$DISTRO_ARCHDIR_SYMLINKS" = "no" ];then
     mkdir -p sandbox3/devx/lib64
     mkdir -p sandbox3/devx/usr/lib64
    else
     ln -snf ./ sandbox3/devx/lib64
     ln -snf ./ sandbox3/devx/usr/lib64
    fi
   fi
  fi
 ;;
esac

#rm -rf sandbox3/devx no, done above.
#mkdir sandbox3/devx
echo " building sandbox3/devx ..."
rm -f /tmp/3builddistro_removed_alt_dev #101013
ALLGENNAMESD="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | cut -f 2 -d '|' | sed -e 's%$%_DEV%'`"
for ONEDEV in `ls -1 packages-${DISTRO_FILE_PREFIX} | grep '_DEV$' | tr '\n' ' '`
do

 ONEPKG="`echo -n "$ONEDEV" | sed -e 's%_DEV%%'`"
 
 devPATTERN='^'"$ONEDEV"
 if [ "`echo "$ALLGENNAMESD" | grep "$devPATTERN"`" != "" ];then
  
  #170801 remove lib hyperlinks, some pets have it...
  [ -h packages-${DISTRO_FILE_PREFIX}/${ONEDEV}/lib64 ] && rm -f packages-${DISTRO_FILE_PREFIX}/${ONEDEV}/lib64
  [ -h packages-${DISTRO_FILE_PREFIX}/${ONEDEV}/usr/lib64 ] && rm -f packages-${DISTRO_FILE_PREFIX}/${ONEDEV}/usr/lib64
 
  #170801 fixed devx copy, following symlinks...
  cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEDEV}/* sandbox3/devx/ 2> /tmp/3builddistro-cp-errlog
  sync #110727 running drake pup 0.3 with k2.6.39-3 new laptop, mysterious loss of dirs/files. try sync.
  if [ -s /tmp/3builddistro-cp-errlog ];then #130430 next line fixes those quote chars... 150929 weird, tr creating multiple ' chars...
   #cat /tmp/3builddistro-cp-errlog | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'" |
   while read ONEDIRSYMLINK
   do
    xONEDIRSYMLINK="`echo -n "$ONEDIRSYMLINK" | sed -e 's%sandbox3/devx%%'`"
    #adding that extra trailing / does the trick...
    cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEDEV}${xONEDIRSYMLINK}/* sandbox3/devx${xONEDIRSYMLINK}/ 2> /tmp/3builddistro-cp-errlog2
    #170418 installing some april pkgs into yocto morty, there are two levels of symlinks, /usr/X11R7/lib64...
    if [ -s /tmp/3builddistro-cp-errlog2 ];then
     cat /tmp/3builddistro-cp-errlog2 | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'" |
     while read ONEDIRSYMLINK2
     do
      xONEDIRSYMLINK2="`echo -n "$ONEDIRSYMLINK2" | sed -e 's%sandbox3/devx%%'`"
      #adding that extra trailing / does the trick...
      cp -a --remove-destination packages-${DISTRO_FILE_PREFIX}/${ONEDEV}${xONEDIRSYMLINK2}/* sandbox3/devx${xONEDIRSYMLINK2}/
     done
     sync
    fi
   done<<_END1
$(cat /tmp/3builddistro-cp-errlog | grep 'cannot overwrite non-directory' | tr '[`‘’]' "'" | tr -s "'" | cut -f 2 -d "'")
_END1
  
  fi
  sync
 fi
done
sync

rm -rf sandbox3/devx/DEBIAN* 2> /dev/null #150801

#200711 have this in rootfs-complete...
if [ -d sandbox3/devx/usr/share/mime/packages ];then
 rm -rf sandbox3/devx/usr/share/mime/packages
fi

#170802 seems python ubuntu post-install script is moving usr/include to /include...
if [ -d sandbox3/devx/include ];then
 cp -a -f --remove-destination sandbox3/devx/include/* sandbox3/devx/usr/include/
 sync
 rm -rf sandbox3/devx/include
fi

#earlier above i moved all invalid symlinks into the devx module, yeah but i
#think should delete them if they really point nowhere...
echo " Deleting really invalid symlinks in devx..."
#200406 save the invalid symlinks somewhere, so can study them afterward...
[ -d sandbox3/devx-invalid-symlinks ] && rm -rf sandbox3/devx-invalid-symlinks
mkdir sandbox3/devx-invalid-symlinks
mkdir layer_top
if [ "$LAYERFS" = "aufs" ];then
 #170731 recent kernel 4.11.12 configured without layer reval...
 #mount -t aufs -o udba=reval,diropq=w,dirs=sandbox3/devx=rw:sandbox3/rootfs-complete=ro layerfs layer_top
 mount -t aufs -o br=sandbox3/devx=rw:sandbox3/rootfs-complete=ro layerfs layer_top
 if [ $? -ne 0 ];then
  echo "aufs failed to mount. ABORTING"
  exit 1
 fi
else
 #mount -t unionfs -o dirs=sandbox3/devx=rw:sandbox3/rootfs-complete=ro layerfs layer_top
 #160902 now using overlay fs...
 mkdir tempwork
 mount -t overlay -o lowerdir=sandbox3/rootfs-complete,upperdir=sandbox3/devx,workdir=tempwork overlay layer_top
 if [ $? -ne 0 ];then
  echo "overlay fs failed to mount. ABORTING"
  exit 1
 fi
fi
for ONESYMLINK in `find layer_top/ -type l`
do
 [ "`echo -n "$ONESYMLINK" | grep '/dev/'`" != "" ] && continue
 [ "`echo -n "$ONESYMLINK" | grep '/proc/'`" != "" ] && continue
 xONESYMLINK="`echo -n "$ONESYMLINK" | sed -e 's/^layer_top//'`"
 #111123 cross-build, cannot do chroot...
 if [ "$WOOF_HOSTARCH" = "$WOOF_TARGETARCH" ];then #111123
  if [ "`chroot layer_top readlink -e $xONESYMLINK`" = "" ];then
   echo " $ONESYMLINK"
   #200406 instead of deleting, save broken symlink...
   #rm -f $ONESYMLINK
   xONESYMPATH="$(dirname "$xONESYMLINK")"
   xONESYMNAME="$(basename "$xONESYMLINK")"
   mkdir -p "sandbox3/devx-invalid-symlinks${xONESYMPATH}"
   mv -f "${ONESYMLINK}" "sandbox3/devx-invalid-symlinks${xONESYMPATH}/${xONESYMNAME}"  
  fi
 else
  #do it without chroot...
  LINKTO="`readlink layer_top${xONESYMLINK}`"
  [ -e layer_top${LINKTO} ] && continue #absolute path
  UPONE="`dirname "$xONESYMLINK"`"
  [ -e layer_top${UPONE}/${LINKTO} ] && continue #relative path
  echo " $ONESYMLINK"
  #200406 instead of deleting, save broken symlink...
  #rm -f $ONESYMLINK
  xONESYMPATH="$(dirname "$xONESYMLINK")"
  xONESYMNAME="$(basename "$xONESYMLINK")"
  mkdir -p "sandbox3/devx-invalid-symlinks${xONESYMPATH}"
  mv -f "${ONESYMLINK}" "sandbox3/devx-invalid-symlinks${xONESYMPATH}/${xONESYMNAME}"  
 fi
done
sync
umount layer_top
rm -rf tempwork 2>/dev/null #160902
rmdir layer_top

###HACK###
if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python|' | grep 'exe>dev')" != "" ];then #121022
 [ -e sandbox3/devx/usr/bin/python2.5 ] && ln -s python2.5 sandbox3/devx/usr/bin/python 2>/dev/null
 [ -e sandbox3/devx/usr/bin/python2.6 ] && ln -s python2.6 sandbox3/devx/usr/bin/python 2>/dev/null
 [ -e sandbox3/devx/usr/bin/python2.7 ] && ln -s python2.7 sandbox3/devx/usr/bin/python 2>/dev/null
fi
 rm -f sandbox3/devx/usr/lib/mozilla/plugins/* #100407 maybe .a, .la files in here.
 
#131212 weird, this should not be there (was removed way above)...
if [ "$(echo "$PKGS_SPECS_TABLE" | grep '^yes|python|' | grep 'exe>dev')" != "" ];then
 [ -e sandbox3/rootfs-complete/usr/lib/python2.5 ] && rm -rf sandbox3/rootfs-complete/usr/lib/python2.5
 [ -e sandbox3/rootfs-complete/usr/lib/python2.6 ] && rm -rf sandbox3/rootfs-complete/usr/lib/python2.6
 [ -e sandbox3/rootfs-complete/usr/lib/python2.7 ] && rm -rf sandbox3/rootfs-complete/usr/lib/python2.7
fi
###END HACK###

#v424 no, i have needed docs in usr/share/doc...
#w003 there's docs here, move them out...
rm -rf packages-${DISTRO_FILE_PREFIX}/devx_DOC 2>/dev/null
mkdir -p packages-${DISTRO_FILE_PREFIX}/devx_DOC/usr/share
#mv sandbox3/devx/usr/share/doc packages-${DISTRO_FILE_PREFIX}/devx_DOC/usr/share/ 2>/dev/null
mv sandbox3/devx/usr/share/doc-base packages-${DISTRO_FILE_PREFIX}/devx_DOC/usr/share/ 2>/dev/null
mv sandbox3/devx/usr/share/man packages-${DISTRO_FILE_PREFIX}/devx_DOC/usr/share/ 2>/dev/null

##100831 hack, this symlink needed...
#if [ -d sandbox3/devx/usr/X11R7/include/xorg ];then
# [ ! -e sandbox3/devx/usr/include/xorg ] && ln -s ../X11/include/xorg sandbox3/devx/usr/include/xorg
#fi

#100622 remove overhead of this script running every bootup...
mkdir -p sandbox3/devx/etc/profile.d
rm -f sandbox3/devx/etc/profile.d/pkgconfig* 2>/dev/null #140102 improve...
#141230 add sandbox3/devx/lib 141231 lib64...
DEVXLIBnorm=''; DEVXLIB64=''; DEVXUSRLIB64=''
[ -d sandbox3/devx/lib ] && DEVXLIBnorm='sandbox3/devx/lib'
[ -d sandbox3/devx/lib64 ] && DEVXLIB64='sandbox3/devx/lib64'
[ -d sandbox3/devx/usr/lib64 ] && DEVXUSRLIB64='sandbox3/devx/usr/lib64'
PKG_CONFIG_PATH="`find ${DEVXLIBnorm} ${DEVXLIB64} ${DEVXUSRLIB64} sandbox3/devx/usr/share sandbox3/devx/usr/lib sandbox3/devx/opt sandbox3/devx/usr/local/lib -type d -name pkgconfig | sed -e 's%sandbox3/devx%%' | tr '\n' ':' | sed -e 's%:$%%'`"
echo "export PKG_CONFIG_PATH='${PKG_CONFIG_PATH}'" > sandbox3/devx/etc/profile.d/pkgconfig

#maybe stray /install dir from slackware pkgs...
rm -rf sandbox3/devx/install 2>/dev/null
[ -f sandbox3/devx/pet.specs ] && rm -f sandbox3/devx/pet.specs #w478
sync

#110215 BaCon...
#111203 remove offer to download and compile bacon (no good for cross-builds)...
if [ ! -f sandbox3/devx/usr/bin/bacon ];then
#if [ -f sandbox3/devx/usr/bin/bacon ];then
# BACONPKG="`grep '|bacon|' sandbox3/rootfs-complete/root/.packages/woof-installed-packages | cut -f 1 -d '|'`"
# echo
# echo "The devx has BaCon compiler package: ${BACONPKG}"
# echo "Great, but if you have an Internet connection, you may update it, however this"
# echo "does not always work as a very recent /usr/bin/bacon must be installed..."
#else
 echo
 echo "Oh, you do not have the BaCon compiler in devx."
 echo "It is recommended that variable PKGS_SPECS_TABLE in file DISTRO_PKGS_SPECS-* have this entry:"
 echo "yes|bacon||exe>dev,dev,doc>dev,nls"
 echo "It is recommended that all Puppy distros standardise on having BaCon available."
# echo "Anyway, if you have an Internet connection, BaCon can be downloaded now, however"
# echo "this does not always work as you need a very recent /usr/bin/bacon already installed..."
fi
echo -n "Press ENTER to continue: "
read keepgoing
##101217 get latest BaCon...
#if [ -f support/fetch ];then #see http://www.basic-converter.org/fetch.bac
# if [ "`which bacon`" != "" ];then
#  echo
#  echo "Press any printable key (then ENTER) to download latest BaCon BASIC compiler"
#  echo "and support files. You will need Internet access to do this."
#  echo -n "ENTER key only to decline, any other printable char to download: "
#  read dobacon
#  if [ "$dobacon" != "" ];then
#   mkdir -p sandbox3/devx/usr/share/BaCon
#   rm -f sandbox3/devx/usr/share/BaCon/* 2>/dev/null
#   cp support/fetch sandbox3/devx/usr/share/BaCon/
#   cd sandbox3/devx/usr/share/BaCon
#   ./fetch
#   sync
#   [ ! -f documentation.pdf ] && wget http://www.basic-converter.org/documentation.pdf
#   [ ! -f documentation.html ] && wget http://www.basic-converter.org/documentation.html
#   [ ! -f hug.txt ] && wget http://www.basic-converter.org/hug.txt
#   [ ! -f sqlite3.txt ] && wget http://www.basic-converter.org/sqlite3.txt
#   [ ! -f gmp.txt ] && wget http://www.basic-converter.org/gmp.txt
#   [ ! -f curses.txt ] && wget http://www.basic-converter.org/curses.txt
#   [ ! -f pthreads.txt ] && wget http://www.basic-converter.org/pthreads.txt
#   [ ! -f gd.txt ] && wget http://www.basic-converter.org/gd.txt
#   [ ! -f gtk.txt ] && wget http://www.basic-converter.org/gtk.txt
#   [ ! -f gl.txt ] && wget http://www.basic-converter.org/gl.txt
#   ##fetch has already downloaded bacon.bac, but want beta version...
#   #mv -f bacon.bac bacon-released.bac
#   #wget http://www.basic-converter.org/beta/bacon.bac
#   #[ $? -ne 0 ] && mv -f bacon-released.bac bacon.bac
#   #mv -f documentation.html documentation-released.html
#   #wget http://www.basic-converter.org/beta/documentation.html
#   #[ $? -ne 0 ] && mv -f documentation-released.html documentation.html
#   sync
#   if [ -f bacon.bac ];then
#    bacon bacon.bac
#    sync
#    if [ -f bacon ];then
#     cp -f -a bacon ../../bin/
#     echo "...done"
#    else
#     echo "ERROR: bacon did not compile!"
#    fi
#   fi
#   cd ../../../../../ #back to woof-tree project dir.
#  fi
# else
#  echo
#  echo "WARNING: 'devx' SFS not loaded, cannot install latest BaCon BASIC compiler."
#  echo "         (or current loaded devx SFS does not have BaCon compiler in it)"
# fi
#fi

#110429 see above, think want glibc scsi headers in usr/include/scsi...
if [ -d sandbox3/devx/usr/include/scsi-GLIBC ];then
 #probably have kernel scsi headers in usr/include/scsi, fix...
 cp -a -f sandbox3/devx/usr/include/scsi-GLIBC/* sandbox3/devx/usr/include/scsi/
fi

#110702 mageia1 python puts 30python.csh here...
rm -f sandbox3/devx/etc/profile.d/*.csh

#140122 not sure about this...
if [ "$(echo -n "$xARCHDIR" | cut -c 1)" == "/" ];then #150102
 #CPATH works any language, replaces C_INCLUDE_PATH and CPLUS_INCLUDE_PATH
 echo "export CPATH=/usr/include/${ARCHDIR}" > sandbox3/devx/etc/profile.d/archinc
fi

#140123 'man-1.6f' binary pkg from T2 has bug, everything in /usr/usr...
if [ -d sandbox3/devx/usr/usr ];then
 cp -a -f --remove-destination sandbox3/devx/usr/usr/bin/* sandbox3/devx/usr/bin/ 2>/dev/null
 cp -a -f --remove-destination sandbox3/devx/usr/usr/sbin/* sandbox3/devx/usr/sbin/ 2>/dev/null
 cp -a -f --remove-destination sandbox3/devx/usr/usr/share/* sandbox3/devx/usr/share/ 2>/dev/null
 sync
 rm -rf sandbox3/devx/usr/usr
fi

#130111 fixed in 2createpackages...
##110726 mageia does something weird, puts all these in wrong place...
#if [ -d sandbox3/devx/usr/bin/multiarch-i386-linux ];then
# cp -a -f --remove-destination sandbox3/devx/usr/bin/multiarch-i386-linux/* sandbox3/devx/usr/bin/
# rm -rf sandbox3/devx/usr/bin/multiarch-i386-linux
#fi

#131229 quirky6, devx now a pet, need to delete some files...
[ -f sandbox3/devx/etc/ld.so.conf ] && rm -f sandbox3/devx/etc/ld.so.conf
[ -h sandbox3/devx/etc/localtime ] && rm -f sandbox3/devx/etc/localtime
#140102 [ -f sandbox3/devx/etc/profile.d/pkgconfig ] && rm -f sandbox3/devx/etc/profile.d/pkgconfig

#140122 seamonkey compile, unable to find gdkconfig.h, glibconfig.h... (note, i actually put these in /usr/include, but this should work also...)
if [ "$xARCHDIR" ];then #150102 fix
 for AINC in `find sandbox3/devx/usr/lib${xARCHDIR} -type d -name 'include' | sed -e "s%sandbox3/devx/usr/%%" | tr '\n' ' '` #ex: glib-2.0/include
 do
  mkdir -p sandbox3/devx/usr/${AINC} #ex: sandbox3/devx/usr/lib/glib-2.0/include
  xAINC="$(echo -n "$AINC" | sed -e 's%lib${xARCHDIR}/%%')"
  cp -a -f --remove-destination sandbox3/devx/usr/${AINC}/*.h sandbox3/devx/usr/lib/${xAINC}/ 2>/dev/null
 done
fi

#141017 quirky unicorn, compile seamonkey needs /usr/sbin/i686-linux-gnu-gcc, but only have ...-gcc-4.6 symlink.
GCCLINK="$(find sandbox3/devx/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-gcc-*' | head -n 1)"
if [ "$GCCLINK" ];then
 xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
 #xxBASE="$(basename $GCCLINK)"
 #ln -s $xxBASE $xxLINK
 [ ! -e $xxLINK ] && cp -a $GCCLINK $xxLINK
fi
#these also...
GCCLINK="$(find sandbox3/devx/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-cpp-*' | head -n 1)"
if [ "$GCCLINK" ];then
 xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
 [ ! -f $xxLINK ] && cp -a $GCCLINK $xxLINK
fi
GCCLINK="$(find sandbox3/devx/usr/bin -mindepth 1 -maxdepth 1 -type l -name '*-linux-gnu-g++-*' | head -n 1)"
if [ "$GCCLINK" ];then
 xxLINK="$(echo -n "$GCCLINK" | rev | cut -f 2- -d '-' | rev)"
 [ ! -e $xxLINK ] && cp -a $GCCLINK $xxLINK
fi

#141019 quirky unicorn has lots of /usr/share/doc/*-dev folders...
DOCDEVDIRS="$(find sandbox3/devx/usr/share/doc -mindepth 1 -maxdepth 1 -type d -name '*-dev')"
if [ "$DOCDEVDIRS" ];then
 echo
 echo 'Deleting sandbox3/devx/usr/share/doc/*-dev folders...'
 for ADDD in $DOCDEVDIRS
 do
  [ -d $ADDD ] && rm -rf $ADDD
 done
fi
#also clean out more files...
DOCDEVFILES="$(find sandbox3/devx/usr/share/doc -type f -name '*.gz')"
if [ "$DOCDEVFILES" ];then
 echo
 echo 'Deleting sandbox3/devx/usr/share/doc/*/*.gz files...'
 for ADDF in $DOCDEVFILES
 do
  [ -f $ADDF ] && rm -f $ADDF
 done
fi
DOCDEVFILES="$(find sandbox3/devx/usr/share/doc -type f -name 'copyright')"
if [ "$DOCDEVFILES" ];then
 echo
 echo 'Deleting sandbox3/devx/usr/share/doc/*/copyright files...'
 for ADDF in $DOCDEVFILES
 do
  [ -f $ADDF ] && rm -f $ADDF
 done
fi

#150724 app-inventor pkg has .git folder, 381MB, offer to remove...
echo
echo "Searching for any .git folders in sandbox3/devx..."
FNDGIT="$(find sandbox3/devx -type d -name '.git')"
if [ "$FNDGIT" ];then
 echo
 echo "These .git folders have been found:"
 echo "$FNDGIT"
 echo
 echo -n "Press ENTER only to delete them: "
 read deletethem
 if [ "$deletethem" == "" ];then
  for AGIT in `echo -n "$FNDGIT" | tr '\n' ' '`
  do
   echo " deleting ${AGIT}"
   rm -rf ./${AGIT}
  done
 fi
fi

##150925 april, this 'fonts' folder is a symlink, but devx has it as a folder. hack...
#if [ -d sandbox3/devx/usr/X11R7/share/fonts ];then
# rm -rf sandbox3/devx/usr/X11R7/share/fonts
#fi

#170813 there is a lot of stuff in devx/usr/share/doc...
#delete empty folders...
find sandbox3/devx/usr/share/doc -mindepth 1 -type d -empty -delete
#...this will cause some broken symlinks, delete symlinks...
#find sandbox3/devx/usr/share/doc -mindepth 1 -type l -delete
for ALINK in `find sandbox3/devx/usr/share/doc -mindepth 1 -type l | tr '\n' ' '`
do
 if ! readlink -e "$ALINK" >/dev/null ;then rm -f ./"$ALINK" ; fi
done

#181029 devx folder has some aufs whiteout files. these exist because of invalid symlinks in easy.sfs,
# for example usr/lib/.wh.libmozsqlite3.so usr/lib/gtk-2.0/2.10.0/.wh.loaders usr/share/pixmaps/.wh.x48.png
# ...they should be fixed. delete the whiteout files/folders in devx...
echo "deleting some aufs whiteout files in devx folder..."
find sandbox3/devx -type f -name '.wh.*' -delete
find sandbox3/devx -type d -name '.wh.*' -delete

#181029 OE pkgs have this file, stray one is left...
[ -f sandbox3/devx/pkg.specs ] && rm -f sandbox3/devx/pkg.specs

sync

############################
#170814 create devx .sfs only...
##140120 create devx .pet (not .sfs)...
#181029 change name from devx-${VER}-${DISTRO_FILE_PREFIX} to devx_${VER}_${DISTRO_TARGETARCH}
cd sandbox3
VER="$DISTRO_VERSION"
rm -rf devx_${VER}_${DISTRO_TARGETARCH} 2>/dev/null
mkdir -p devx_${VER}_${DISTRO_TARGETARCH}
cp -a -f devx/* devx_${VER}_${DISTRO_TARGETARCH}/
sync

#170526 keep the .a static libs!... 171107 build-choice variable...
if [ "$BUILD_CHOICE_DEVX_STATIC_KEEP" != "yes" ];then
 #probably a good idea. quirky devx pet 6.1 is 236MB (sfs is 135MB --xz'ed), after removing .a's is 198MB...
 for ASO in `find devx_${VER}_${DISTRO_TARGETARCH} -name '*.so' | tr ' ' 'x' | tr '\n' ' '`
 do
  [ "`echo -n "$ASO" | grep -i 'qt'`" != "" ] && continue
  [ "`echo -n "$ASO" | grep -i 'mm'`" != "" ] && continue
  [ "`echo -n "$ASO" | grep -i 'fltk'`" != "" ] && continue
  [ "`echo -n "$ASO" | grep -i 'diet'`" != "" ] && continue
  ADIR="`dirname $ASO`"
  ANAME="`basename $ASO .so`"
 
  #150925 want to leave these .a's alone (from glibc)...
  [ "$ANAME" == "libc" ] && continue
  [ "$ANAME" == "libanl" ] && continue
  [ "$ANAME" == "libBrokenLocale" ] && continue
  [ "$ANAME" == "libBrokenLocale_pic" ] && continue
  [ "$ANAME" == "libc_nonshared" ] && continue
  [ "$ANAME" == "libcrypt" ] && continue
  [ "$ANAME" == "libdl" ] && continue
  [ "$ANAME" == "libm" ] && continue
  [ "$ANAME" == "libnsl" ] && continue
  [ "$ANAME" == "libresolv" ] && continue
  [ "$ANAME" == "librt" ] && continue
  [ "$ANAME" == "libutil" ] && continue
  [ "$ANAME" == "libpthread" ] && continue
  [ "$ANAME" == "libmvec" ] && continue #180818
  [ "$ANAME" == "libstdc++" ] && continue #200511 livecode needs libstdc++.a to compile.
   
  [ -e ${ADIR}/${ANAME}.a ] && rm -f ${ADIR}/${ANAME}.a
 done
 sync
 #140201 deleting the .a, leaves some broken links behind. ex in quirky tahr /lib/i386-linux-gnu/libcurses.a -> libncurses.a
 for AA in `find devx_${VER}_${DISTRO_TARGETARCH} -type l -name '*.a' | tr ' ' 'x' | tr '\n' ' '`
 do
  ALINK="`readlink $AA`"
  [ ! "$ALINK" ] && continue
  AL1="${ALINK:0:1}"
  if [ "$AL1" = "/" ];then
   ALSPEC="devx_${VER}_${DISTRO_TARGETARCH}${ALINK}"
  else
   ALDIR="`dirname $AA`"
   ALSPEC="${ALDIR}/${ALINK}"
  fi
  [ ! -e ${ALSPEC} ] && rm -f $AA 2>/dev/null
 done
fi

#140201 this is a hack...
#quirky tahr, devx has /usr/bin/man, but main f.s. has man as a symlink to script pman...
if [ -e devx_${VER}_${DISTRO_TARGETARCH}/usr/bin/man ];then
 rm -f devx_${VER}_${DISTRO_TARGETARCH}/usr/bin/man
 ln -s pman devx_${VER}_${DISTRO_TARGETARCH}/usr/bin/man #so as to restore symlink if earlier devx deleted it.
fi

SIZEK="$(du -s -k devx_${VER}_${DISTRO_TARGETARCH} | cut -f 1)"
#echo "devx-${VER}-${DISTRO_FILE_PREFIX}|devx|${VER}-${DISTRO_FILE_PREFIX}||Utility;development|${SIZEK}K||devx-${VER}-${DISTRO_FILE_PREFIX}.pet||A complete C/C++/Vala/Genie/BaCon compiling environment for Quirky, with extras such as svn, git, gdb|${DISTRO_BINARY_COMPAT}|${DISTRO_COMPAT_VERSION}||" > devx-${VER}-${DISTRO_FILE_PREFIX}/pet.specs

##cat << 'EX1' >> devx-${VER}-${DISTRO_FILE_PREFIX}/pinstall.sh
#echo "#!/bin/sh
#if [ \$DISPLAY ];then
#pupmessage -bg '#80FF80' -title \"devx version: ${VER}\" \"Congratulations, Quirky has been converted into a complete C/C++/Vala/Genie/BaCon compiling environment for Quirky, with extras such as svn, git, gdb, nasm, yasm and python.
#
#It is strongly recommended to reboot now, for the package installation to take full effect (please wait a few minutes though, for some final install operations to complete).
#
#Note: This package can be uninstalled by the Quirky Package Manager.
#Suggestion: After rebooting, take a snapshot of the system (see Snapshot Manager in Filesystem menu) -- very handy for later, if you want to get rid of packages after having compiled and installed them.\" &
#fi" > devx-${VER}-${DISTRO_FILE_PREFIX}/pinstall.sh
#chmod 755 devx-${VER}-${DISTRO_FILE_PREFIX}/pinstall.sh
##EX1

#sync
#[ -f devx-${VER}-${DISTRO_FILE_PREFIX}.tar.gz ] && rm -f devx-${VER}-${DISTRO_FILE_PREFIX}.tar.gz
#[ -f devx-${VER}-${DISTRO_FILE_PREFIX}.pet ] && rm -f devx-${VER}-${DISTRO_FILE_PREFIX}.pet
#dir2tgz devx-${VER}-${DISTRO_FILE_PREFIX}/
#tgz2pet devx-${VER}-${DISTRO_FILE_PREFIX}.tar.gz
sync

##170220 remove pinstall.sh and pet.specs when create devx .sfs...
#rm -f devx-${VER}-${DISTRO_FILE_PREFIX}/pinstall.sh
#rm -f devx-${VER}-${DISTRO_FILE_PREFIX}/pet.specs
#sync

#181102 create meta-data for sfs (ref: /usr/local/sfsget/dir2sfs). 181122 fix
echo "Creating meta-data for devx..."
echo "#generated by 3buildeasydistro:
DB_pkgname='devx_${VER}'
DB_nameonly='devx'
DB_version='${VER}'
DB_revision=''
DB_arch='${DISTRO_TARGETARCH}'
DB_categories='Utility'
DB_size='${SIZEK}'
DB_fullfilename='devx_${VER}_${DISTRO_TARGETARCH}.sfs'
DB_dependencies='easy_${VER}'
DB_description='Development environment'
DB_description_long='devx is a complete C/C++/BaCon/Vala compiling environment, for creating GTK/Qt/Xlib apps, as well as CLI utilities, with major support tools such as svn, git and gdb.'
DB_compileddistro='${DISTRO_BINARY_COMPAT}'
DB_compiledrelease='${DISTRO_COMPAT_VERSION}'
DB_path='easyos/${DISTRO_BINARY_COMPAT}/${DISTRO_COMPAT_VERSION}'
DB_apps='devx'
DB_icons='devx'
DB_install='terminal'
DB_hash=''" > export-sfs-${DEFAULTLANG1}/devx_${VER}_${DISTRO_TARGETARCH}.specs
#icons...
mkdir -p devx_${VER}_${DISTRO_TARGETARCH}/.control
cp -a -f export-sfs-${DEFAULTLANG1}/devx_${VER}_${DISTRO_TARGETARCH}.specs devx_${VER}_${DISTRO_TARGETARCH}/.control/devx.specs
cp -a -f /usr/share/pixmaps/puppy/terminal.svg ./
cp -a -f /usr/local/lib/X11/pixmaps/ec-overlay48.png ./
cp -f /usr/sbin/pngoverlay ./
picscale -i terminal.svg -o devx48.png 48 48 9
./pngoverlay devx48.png ec-overlay48.png ec-devx48.png
mkdir -p devx_${VER}_${DISTRO_TARGETARCH}/usr/share/pixmaps
cp -f devx48.png devx_${VER}_${DISTRO_TARGETARCH}/usr/share/pixmaps/
cp -f ec-devx48.png devx_${VER}_${DISTRO_TARGETARCH}/usr/share/pixmaps/
cp -f devx48.png export-sfs-${DEFAULTLANG1}/devx.png
#dummy .desktop...
mkdir -p devx_${VER}_${DISTRO_TARGETARCH}/usr/share/applications
echo "[Desktop Entry]
NoDisplay=true
Name=devx
Exec=ec-chroot-devx
Icon=ec-devx48.png
Categories=X-Utility" > devx_${VER}_${DISTRO_TARGETARCH}/usr/share/applications/devx.desktop
#run script...
mkdir -p devx_${VER}_${DISTRO_TARGETARCH}/usr/sbin
echo "#!/bin/sh
empty -f ec-chroot devx sakura" > devx_${VER}_${DISTRO_TARGETARCH}/usr/sbin/ec-chroot-devx
chmod 755 devx_${VER}_${DISTRO_TARGETARCH}/usr/sbin/ec-chroot-devx
#***NOTICE*** haven't created .control/devx.configuration (190830: have /usr/local/easy_containers/templates/devx/configuration)
sync

#also create .sfs file, used by 5create-devx-service-packs...
[ -f devx_${VER}_${DISTRO_TARGETARCH}.sfs ] && rm -f devx_${VER}_${DISTRO_TARGETARCH}.sfs
mksquashfs devx_${VER}_${DISTRO_TARGETARCH} devx_${VER}_${DISTRO_TARGETARCH}.sfs ${COMPCHOICE} -processors 1
sync
rm -rf devx_${VER}_${DISTRO_TARGETARCH}
echo
echo "Created: devx_${VER}_${DISTRO_TARGETARCH}.sfs"

cp -a -f devx_${VER}_${DISTRO_TARGETARCH}.sfs export-sfs-${DEFAULTLANG1}/
sync
HASH="$(sha256sum export-sfs-${DEFAULTLANG1}/devx_${VER}_${DISTRO_TARGETARCH}.sfs | cut -f 1 -d ' ')"
sed -i -e "s%^DB_hash=.*%DB_hash='${HASH}'%" export-sfs-${DEFAULTLANG1}/devx_${VER}_${DISTRO_TARGETARCH}.specs

cd ..
sync
echo "...done"

###END###

