#!/bin/bash #Copyright 2003 William Stearns MSIVer='0.1.0' #To add a new package, put in approriate sections everywhere you see #ADD #FIXME - check for more than one i386 rpm. Banner () { echo "======== $* ========" } Debug () { echo "$*" >&2 } RequireUtil () { while [ -n "$1" ]; do if ! type -path "$1" >/dev/null 2>/dev/null ; then echo Missing utility "$1". Please install it. >&2 return 1 #False, app is not available. fi shift done return 0 #True, app is there. } #End of RequireUtil GetFile () { if [ -n "$1" ]; then for OneSource in $Sources ; do case $OneSource in /*) #Local path if [ -n "`ls -A1rt $OneSource/$1 2>/dev/null`" ]; then Debug $1 found in $OneSource if [ "$OneSource" = "$Cache" ]; then Debug $1 already in cache break else Debug Copying $1 from $OneSource cp -p $OneSource/$1 $Cache >/dev/null && break #Exit if successful fi fi ;; *::*) #Rsync if rsync "$OneSource/$1" >/dev/null 2>&1 ; then #Return code 0=file exists, 23, not there. Works with wildcards. Debug Rsyncing $1 down from $OneSource rsync -a "$OneSource/$1" "$Cache" >/dev/null && break #Exits from innermost for/while/until loop. else Debug Rsync $OneSource doesn\'t have $1 fi ;; http*|ftp*) Debug http/ftp unimplemented. # cd "$WorkDir/sources/" # wget "$1" # cd - ;; esac done else Debug Nothing requested in GetFile fi echo `ls -A1rt $Cache/$1 2>/dev/null | tail -1` #Most recent cached rpm } BuildRpm () { Banner $1 if [ "$build" = 'yes' ]; then MyRpm=`GetFile $1-*.src.rpm` Debug Source RPM is $MyRpm if ! rpm --checksig $MyRpm ; then echo Source RPM signature failed for $MyRpm, exiting. exit 1 fi rpm --rebuild "$MyRpm" fi cd "$WorkDir/unpack/" rpm2cpio $RpmDir/$1-*.i386.rpm | cpio -i -d -m case $1 in nmap) rpm2cpio $RpmDir/nmap-frontend-*.i386.rpm | cpio -i -d -m ;; util-linux) rpm2cpio $RpmDir/mount-*.i386.rpm | cpio -i -d -m rpm2cpio $RpmDir/losetup-*.i386.rpm | cpio -i -d -m ;; esac } echo "mkstaticiso Version $MSIVer" echo "Copyright 2003 William Stearns \" echo RequireUtil [ bzip2 cc cd chmod cp cpio date gcc grep ls mkdir mkisofs mktemp rm rmdir rpm rpm2cpio rsync tail wget || exit 1 build='yes' for OneRequest in $* ; do case $OneRequest in --build) build='yes' ;; --nobuild) build='no' ;; #ADD #Template #packagename|oneapp|anotherapp) # packagename='yes' # ;; bash) bash='yes' ;; binutils|addr2line|ar|as|gasp|gprof|ld|nm|objcopy|objdump|ranlib|readelf|size|strings|strip) binutils='yes' ;; bzip2|bunzip2) bzip2='yes' ;; cpio) cpio='yes' ;; diffutils|cmp|diff|diff3|sdiff) diffutils='yes' ;; e2fsprogs|badblocks|debugfs|dumpe2fs|e2fsck|e2image|e2label|fsck|fsck.ext2|fsck.ext3|mke2fs|mkfs.ext2|mkfs.ext3|resize2fs|tune2fs|chattr|lsattr|uuidgen|mklost+found) e2fsprogs='yes' ;; file) file='yes' ;; fileutils|chgrp|chmod|chown|cp|dd|df|ln|ls|mkdir|mknod|mv|rm|rmdir|sync|touch|dir|dircolors|du|install|mkfifo|shred|vdir) fileutils='yes' ;; findutils|find|xargs) findutils='yes' ;; ftp|pftp) ftp='yes' ;; gawk|awk|igawk|pgawk) gawk='yes' ;; grep|egrep|fgrep) grep='yes' ;; hexedit) hexedit='yes' ;; iputils|ping|arping|ifenslave|clockdiff|ping6|rdisc|tracepath|tracepath6|traceroute6) iputils='yes' ;; less) less='yes' ;; lsof) lsof='yes' ;; modutils|depmod|genksyms|insmod|insmod.static|insmod_ksymoops_clean|kallsyms|kernelversion|ksyms|lsmod|modinfo|modprobe|rmmod) modutils='yes' ;; nc) nc='yes' ;; net-tools|dnsdomainname|domainname|hostname|netstat|nisdomainname|ypdomainname|arp|ether-wake|ifconfig|ipmaddr|iptunnel|mii-tool|nameif|plipconfig|route|slattach) nettools='yes' ;; nmap|nmapfe|xnmap) nmap='yes' ;; openssh|sftp|slogin|ssh|ssh-add|ssh-agent|ssh-keyscan|sshd|scp|ssh-keygen) openssh='yes' ;; procps|ps|sysctl|free|oldps|pgrep|pkill|skill|snice|tload|top|uptime|vmstat|w|watch) procps='yes' ;; psmisc|fuser|killall|pstree) psmisc='yes' ;; rpm|gendiff|rpm2cpio|rpmdb|rpmquery|rpmsign|rpmverify) rpm='yes' ;; rsync) rsync='yes' ;; sed) sed='yes' ;; sh-utils|basename|date|echo|false|nice|pwd|sleep|stty|su|true|uname|[|dirname|env|expr|factor|groups|hostid|id|logname|nohup|pathchk|pinky|printenv|printf|seq|tee|test|tty|users|who|whoami|yes|chroot) shutils='yes' ;; stat) stat='yes' ;; strace) strace='yes' ;; stunnel) stunnel='yes' ;; sysvinit|SysVinit|halt|init|killall5|pidof|poweroff|reboot|runlevel|shutdown|sulogin|telinit|last|lastb|mesg|utmpdump|wall) sysvinit=yes ;; tar|gtar) tar='yes' ;; telnet) telnet='yes' ;; textutils|cat|cut|sort|cksum|comm|csplit|cut|expand|fmt|fold|head|join|md5sum|nl|od|paste|pr|ptx|sha1sum|split|sum|tac|tail|tr|tsort|unexpand|uniq|wc) textutils='yes' ;; util-linux|arch|dmesg|kill|login|more|addpart|agetty|blockdev|clock|ctrlaltdel|delpart|elvtune|fdisk|fsck.minix|hwclock|kbdrate|mkfs|mkfs.bfs|mkfs.minix|mkswap|nologin|partx|pivot_root|rescuept|sfdisk|cal|chfn|chsh|col|colcrt|colrm|column|cytune|ddate|fdformat|getopt|hexdump|ipcrm|ipcs|kbdrate|logger|look|mcookie|mkcramfs|namei|newgrp|raw|rename|renice|rev|script|setfdprm|setsid|setterm|ul|whereis|write|hwclock|ramsize|rdev|readprofile|rootflags|tunelp|vidmode|vigr|vipw|mount|umount|swapoff|swapon) utillinux='yes' ;; wget) wget='yes' ;; *) Debug 'Unknown request '$OneRequest', what rpm has that? Exiting.' exit 1 ;; esac done #ADD - put in $packagename inside the double quotes if [ -z "$bash$binutils$bzip2$cpio$diffutils$e2fsprogs$file$fileutils$findutils$ftp$gawk$grep$hexedit$iputils$less$lsof$modutils$nc$nettools$nmap$openssh$procps$psmisc$rpm$rsync$sed$shutils$stat$strace$stunnel$sysvinit$tar$telnet$textutils$utillinux$wget" ]; then #If no requests made, build everything #ADD #Template #packagename='yes' bash='yes' binutils='yes' bzip2='yes' cpio='yes' diffutils='yes' e2fsprogs='yes' file='yes' fileutils='yes' findutils='yes' ftp='yes' gawk='yes' grep='yes' hexedit='yes' iputils='yes' less='yes' lsof='yes' modutils='yes' nc='yes' nettools='yes' nmap='yes' openssh='yes' procps='yes' psmisc='yes' rpm='yes' rsync='yes' sed='yes' shutils='yes' stat='yes' strace='yes' stunnel='yes' sysvinit='yes' tar='yes' telnet='yes' textutils='yes' utillinux='yes' wget='yes' fi #Preferred first, space separated rsync or /path/ dirs (future ftp/http) Sources="/usr/src/staticiso-sources/ zaphod.stearns.org::redhatmirror/pub/redhat/linux/updates/7.3/en/os/SRPMS/ zaphod.stearns.org::redhatmirror/pub/redhat/linux/7.3/en/os/i386/SRPMS/" Cache=/usr/src/staticiso-sources/ RpmDir='/home/wstearns/rpm/RPMS/i386/' #FIXME - mktemp'ed workdir if [ -z "$WorkDir" ]; then WorkDir="$HOME/staticiso-build/" fi mkdir --parents "$Cache" if [ -d "$WorkDir" ]; then echo "$WorkDir exists, exiting." exit 1 fi mkdir --parents "$WorkDir" mkdir --parents "$WorkDir/unpack/" if ! cd "$WorkDir" 2>/dev/null ; then echo "Unable to change to $WorkDir, exiting." exit 1 fi #Approach 1 #This works for most, but I'd like to see the gcc/cc wrappers universally do the work. They don't, of course. export CFLAGS="$CFLAGS -static" export LDFLAGS="$LDFLAGS -static" #Approach 2 #Doesn't appear to help at first glance. #gcc () { # /usr/bin/gcc -static $* #} #export -f gcc #cc () { # /usr/bin/cc -static $* #} #export -f cc #Approach 3 BinDir=`mktemp -d -q $HOME/bin.XXXXXX` if [ $? -ne 0 ]; then echo "$0: Can't create temp directory $HOME/bin.XXXXXX, exiting..." >&2 exit 1 fi Debug Installing BinDir $BinDir chmod 700 $BinDir export PATH="$BinDir:$PATH" Debug Path is now $PATH cat >$BinDir/README <$BinDir/gcc <>$BinDir/gcc-called EOF chmod 755 $BinDir/gcc cat >$BinDir/cc <>$BinDir/cc-called EOF chmod 755 $BinDir/cc #Needed? Doesn't seem to help with procps cat >$BinDir/ld <>$BinDir/ld-called EOF chmod 755 $BinDir/ld cat >$BinDir/i386-redhat-linux-gcc <>$BinDir/i386-redhat-linux-gcc-called EOF chmod 755 $BinDir/i386-redhat-linux-gcc #ADD #[ "$ZZ" = 'yes' ] && BuildRpm ZZ # [ "$bash" = 'yes' ] && BuildRpm bash #Static #[ "$binutils" = 'yes' ] && BuildRpm binutils #Doesn't build. FIXME [ "$binutils" = 'yes' ] && echo 'WARNING - binutils does not build, disabling' [ "$bzip2" = 'yes' ] && BuildRpm bzip2 #bzip2 not static [ "$cpio" = 'yes' ] && BuildRpm cpio #Static [ "$diffutils" = 'yes' ] && BuildRpm diffutils #Static [ "$e2fsprogs" = 'yes' ] && BuildRpm e2fsprogs #Not sure. [ "$file" = 'yes' ] && BuildRpm file #Static [ "$gawk" = 'yes' ] && BuildRpm gawk #Static [ "$grep" = 'yes' ] && BuildRpm grep #Static [ "$fileutils" = 'yes' ] && BuildRpm fileutils #Static (CFLAGS) [ "$findutils" = 'yes' ] && BuildRpm findutils #Static [ "$ftp" = 'yes' ] && BuildRpm ftp #Static [ "$hexedit" = 'yes' ] && BuildRpm hexedit #Static (needs i386-redhat-linux-gcc wrapper) [ "$iputils" = 'yes' ] && BuildRpm iputils #Static [ "$less" = 'yes' ] && BuildRpm less #Static [ "$lsof" = 'yes' ] && BuildRpm lsof #Static [ "$modutils" = 'yes' ] && BuildRpm modutils #Static [ "$nc" = 'yes' ] && BuildRpm nc #Static makefile clobbers -static, so simply setting CFLAGS doesn't work. Must use cc wrapper approach above. [ "$nettools" = 'yes' ] && BuildRpm net-tools #Static [ "$nmap" = 'yes' ] && BuildRpm nmap #Static #[ "$openssh" = 'yes' ] && BuildRpm openssh #Doesn't build. FIXME [ "$openssh" = 'yes' ] && echo 'WARNING - openssh does not build, disabling' [ "$psmisc" = 'yes' ] && BuildRpm psmisc #Static #[ "$rpm" = 'yes' ] && BuildRpm rpm #Doesn't build. FIXME [ "$rpm" = 'yes' ] && echo 'WARNING - rpm does not build, disabling' [ "$rsync" = 'yes' ] && BuildRpm rsync #Static [ "$sed" = 'yes' ] && BuildRpm sed #Static #[ "$shutils" = 'yes' ] && BuildRpm sh-utils #Doesn't build. FIXME [ "$shutils" = 'yes' ] && echo 'WARNING - sh-utils does not build, disabling' [ "$stat" = 'yes' ] && BuildRpm stat #Static [ "$strace" = 'yes' ] && BuildRpm strace #Static #[ "$stunnel" = 'yes' ] && BuildRpm stunnel #Doesn't build. FIXME [ "$stunnel" = 'yes' ] && echo 'WARNING - stunnel does not build, disabling' [ "$sysvinit" = 'yes' ] && BuildRpm SysVinit #Static [ "$tar" = 'yes' ] && BuildRpm tar #Static [ "$telnet" = 'yes' ] && BuildRpm telnet #Static [ "$textutils" = 'yes' ] && BuildRpm textutils #Static (CFLAGS) [ "$utillinux" = 'yes' ] && BuildRpm util-linux #Static [ "$wget" = 'yes' ] && BuildRpm wget #Static rm -f $BinDir/gcc rm -f $BinDir/cc rm -f $BinDir/ld rm -f $BinDir/i386-redhat-linux-gcc rm -f $BinDir/README rmdir $BinDir #Procps does not want to play nice. It refuses to compile if the above wrappers are in place. [ "$procps" = 'yes' ] && BuildRpm procps #FIXME - neither CFLAGS nor gcc/cc/ld wrapper makes it static. cd "$WorkDir/unpack" ThisDate=`date` cat >README </dev/null | sort >MANIFEST cd "$WorkDir" mkisofs -gid 0 -uid 0 -pad -r -T -o "$WorkDir/static.$MSIVer.`date +%y%m%d`.iso" unpack/ bzip2 -9 -k "$WorkDir/static.$MSIVer.`date +%y%m%d`.iso" Banner 'Done!'