home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / .kconfig next >
Text File  |  2012-08-08  |  40KB  |  1,427 lines

  1. #================
  2. # FILE          : KIWIConfig.sh
  3. #----------------
  4. # PROJECT       : OpenSUSE Build-Service
  5. # COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH, Germany
  6. #               :
  7. # AUTHOR        : Marcus Schaefer <ms@suse.de>
  8. #               :
  9. # BELONGS TO    : Operating System images
  10. #               :
  11. # DESCRIPTION   : This module contains common used functions
  12. #               : for the config.sh image scripts
  13. #               : 
  14. #               :
  15. # STATUS        : Development
  16. #----------------
  17. #======================================
  18. # work in POSIX environment
  19. #--------------------------------------
  20. export LANG=C
  21. export LC_ALL=C
  22. #======================================
  23. # suseInsertService
  24. #--------------------------------------
  25. function suseInsertService {
  26.     # /.../
  27.     # Recursively insert a service. If there is a service
  28.     # required for this service it will be inserted first
  29.     # -----
  30.     local service=$1
  31.     local result
  32.     while true;do
  33.         result=`/sbin/insserv $service 2>&1`
  34.         if [ $? = 0 ];then
  35.             echo "Service $service inserted"
  36.             break
  37.         else
  38.             result=`echo $result | head -n 1 | cut -f3 -d " "`
  39.             if [ -f /etc/init.d/$result ];then
  40.                 suseInsertService /etc/init.d/$result
  41.             else
  42.                 echo "$service: required service: $result not found...skipped"
  43.                 break
  44.             fi
  45.         fi
  46.     done
  47. }
  48.  
  49. #======================================
  50. # suseRemoveService
  51. #--------------------------------------
  52. function suseRemoveService {
  53.     # /.../
  54.     # Remove a service and its dependant services
  55.     # using insserv -r
  56.     # ----
  57.     local service=/etc/init.d/$1
  58.     while true;do
  59.         /sbin/insserv -r $service &>/dev/null
  60.         if [ $? = 0 ];then
  61.             echo "Service $service removed"
  62.             break
  63.         else
  64.             result=`/sbin/insserv -r $service 2>&1|tail -n 2|cut -f10 -d " "`
  65.             if [ -f /etc/init.d/$result ];then
  66.                 suseRemoveService $result
  67.             else
  68.                 echo "$service: $result not found...skipped"
  69.                 break
  70.             fi
  71.         fi
  72.     done
  73. }
  74.  
  75. #======================================
  76. # suseActivateServices
  77. #--------------------------------------
  78. function suseActivateServices {
  79.     # /.../
  80.     # Check all services in /etc/init.d/ and activate them
  81.     # by calling insertService
  82.     # -----
  83.     for i in /etc/init.d/*;do
  84.         if [ -x $i ] && [ -f $i ];then
  85.             echo $i | grep -q skel
  86.             if [ $? = 0 ];then
  87.                 continue
  88.             fi
  89.             suseInsertService $i
  90.         fi
  91.     done
  92. }
  93.  
  94. #======================================
  95. # suseService
  96. #--------------------------------------
  97. function suseService {
  98.     # /.../
  99.     # if a service exist then enable or disable it using chkconfig
  100.     # example : suseService apache2 on
  101.     # example : suseService apache2 off
  102.     # ----
  103.     local service=$1
  104.     local action=$2
  105.     if [ -x /etc/init.d/$i ] && [ -f /etc/init.d/$service ];then
  106.         if [ $action = on ];then
  107.             /sbin/chkconfig $service on
  108.         elif [ $action = off ];then
  109.             /sbin/chkconfig $service off
  110.         fi
  111.     fi
  112. }
  113.  
  114. #======================================
  115. # suseServiceDefaultOn
  116. #--------------------------------------
  117. function suseActivateDefaultServices {
  118.     # /.../
  119.     # Some basic services that needs to be on.
  120.     # ----
  121.     local services=(
  122.         boot.rootfsck
  123.         boot.cleanup
  124.         boot.localfs
  125.         boot.localnet
  126.         boot.clock
  127.         policykitd
  128.         dbus
  129.         consolekit
  130.         haldaemon
  131.         network
  132.         atd
  133.         syslog
  134.         cron
  135.         kbd
  136.     )
  137.     for i in "${services[@]}";do
  138.         if [ -x /etc/init.d/$i ] && [ -f /etc/init.d/$i ];then
  139.             suseInsertService $i
  140.         fi
  141.     done
  142. }
  143.  
  144. #======================================
  145. # suseCloneRunlevel
  146. #--------------------------------------
  147. function suseCloneRunlevel {
  148.     # /.../
  149.     # Clone the given runlevel to work in the same way
  150.     # as the default runlevel 3.
  151.     # ----
  152.     local clone=$1
  153.     if [ -z "$clone" ];then
  154.         echo "suseCloneRunlevel: no runlevel given... abort"
  155.         return 1
  156.     fi
  157.     if [ $clone = 3 ];then
  158.         echo "suseCloneRunlevel: can't clone myself... abort"
  159.         return 1
  160.     fi
  161.     if [ -d /etc/init.d/rc$clone.d ];then
  162.         rm -rf /etc/init.d/rc$clone.d
  163.     fi
  164.     cp -a /etc/init.d/rc3.d /etc/init.d/rc$clone.d
  165.     sed -i -e s"@#l$clone@l4@" /etc/inittab
  166. }
  167.  
  168. #======================================
  169. # suseImportBuildKey
  170. #--------------------------------------
  171. function suseImportBuildKey {
  172.     # /.../
  173.     # Add missing gpg keys to rpm database
  174.     # ----
  175.     local KEY
  176.     local TDIR=$(mktemp -d)
  177.     if [ ! -d "$TDIR" ]; then
  178.         echo "suseImportBuildKey: Failed to create temp dir"
  179.         return
  180.     fi
  181.     pushd "$TDIR"
  182.     /usr/lib/rpm/gnupg/dumpsigs /usr/lib/rpm/gnupg/suse-build-key.gpg
  183.     ls gpg-pubkey-*.asc | while read KFN; do
  184.         KEY=$(basename "$KFN" .asc)
  185.         rpm -q "$KEY" >/dev/null
  186.         [ $? -eq 0 ] && continue
  187.         echo "Importing $KEY to rpm database"
  188.         rpm --import "$KFN"
  189.     done
  190.     popd
  191.     rm -rf "$TDIR"
  192. }
  193.  
  194. #======================================
  195. # baseSetupOEMPartition
  196. #--------------------------------------
  197. function baseSetupOEMPartition {
  198.     local oemfile=/config.oempartition
  199.     if [ -e $oemfile ];then
  200.         echo "config.oempartition already defined:"
  201.         cat $oemfile
  202.         return
  203.     fi
  204.     if [ ! -z "$kiwi_oemreboot" ];then
  205.         echo "Setting up OEM_REBOOT=1"
  206.         echo "OEM_REBOOT=1" >> $oemfile
  207.     fi
  208.     if [ ! -z "$kiwi_oemswap" ];then
  209.         echo "Setting up OEM_WITHOUTSWAP=1"
  210.         echo "OEM_WITHOUTSWAP=1" >> $oemfile
  211.     fi
  212.     if [ ! -z "$kiwi_oemswapMB" ];then
  213.         echo "Setting up OEM_SWAPSIZE=$kiwi_oemswapMB"
  214.         echo "OEM_SWAPSIZE=$kiwi_oemswapMB" >> $oemfile
  215.     fi
  216.     if [ ! -z "$kiwi_oemhome" ];then
  217.         echo "Setting up OEM_WITHOUTHOME=1"
  218.         echo "OEM_WITHOUTHOME=1" >> $oemfile
  219.     fi
  220.     if [ ! -z "$kiwi_oemrootMB" ];then
  221.         echo "Setting up OEM_SYSTEMSIZE=$kiwi_oemrootMB"
  222.         echo "OEM_SYSTEMSIZE=$kiwi_oemrootMB" >> $oemfile
  223.     fi
  224.     if [ ! -z "$kiwi_oemtitle" ];then
  225.         echo "Setting up OEM_BOOT_TITLE=$kiwi_oemtitle"
  226.         echo "OEM_BOOT_TITLE=\"$kiwi_oemtitle\"" >> $oemfile
  227.     fi
  228.     if [ ! -z "$kiwi_oemkboot" ];then
  229.         echo "Setting up OEM_KIWI_INITRD=$kiwi_oemkboot"
  230.         echo "OEM_KIWI_INITRD=$kiwi_oemkboot" >> $oemfile
  231.     fi
  232.     if [ ! -z "$kiwi_oemsap" ];then
  233.         echo "Setting up OEM_SAP_INSTALL=$kiwi_oemsap"
  234.         echo "OEM_SAP_INSTALL=$kiwi_oemsap" >> $oemfile
  235.     fi
  236.     if [ ! -z "$kiwi_oemrecovery" ];then
  237.         echo "Setting up OEM_RECOVERY=1"
  238.         echo "OEM_RECOVERY=1" >> $oemfile
  239.     fi
  240.     if [ ! -z "$kiwi_oemrecoveryID" ];then
  241.         echo "Setting up OEM_RECOVERY_ID=$kiwi_oemrecoveryID"
  242.         echo "OEM_RECOVERY_ID=$kiwi_oemrecoveryID" >> $oemfile
  243.     fi
  244. }
  245.  
  246. #======================================
  247. # baseSetupUserPermissions
  248. #--------------------------------------
  249. function baseSetupUserPermissions {
  250.     while read line in;do
  251.         dir=`echo $line | cut -f6 -d:`
  252.         uid=`echo $line | cut -f3 -d:`
  253.         usern=`echo $line | cut -f1 -d:`
  254.         group=`echo $line | cut -f4 -d:`
  255.         if [ -d "$dir" ] && [ $uid -gt 200 ] && [ $usern != "nobody" ];then
  256.             group=`cat /etc/group | grep "$group" | cut -f1 -d:`
  257.             chown -c -R $usern:$group $dir/*
  258.         fi
  259.     done < /etc/passwd
  260. }
  261.  
  262. #======================================
  263. # baseSetupBoot
  264. #--------------------------------------
  265. function baseSetupBoot {
  266.     if [ -f /linuxrc ];then
  267.         cp linuxrc init
  268.         exit 0
  269.     fi
  270. }
  271.  
  272. #======================================
  273. # suseConfig
  274. #--------------------------------------
  275. function suseConfig {
  276.     #======================================
  277.     # keytable
  278.     #--------------------------------------
  279.     if [ ! -z "$kiwi_keytable" ];then
  280.         cat etc/sysconfig/keyboard |\
  281.             sed -e s"@KEYTABLE=\".*\"@KEYTABLE=\"$kiwi_keytable\"@" \
  282.         > etc/sysconfig/keyboard.new
  283.         mv etc/sysconfig/keyboard.new etc/sysconfig/keyboard
  284.     fi
  285.     #======================================
  286.     # locale
  287.     #--------------------------------------
  288.     if [ ! -z "$kiwi_language" ];then
  289.         language=$(echo $kiwi_language | cut -f1 -d,).UTF-8
  290.         cat /etc/sysconfig/language |\
  291.             sed -e s"@RC_LANG=\".*\"@RC_LANG=\"$language\"@" \
  292.         > etc/sysconfig/language.new
  293.         mv etc/sysconfig/language.new etc/sysconfig/language
  294.     fi
  295.     #======================================
  296.     # timezone
  297.     #--------------------------------------
  298.     if [ ! -z "$kiwi_timezone" ];then
  299.         if [ -f /usr/share/zoneinfo/$kiwi_timezone ];then
  300.             cp /usr/share/zoneinfo/$kiwi_timezone /etc/localtime
  301.             cat /etc/sysconfig/clock |\
  302.                 sed -e s"@TIMEZONE=\".*\"@TIMEZONE=\"$kiwi_timezone\"@" \
  303.             > etc/sysconfig/clock.new
  304.             mv etc/sysconfig/clock.new etc/sysconfig/clock
  305.             cat /etc/sysconfig/clock |\
  306.                 sed -e s"@HWCLOCK=\".*\"@HWCLOCK=\"-u\"@" \
  307.             > etc/sysconfig/clock.new
  308.             mv etc/sysconfig/clock.new etc/sysconfig/clock
  309.         else
  310.             echo "timezone: $kiwi_timezone not found"
  311.         fi
  312.     fi
  313.     #======================================
  314.     # SuSEconfig
  315.     #--------------------------------------
  316.     /sbin/SuSEconfig
  317. }
  318.  
  319. #======================================
  320. # baseGetPackagesForDeletion
  321. #--------------------------------------
  322. function baseGetPackagesForDeletion {
  323.     echo $kiwi_delete
  324. }
  325.  
  326. #======================================
  327. # baseGetProfilesUsed
  328. #--------------------------------------
  329. function baseGetProfilesUsed {
  330.     echo $kiwi_profiles
  331. }
  332.  
  333. #======================================
  334. # baseCleanMount
  335. #--------------------------------------
  336. function baseCleanMount {
  337.     umount /proc/sys/fs/binfmt_misc
  338.     umount /proc
  339.     umount /dev/pts
  340.     umount /sys
  341. }
  342.  
  343. #======================================
  344. # baseStripMans 
  345. #--------------------------------------
  346. function baseStripMans {
  347.     # /..,/
  348.     # remove all manual pages, except 
  349.     # one given as parametr
  350.     #
  351.     # params - name of keep man pages
  352.     # example baseStripMans less
  353.     # ----
  354.     local keepMans="$@"
  355.     local directories="
  356.         /opt/gnome/share/man
  357.         /usr/local/man
  358.         /usr/share/man
  359.         /opt/kde3/share/man/packages
  360.     "
  361.     find $directories -mindepth 1 -maxdepth 2 -type f 2>/dev/null |\
  362.         baseStripAndKeep ${keepMans}
  363. }
  364.  
  365. #======================================
  366. # baseStripDocs 
  367. #--------------------------------------
  368. function baseStripDocs {
  369.     # /.../
  370.     # remove all documentation, except 
  371.     # copying license copyright
  372.     # ----
  373.     local docfiles
  374.     local directories="
  375.         /opt/gnome/share/doc/packages
  376.         /usr/share/doc/packages
  377.         /opt/kde3/share/doc/packages
  378.     "
  379.     for dir in $directories; do
  380.         docfiles=$(find $dir -type f |grep -iv "copying\|license\|copyright")
  381.         rm -f $docfiles
  382.     done
  383.     rm -rf /usr/share/info
  384.     rm -rf /usr/share/man
  385. }
  386. #======================================
  387. # baseStripLocales
  388. #--------------------------------------
  389. function baseStripLocales {
  390.     local keepLocales="$@"
  391.     local directories="
  392.         /usr/lib/locale
  393.     "
  394.     find $directories -mindepth 1 -maxdepth 1 -type d 2>/dev/null |\
  395.         baseStripAndKeep ${keepLocales}
  396. }
  397.  
  398. #======================================
  399. # baseStripTranslations
  400. #--------------------------------------
  401. function baseStripTranslations {
  402.     local keepMatching="$@"
  403.     find /usr/share/locale -name "*.mo" | grep -v $keepMatching | xargs rm -f
  404. }
  405.  
  406. #======================================
  407. # baseStripInfos 
  408. #--------------------------------------
  409. function baseStripInfos {
  410.     # /.../
  411.     # remove all info files, 
  412.     # except one given as parametr
  413.     #
  414.     # params - name of keep info files
  415.     # ----
  416.     local keepInfos="$@"
  417.     local directories="
  418.         /usr/share/info
  419.     "
  420.     find $directories -mindepth 1 -maxdepth 1 -type f 2>/dev/null |\
  421.         baseStripAndKeep "${keepInfos}"
  422. }
  423. #======================================
  424. # baseStripAndKeep
  425. #--------------------------------------
  426. function baseStripAndKeep {
  427.     # /.../
  428.     # helper function for strip* functions
  429.     # read stdin lines of files to check 
  430.     # for removing
  431.     # - params - files which should be keep
  432.     # ----
  433.     local keepFiles="$@"
  434.     while read file; do
  435.             local baseFile=`/usr/bin/basename $file`
  436.             local found="no"
  437.             for keep in $keepFiles;do
  438.                     if echo $baseFile | grep -q $keep; then
  439.                             found="yes"
  440.                             break
  441.                     fi
  442.             done
  443.             if test $found = "no";then
  444.                    Rm -rf $file
  445.             fi
  446.     done
  447. }
  448. #======================================
  449. # baseStripTools
  450. #--------------------------------------
  451. function baseStripTools {
  452.     local tpath=$1
  453.     local tools=$2
  454.     for file in `find $tpath`;do
  455.         found=0
  456.         base=`/usr/bin/basename $file`
  457.         for need in $tools;do
  458.             if [ $base = $need ];then
  459.                 found=1
  460.                 break
  461.             fi
  462.         done
  463.         if [ $found = 0 ] && [ ! -d $file ];then
  464.             Rm -fv $file
  465.         fi
  466.     done
  467. }
  468. #======================================
  469. # suseStripPackager 
  470. #--------------------------------------
  471. function suseStripPackager {
  472.     # /.../ 
  473.     # remove smart o zypper packages and db 
  474.     # files. Also remove rpm package and db 
  475.     # if "-a" given
  476.     #
  477.     # params [-a]
  478.     # ----
  479.     local removerpm=falseq
  480.     if [ ! -z ${1} ] && [ $1 = "-a" ]; then
  481.         removerpm=true
  482.     fi
  483.     
  484.     #zypper#
  485.     Rpm -e --nodeps zypper libzypp satsolver-tools
  486.     Rm -rf /var/lib/zypp
  487.     
  488.     #smart
  489.     Rpm -e --nodeps smart smart-gui
  490.     Rm -rf /var/lib/smart
  491.     
  492.     if [ $removerpm = true ]; then
  493.         Rpm -e --nodeps rpm 
  494.         Rm -rf /var/lib/rpm
  495.     fi
  496. }
  497. #======================================
  498. # baseStripRPM
  499. #--------------------------------------
  500. function baseStripRPM {
  501.     # /.../
  502.     # remove rpms defined in config.xml 
  503.     # under image=delete section
  504.     # ----
  505.     for i in `baseGetPackagesForDeletion`
  506.     do
  507.         Rpm -e --nodeps $i
  508.     done
  509. }
  510. #======================================
  511. # baseSetupInPlaceSVNRepository
  512. #--------------------------------------
  513. function baseSetupInPlaceSVNRepository {
  514.     # /.../
  515.     # create an in place subversion repository for the
  516.     # specified directories. A standard call could look like this
  517.     # baseSetupInPlaceSVNRepository /etc /srv /var/log
  518.     # ----
  519.     local paths=$1
  520.     local repo=/var/adm/sys-repo
  521.     if [ ! -x /usr/bin/svn ];then
  522.         echo "subversion not installed... skipped"
  523.         return
  524.     fi
  525.     svnadmin create $repo
  526.     chmod 700 $repo
  527.     svn mkdir -m created file:///$repo/trunk
  528.     local ifss=$IFS
  529.     local subp=""
  530.     for dir in $paths;do
  531.         subp=""
  532.         IFS="/"; for n in $dir;do
  533.             if [ -z $n ];then
  534.                 continue
  535.             fi
  536.             subp="$subp/$n"
  537.             svn mkdir -m created file:///$repo/trunk/$subp
  538.         done
  539.     done
  540.     IFS=$ifss
  541.     for dir in $paths;do
  542.         chmod 700 $dir/.svn
  543.         svn add $dir/*
  544.         find $dir -name .svn | xargs chmod 700
  545.         svn ci -m initial $dir
  546.     done
  547. }
  548.  
  549. #======================================
  550. # baseSetupPlainTextGITRepository
  551. #--------------------------------------
  552. function baseSetupPlainTextGITRepository {
  553.     # /.../
  554.     # create an in place git repository of the root
  555.     # directory containing all plain/text files.
  556.     # ----
  557.     if [ ! -x /usr/bin/git ];then
  558.         echo "git not installed... skipped"
  559.         return
  560.     fi
  561.     pushd /
  562.     local ignore=""
  563.     #======================================
  564.     # directories to ignore
  565.     #--------------------------------------
  566.     local dirs="
  567.         /sys /dev /var/log /home /media /var/run /var/tmp /tmp /var/lock
  568.         /image /var/spool /var/cache /var/lib /boot /root /var/adm
  569.         /usr/share/doc /base-system /usr/lib /usr/lib64 /usr/bin /usr/sbin
  570.         /usr/share/man /proc /bin /sbin /lib /lib64 /opt
  571.         /usr/share/X11 /.git
  572.     "
  573.     #======================================
  574.     # files to ignore
  575.     #--------------------------------------
  576.     local files="
  577.         ./etc/Image* *.lock ./etc/resolv.conf *.gif *.png
  578.         *.jpg *.eps *.ps *.la *.so */lib */lib64 */doc */zoneinfo
  579.     "
  580.     #======================================
  581.     # creae .gitignore and find list
  582.     #--------------------------------------
  583.     for entry in $files;do
  584.         echo $entry >> .gitignore
  585.         if [ -z "$ignore" ];then
  586.             ignore="-wholename $entry"
  587.         else
  588.             ignore="$ignore -or -wholename $entry"
  589.         fi
  590.     done
  591.     for entry in $dirs;do
  592.         echo $entry >> .gitignore
  593.         if [ -z "$ignore" ];then
  594.             ignore="-path .$entry"
  595.         else
  596.             ignore="$ignore -or -path .$entry"
  597.         fi
  598.     done
  599.     #======================================
  600.     # init git base
  601.     #--------------------------------------
  602.     git init
  603.     #======================================
  604.     # find all text/plain files except ign
  605.     #--------------------------------------
  606.     for i in `find . \( $ignore \) -prune -o -print`;do
  607.         file=`echo $i | cut -f2 -d.`
  608.         if file -i $i | grep -q "text/*";then
  609.             git add $i
  610.         fi
  611.         if file -i $i | grep -q "application/x-shellscript";then
  612.             git add $i
  613.         fi
  614.         if file -i $i | grep -q "application/x-awk";then
  615.             git add $i
  616.         fi
  617.         if file -i $i | grep -q "application/x-c";then
  618.             git add $i
  619.         fi
  620.         if file -i $i | grep -q "application/x-c++";then
  621.             git add $i
  622.         fi
  623.         if file -i $i | grep -q "application/x-not-regular-file";then
  624.             echo $file >> .gitignore
  625.         fi
  626.         if file -i $i | grep -q "application/x-gzip";then
  627.             echo $file >> .gitignore
  628.         fi
  629.         if file -i $i | grep -q "application/x-empty";then
  630.             echo $file >> .gitignore
  631.         fi
  632.     done
  633.     #======================================
  634.     # commit the git
  635.     #--------------------------------------
  636.     git commit -m "deployed"
  637.     popd
  638. }
  639.  
  640. #======================================
  641. # baseSetupInPlaceGITRepository
  642. #--------------------------------------
  643. function baseSetupInPlaceGITRepository {
  644.     # /.../
  645.     # create an in place git repository of the root
  646.     # directory. This process may take some time and you
  647.     # may expect problems with binary data handling
  648.     # ----
  649.     if [ ! -x /usr/bin/git ];then
  650.         echo "git not installed... skipped"
  651.         return
  652.     fi
  653.     pushd /
  654.     echo /proc > .gitignore
  655.     local files="
  656.         /sys /dev /var/log /home /media /var/run /etc/Image*
  657.         /var/tmp /tmp /var/lock *.lock /image /var/spool /var/cache
  658.         /var/lib /boot /root /var/adm /base-system
  659.     "
  660.     for entry in $files;do
  661.         echo $entry >> .gitignore
  662.     done
  663.     git init && git add . && \
  664.     git commit -m "deployed"
  665.     popd
  666. }
  667. #======================================
  668. # Rm  
  669. #--------------------------------------
  670. function Rm {
  671.     # /.../
  672.     # delete files & anounce it to log
  673.     # ----
  674.     Debug "rm $@"
  675.     rm $@
  676. }
  677.  
  678. #======================================
  679. # Rpm  
  680. #--------------------------------------
  681. function Rpm {
  682.     # /.../
  683.     # all rpm function & anounce it to log
  684.     # ----
  685.     Debug "rpm $@"
  686.     rpm $@
  687. }
  688. #======================================
  689. # Echo
  690. #--------------------------------------
  691. function Echo {
  692.     # /.../
  693.     # print a message to the controling terminal
  694.     # ----
  695.     local option=""
  696.     local prefix="----->"
  697.     local optn=""
  698.     local opte=""
  699.     while getopts "bne" option;do
  700.         case $option in
  701.             b) prefix="      " ;;
  702.             n) optn="-n" ;;
  703.             e) opte="-e" ;;
  704.             *) echo "Invalid argument: $option" ;;
  705.         esac
  706.     done
  707.     shift $(($OPTIND - 1))
  708.     echo $optn $opte "$prefix $1"
  709.     OPTIND=1
  710. }
  711. #======================================
  712. # Debug
  713. #--------------------------------------
  714. function Debug {
  715.     # /.../
  716.     # print message if variable DEBUG is set to 1
  717.     # -----
  718.     if test "$DEBUG" = 1;then
  719.         echo "+++++> (caller:${FUNCNAME[1]}:${FUNCNAME[2]} )  $@"
  720.     fi
  721. }
  722. #======================================
  723. # baseSetupBusyBox
  724. #--------------------------------------
  725. function baseSetupBusyBox {
  726.     # /.../
  727.     # activates busybox if installed for all links from
  728.     # the busybox/busybox.links file - you can choose custom apps to
  729.     # be forced into busybox with the "-f" option as first parameter
  730.     # ---
  731.     # example: baseSetupBusyBox -f /bin/zcat /bin/vi
  732.     # ---
  733.     local applets=""
  734.     local force=no
  735.     local busyboxlinks=/usr/share/busybox/busybox.links
  736.     if ! rpm -q --quiet busybox; then
  737.         echo "Busybox not installed... skipped"
  738.         return 0
  739.     fi
  740.     if [ $# -gt 0 ] && [ "$1" = "-f" ]; then
  741.         force=yes
  742.         shift
  743.     fi
  744.     if [ $# -gt 0 ]; then
  745.         for i in "$@"; do
  746.             if grep -q "^$i$" "$busyboxlinks"; then 
  747.                 applets="${applets} $i"
  748.             fi
  749.         done
  750.     else
  751.         applets=`cat "$busyboxlinks"`
  752.     fi
  753.     for applet in $applets; do
  754.         if [ ! -f "$applet" ] || [ "$force" = "yes" ]; then
  755.             echo "Busybox Link: ln -sf /usr/bin/busybox $applet"
  756.             ln -sf /usr/bin/busybox "$applet"
  757.         fi
  758.     done
  759. }
  760.  
  761. #======================================
  762. # stripUnusedLibs
  763. #--------------------------------------
  764. function baseStripUnusedLibs {
  765.     # /.../
  766.     # remove libraries which are not directly linked
  767.     # against applications in the bin directories
  768.     # ----
  769.     local needlibs
  770.     local found
  771.     local dir
  772.     local lnk
  773.     local new
  774.     # /.../
  775.     # find directly used libraries, by calling ldd
  776.     # on files in *bin*
  777.     # ---
  778.     ldconfig
  779.     rm -f /tmp/needlibs
  780.     for i in /usr/bin/* /bin/* /sbin/* /usr/sbin/*;do
  781.         for n in `ldd $i 2>/dev/null`;do
  782.             if [ -e $n ];then
  783.                 echo $n >> /tmp/needlibs
  784.             fi
  785.         done
  786.     done
  787.     count=0
  788.     for i in `cat /tmp/needlibs | sort | uniq`;do
  789.         needlibs[$count]=$i
  790.         count=`expr $count + 1`
  791.         if [ -L $i ];then
  792.             dir=`dirname $i`
  793.             lnk=`readlink $i`
  794.             new=$dir/$lnk
  795.             needlibs[$count]=$new
  796.             count=`expr $count + 1`
  797.         fi
  798.     done
  799.     # /.../
  800.     # add exceptions
  801.     # ----
  802.     while [ ! -z $1 ];do
  803.         for i in /lib*/$1* /usr/lib*/$1* /usr/X11R6/lib*/$1*;do
  804.             if [ -e $i ];then
  805.                 needlibs[$count]=$i
  806.                 count=`expr $count + 1`
  807.             fi
  808.         done
  809.         shift
  810.     done
  811.     # /.../
  812.     # find unused libs and remove it, dl loaded libs
  813.     # seems not to be that important within the initrd
  814.     # ----
  815.     rm -f /tmp/needlibs
  816.     for i in \
  817.         /lib/lib* /lib64/lib* /usr/lib/lib* \
  818.         /usr/lib64/lib* /usr/X11R6/lib*/lib*
  819.     do
  820.         found=0
  821.         if [ -d $i ];then
  822.             continue
  823.         fi
  824.         for n in ${needlibs[*]};do
  825.             if [ $i = $n ];then
  826.                 found=1; break
  827.             fi
  828.         done
  829.         if [ $found -eq 0 ];then
  830.             echo "Removing: $i"
  831.             rm $i
  832.         fi
  833.     done
  834. }
  835.  
  836. #======================================
  837. # baseSysConfig
  838. #--------------------------------------
  839. function baseUpdateSysConfig {
  840.     # /.../
  841.     # update sysconfig variable contents
  842.     # ----
  843.     local FILE=$1
  844.     local VAR=$2
  845.     local VAL=$3
  846.     local args=$(echo "s'@^\($VAR=\).*\$@\1\\\"$VAL\\\"@'")
  847.     eval sed -i $args $FILE
  848. }
  849.  
  850. #======================================
  851. # suseStripInitrd
  852. #--------------------------------------
  853. function suseStripInitrd {
  854.     #==========================================
  855.     # remove unneeded files
  856.     #------------------------------------------
  857.     rm -rf `find -type d | grep .svn`
  858.     local files="
  859.         /usr/share/info /usr/share/man /usr/share/cracklib /usr/lib*/python*
  860.         /usr/lib*/perl* /usr/share/doc/packages /var/lib/rpm
  861.         /usr/lib*/rpm /var/lib/smart /opt/* /usr/include /root/.gnupg
  862.         /etc/PolicyKit /etc/sysconfig /etc/init.d /etc/profile.d /etc/skel
  863.         /etc/ssl /etc/java /etc/default /etc/cron* /etc/dbus*
  864.         /etc/pam.d* /etc/DIR_COLORS /etc/rc* /usr/share/hal /usr/share/ssl
  865.         /usr/lib*/hal /usr/lib*/*.a /usr/lib*/*.la /usr/lib*/librpm*
  866.         /usr/lib*/libpanel* /usr/lib*/libmenu* /usr/src/packages/RPMS
  867.         /usr/lib*/X11 /var/X11R6 /usr/share/X11 /etc/X11
  868.         /usr/lib*/xorg /usr/lib*/libidn* /usr/share/locale-bundle
  869.         /etc/ppp /etc/xdg /etc/NetworkManager /lib*/YaST /lib*/security
  870.         /lib*/mkinitrd/boot /lib*/mkinitrd/dev /lib*/mkinitrd/scripts
  871.         /lib*/mkinitrd/setup
  872.         /srv /var/adm /usr/lib*/engines /usr/src/packages
  873.         /usr/src/linux* /usr/local /var/log/* /usr/share/pixmaps
  874.         /usr/share/gtk-doc /var/games /opt /var/spool /var/opt
  875.         /var/cache /var/tmp /etc/rpm /etc/cups /etc/opt
  876.         /home /media /usr/lib*/lsb /usr/lib*/krb5
  877.         /usr/lib*/ldscripts /usr/lib*/getconf /usr/lib*/pwdutils
  878.         /usr/lib*/pkgconfig /usr/lib*/browser-plugins
  879.         /usr/share/omc /usr/share/tmac /usr/share/emacs /usr/share/idnkit
  880.         /usr/share/games /usr/share/PolicyKit /usr/share/tabset
  881.         /usr/share/mkinitrd /usr/share/xsessions /usr/share/pkgconfig
  882.         /usr/share/dbus-1 /usr/share/sounds /usr/share/dict /usr/share/et
  883.         /usr/share/ss /usr/share/java /usr/share/themes /usr/share/doc
  884.         /usr/share/applications /usr/share/mime /usr/share/icons
  885.         /usr/share/xml /usr/share/sgml /usr/share/fonts /usr/games
  886.         /usr/lib/mit /usr/lib/news /usr/lib/pkgconfig /usr/lib/smart
  887.         /usr/lib/browser-plugins /usr/lib/restricted /usr/x86_64-suse-linux
  888.         /etc/logrotate* /etc/susehelp* /etc/SuSEconfig /etc/permissions.d
  889.         /etc/aliases.d /etc/hal /etc/news /etc/pwdutils /etc/uucp
  890.         /etc/openldap /etc/xinetd /etc/depmod.d /etc/smart /etc/lvm
  891.         /etc/named* /etc/bash_completion* usr/share/gnupg
  892.         /lib/modules/*/kernel/drivers/net/wireless
  893.         /lib/modules/*/kernel/drivers/net/pcmcia
  894.         /lib/modules/*/kernel/drivers/net/tokenring
  895.         /lib/modules/*/kernel/drivers/net/bonding
  896.         /lib/modules/*/kernel/drivers/net/hamradio
  897.         /usr/X11R6/bin /usr/X11R6/lib/X11/locale
  898.     "
  899.     for i in $files;do
  900.         rm -rfv $i
  901.     done
  902.     #==========================================
  903.     # remove unneeded files
  904.     #------------------------------------------
  905.     if [ -d /var/cache/zypp ];then
  906.         files="
  907.             /usr/lib*/libzypp* /lib*/libgcrypt* /lib*/libgpg*
  908.             /usr/lib*/dirmngr /usr/lib*/gnupg* /usr/lib*/gpg*
  909.             /usr/lib*/libboost* /usr/lib*/libcurl* /usr/lib*/libicu*
  910.             /usr/lib*/libksba* /usr/lib*/libpth*
  911.             /var/cache/zypp /usr/lib*/zypp* /usr/share/curl
  912.             /usr/share/emacs /usr/share/gnupg
  913.             /usr/share/zypp* /var/lib/zypp* /var/log/zypper.log
  914.         "
  915.         for i in $files;do
  916.             rm -rfv $i
  917.         done
  918.     fi
  919.     #==========================================
  920.     # remove unneeded tools
  921.     #------------------------------------------
  922.     local tools="
  923.         tune2fs swapon swapoff shutdown sfdisk resize_reiserfs
  924.         reiserfsck reboot halt pivot_root modprobe modinfo rmmod
  925.         mkswap mkinitrd mkreiserfs mkfs.cramfs
  926.         losetup ldconfig insmod init ifconfig fdisk e2fsck fsck.ext2
  927.         fsck.ext3 fsck.ext4 dhcpcd mkfs.ext2 mkfs.ext3 mkfs.ext4
  928.         depmod atftpd klogconsole hwinfo xargs wc tail tac readlink
  929.         mkfifo md5sum head expr file free find env du dirname cut
  930.         column chroot atftp tr host test printf mount dd uname umount
  931.         true touch sleep sh pidof sed rmdir rm pwd ps mv mkdir kill hostname
  932.         gzip grep false df cp cat bash basename arch sort ls uniq lsmod
  933.         usleep parted mke2fs pvcreate vgcreate lvm resize2fs ln hdparm
  934.         dmesg splash fbmngplay portmap start-statd sm-notify
  935.         rpc.statd rpc.idmapd nbd-client mount.nfs mount.nfs4 eject
  936.         blockdev posbios ping killall killall5 udevcontrol udevd
  937.         udevsettle udevtrigger mknod stat path_id hwup scsi_id scsi_tur
  938.         usb_id ata_id vol_id edd_id setctsid dumpe2fs debugreiserfs
  939.         fuser udevadm blogd showconsole killproc curl tar
  940.         ldd driveready checkmedia splashy bzip2 hexdump vgremove
  941.         pvchange pvresize pvscan vgscan vgchange vgextend vgdisplay
  942.         lvchange lvresize lvextend lvcreate grub dcounter tty
  943.         dmsetup dialog awk gawk clicfs cryptsetup clear blkid fbiterm
  944.         gettext diff bc utimer cmp busybox kexec setterm
  945.     "
  946.     tools="$tools $@"
  947.     for path in /sbin /usr/sbin /usr/bin /bin;do
  948.         baseStripTools "$path" "$tools"
  949.     done
  950.     #==========================================
  951.     # remove unused libs
  952.     #------------------------------------------
  953.     baseStripUnusedLibs \
  954.         librt libutil libsysfs libnss_files libnss_compat libnsl libpng \
  955.         libfontenc libutempter libfreetype libgcc_s
  956.     #==========================================
  957.     # remove images.sh and /root
  958.     #------------------------------------------
  959.     rm -f /image/images.sh
  960.     rm -rf /root
  961.     #==========================================
  962.     # strip down configuration files
  963.     #------------------------------------------
  964.     rm -rf /tmp/*
  965.     rm -rf /tmp/.*
  966.     files="
  967.         /etc/modprobe.conf /etc/modprobe.conf.local /etc/mtab
  968.         /etc/protocols /etc/services /etc/termcap /etc/aliases
  969.         /etc/bash.bashrc /etc/filesystems /etc/ld.so.conf /etc/magic
  970.         /etc/group /etc/passwd /etc/nsswitch.conf /etc/scsi_id.config
  971.     "
  972.     for i in $files;do
  973.         if [ -e $i ];then
  974.             mv $i /tmp
  975.         fi
  976.     done
  977.     rm -f /etc/*
  978.     mv /tmp/* /etc
  979. }
  980.  
  981. #======================================
  982. # suseGFXBoot
  983. #--------------------------------------
  984. function suseGFXBoot {
  985.     local theme=$1
  986.     local loader=$2
  987.     export PATH=$PATH:/usr/sbin
  988.     if [ ! -z "$kiwi_boottheme" ];then
  989.         theme=$kiwi_boottheme
  990.     fi
  991.     if [ ! -z "$kiwi_hybrid" ];then
  992.         loader="isolinux"
  993.     fi
  994.     #======================================
  995.     # setup bootloader data
  996.     #--------------------------------------
  997.     if [ -d /usr/share/gfxboot ];then
  998.         #======================================
  999.         # create boot theme with gfxboot-devel
  1000.         #--------------------------------------
  1001.         cd /usr/share/gfxboot
  1002.         # check for new source layout
  1003.         local newlayout=
  1004.         [ -f themes/$theme/config ] && newlayout=1
  1005.         # create the archive [1]
  1006.         [ "$newlayout" ] || make -C themes/$theme prep
  1007.         make -C themes/$theme
  1008.         # find gfxboot.cfg file
  1009.         local gfxcfg=
  1010.         if [ "$newlayout" ];then
  1011.             if [ $loader = "isolinux" ];then
  1012.                 gfxcfg=themes/$theme/data-install/gfxboot.cfg
  1013.             else
  1014.                 gfxcfg=themes/$theme/data-boot/gfxboot.cfg
  1015.             fi
  1016.             if [ ! -f $gfxcfg ];then
  1017.                 gfxcfg=themes/$theme/src/gfxboot.cfg
  1018.             fi
  1019.             if [ ! -f $gfxcfg ];then
  1020.                 echo "gfxboot.cfg not found !"
  1021.                 echo "install::livecd will be skipped"
  1022.                 echo "live || boot:addopt.keytable will be skipped"
  1023.                 echo "live || boot:addopt.lang will be skipped"
  1024.                 unset gfxcfg
  1025.             fi
  1026.         fi
  1027.         # update configuration for new layout only
  1028.         if [ "$newlayout" ] && [ ! -z "$gfxcfg" ];then
  1029.             if [ $loader = "isolinux" ];then
  1030.                 # tell the bootloader about live CD setup
  1031.                 gfxboot --config-file $gfxcfg \
  1032.                     --change-config install::livecd=1
  1033.                 # tell the bootloader to hand over keytable to cmdline 
  1034.                 gfxboot --config-file $gfxcfg \
  1035.                     --change-config live::addopt.keytable=1
  1036.                 # tell the bootloader to hand over lang to cmdline
  1037.                 gfxboot --config-file $gfxcfg \
  1038.                     --change-config live::addopt.lang=1
  1039.             else
  1040.                 # tell the bootloader to hand over keytable to cmdline 
  1041.                 gfxboot --config-file $gfxcfg \
  1042.                     --change-config boot::addopt.keytable=1
  1043.                 # tell the bootloader to hand over lang to cmdline
  1044.                 gfxboot --config-file $gfxcfg \
  1045.                     --change-config boot::addopt.lang=1
  1046.                 # add selected languages to the bootloader menu
  1047.                 if [ ! -z "$kiwi_language" ];then
  1048.                     for l in `echo $kiwi_language | tr "," " "`;do
  1049.                         echo "Adding language: $l"
  1050.                         echo $l >> themes/$theme/data-boot/languages
  1051.                     done
  1052.                 fi
  1053.             fi
  1054.         fi
  1055.         # create the archive [2]
  1056.         [ "$newlayout" ] || make -C themes/$theme prep
  1057.         make -C themes/$theme
  1058.         mkdir /image/loader
  1059.         local gfximage=
  1060.         local bootimage=
  1061.         if [ "$newlayout" ] ; then
  1062.             gfximage=themes/$theme/bootlogo
  1063.             bootimage=themes/$theme/message
  1064.         else
  1065.             gfximage=themes/$theme/install/bootlogo
  1066.             bootimage=themes/$theme/boot/message
  1067.         fi
  1068.         if [ $loader = "isolinux" ];then
  1069.             # isolinux boot data...
  1070.             cp $gfximage /image/loader
  1071.             bin/unpack_bootlogo /image/loader
  1072.         else
  1073.             # boot loader graphics image file...
  1074.             if [ ! -z "$kiwi_language" ];then
  1075.                 msgdir=/image/loader/message.dir
  1076.                 mkdir $msgdir && mv $bootimage $msgdir
  1077.                 (cd $msgdir && cat message | cpio -i && rm -f message)
  1078.                 if [ "$newlayout" ];then
  1079.                     for l in `echo $kiwi_language | tr "," " "`;do
  1080.                         l=$(echo $l | cut -f1 -d_)
  1081.                         cp themes/$theme/po/$l*.tr $msgdir
  1082.                         cp themes/$theme/help-boot/$l*.hlp $msgdir
  1083.                     done
  1084.                 else
  1085.                     for l in `echo $kiwi_language | tr "," " "`;do
  1086.                         l=$(echo $l | cut -f1 -d_)
  1087.                         cp themes/$theme/boot/$l*.tr  $msgdir
  1088.                         cp themes/$theme/boot/$l*.hlp $msgdir
  1089.                         echo $l >> $msgdir/languages
  1090.                     done
  1091.                 fi
  1092.                 (cd $msgdir && find | cpio --quiet -o > ../message)
  1093.                 rm -rf $msgdir
  1094.             else
  1095.                 mv $bootimage /image/loader
  1096.             fi
  1097.         fi
  1098.         make -C themes/$theme clean
  1099.     elif [ -f /etc/bootsplash/themes/$theme/bootloader/message ];then
  1100.         #======================================
  1101.         # use boot theme from gfxboot-branding
  1102.         #--------------------------------------
  1103.         echo "gfxboot devel not installed, custom branding skipped !"
  1104.         echo "using gfxboot branding package"
  1105.         mkdir /image/loader
  1106.         if [ $loader = "isolinux" ];then
  1107.             # isolinux boot data...
  1108.             mv /etc/bootsplash/themes/$theme/cdrom/* /image/loader
  1109.             local gfxcfg=/image/loader/gfxboot.cfg
  1110.             # tell the bootloader about live CD setup
  1111.             gfxboot --config-file $gfxcfg \
  1112.                 --change-config install::livecd=1
  1113.             # tell the bootloader to hand over keytable to cmdline 
  1114.             gfxboot --config-file $gfxcfg \
  1115.                 --change-config live::addopt.keytable=1
  1116.             # tell the bootloader to hand over lang to cmdline
  1117.             gfxboot --config-file $gfxcfg \
  1118.                 --change-config live::addopt.lang=1
  1119.         else
  1120.             # boot loader graphics image file...
  1121.             mv /etc/bootsplash/themes/$theme/bootloader/message /image/loader
  1122.             local archive=/image/loader/message
  1123.             # tell the bootloader to hand over keytable to cmdline 
  1124.             gfxboot --archive $archive \
  1125.                 --change-config boot::addopt.keytable=1
  1126.             # tell the bootloader to hand over lang to cmdline
  1127.             gfxboot --archive $archive \
  1128.                 --change-config boot::addopt.lang=1
  1129.             # add selected languages to the bootloader menu
  1130.             if [ ! -z "$kiwi_language" ];then
  1131.                 gfxboot --archive $archive --add-language \
  1132.                     $(echo $kiwi_language | tr "," " ") --default-language en_US
  1133.             fi
  1134.         fi
  1135.     else
  1136.         #======================================
  1137.         # no graphics boot possible
  1138.         #--------------------------------------
  1139.         echo "gfxboot devel not installed"
  1140.         echo "gfxboot branding not installed"
  1141.         echo "graphics boot skipped !"
  1142.         mkdir /image/loader
  1143.     fi
  1144.     #======================================
  1145.     # copy bootloader binaries of required
  1146.     #--------------------------------------
  1147.     if [ $loader = "isolinux" ];then
  1148.         # isolinux boot code...
  1149.         mv /usr/share/syslinux/isolinux.bin /image/loader
  1150.         if [ -f "/usr/share/syslinux/gfxboot.com" ];then
  1151.             mv /usr/share/syslinux/gfxboot.com /image/loader
  1152.         fi
  1153.         if [ -f "/usr/share/syslinux/mboot.c32" ];then
  1154.             mv /usr/share/syslinux/mboot.c32 /image/loader
  1155.         fi
  1156.         if [ -f "/boot/memtest.bin" ];then 
  1157.             mv /boot/memtest.bin /image/loader/memtest
  1158.         fi
  1159.     else
  1160.         # boot loader binary part of MBR
  1161.         :
  1162.     fi
  1163.     #======================================
  1164.     # create splash screen
  1165.     #--------------------------------------
  1166.     if [ ! -f /sbin/splash ];then
  1167.         echo "bootsplash not installed... skipped"
  1168.         return
  1169.     fi
  1170.     sname[0]="08000600.spl"
  1171.     sname[1]="10240768.spl"
  1172.     sname[2]="12801024.spl"
  1173.     index=0
  1174.     if [ ! -d /etc/bootsplash/themes/$theme ];then
  1175.         theme="SuSE-$theme"
  1176.     fi
  1177.     if [ ! -d /etc/bootsplash/themes/$theme ];then
  1178.         echo "bootsplash branding not installed... skipped"
  1179.         return
  1180.     fi
  1181.     mkdir -p /image/loader/branding
  1182.     cp /etc/bootsplash/themes/$theme/images/logo.mng  /image/loader/branding
  1183.     cp /etc/bootsplash/themes/$theme/images/logov.mng /image/loader/branding
  1184.     for cfg in 800x600 1024x768 1280x1024;do
  1185.         cp /etc/bootsplash/themes/$theme/images/bootsplash-$cfg.jpg \
  1186.         /image/loader/branding
  1187.         cp /etc/bootsplash/themes/$theme/images/silent-$cfg.jpg \
  1188.         /image/loader/branding
  1189.         cp /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg \
  1190.         /image/loader/branding
  1191.     done
  1192.     mkdir -p /image/loader/animations
  1193.     cp /etc/bootsplash/themes/$theme/animations/* \
  1194.         /image/loader/animations &>/dev/null
  1195.     for cfg in 800x600 1024x768 1280x1024;do
  1196.         /sbin/splash -s -c -f \
  1197.             /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg |\
  1198.             gzip -9c \
  1199.         > /image/loader/${sname[$index]}
  1200.         tdir=/image/loader/xxx
  1201.         mkdir $tdir
  1202.         cp -a --parents /etc/bootsplash/themes/$theme/config/*-$cfg.* $tdir
  1203.         cp -a --parents /etc/bootsplash/themes/$theme/images/*-$cfg.* $tdir
  1204.         ln -s /etc/bootsplash/themes/$theme/config/bootsplash-$cfg.cfg \
  1205.                 $tdir/etc/splash.cfg
  1206.         pushd $tdir
  1207.         chmod -R a+rX .
  1208.         find | cpio --quiet -o -H newc |\
  1209.             gzip -9 >> /image/loader/${sname[$index]}
  1210.         popd
  1211.         rm -rf $tdir
  1212.         index=`expr $index + 1`
  1213.     done
  1214. }
  1215.  
  1216. #======================================
  1217. # suseSetupProductInformation
  1218. #--------------------------------------
  1219. function suseSetupProductInformation {
  1220.     # /.../
  1221.     # This function will use zypper to search for the installed
  1222.     # product and prepare the product specific information
  1223.     # for YaST
  1224.     # ----
  1225.     if [ ! -x /usr/bin/zypper ];then
  1226.         echo "zypper not installed... skipped"
  1227.         return
  1228.     fi
  1229.     local zypper="zypper --non-interactive --no-gpg-checks"
  1230.     local product=$($zypper search -t product | grep product | head -n 1)
  1231.     local p_alias=$(echo $product | cut -f4 -d'|')
  1232.     local p_name=$(echo $product | cut -f 4-5 -d'|' | tr '|' '-' | tr -d " ")
  1233.     p_alias=$(echo $p_alias)
  1234.     p_name=$(echo $p_name)
  1235.     echo "Installing product information for $p_name"
  1236.     $zypper install -t product $p_alias
  1237. }
  1238.  
  1239. #======================================
  1240. # suseStripKernel
  1241. #--------------------------------------
  1242. function suseStripKernel {
  1243.     # /.../
  1244.     # this function will strip the kernel according to the
  1245.     # drivers information in the xml descr. It also will create
  1246.     # the vmlinux.gz and vmlinuz files which are required
  1247.     # for the kernel extraction in case of kiwi boot images
  1248.     # ----
  1249.     local ifss=$IFS
  1250.     local kversion
  1251.     local i
  1252.     local d
  1253.     local mod
  1254.     local stripdir
  1255.     local kdata
  1256.     for kversion in /lib/modules/*;do
  1257.         IFS="
  1258.         "
  1259.         if [ ! -d "$kversion" ];then
  1260.             IFS=$ifss
  1261.             continue
  1262.         fi
  1263.         if [ -x /bin/rpm ];then
  1264.             kdata=$(rpm -qf $kversion)
  1265.         else
  1266.             kdata=$kversion
  1267.         fi
  1268.         for p in $kdata;do
  1269.             #==========================================
  1270.             # get kernel VERSION information
  1271.             #------------------------------------------
  1272.             if [ ! $? = 0 ];then
  1273.                 # not in a package...
  1274.                 IFS=$ifss
  1275.                 continue
  1276.             fi
  1277.             if echo $p | grep -q "\-kmp\-";then  
  1278.                 # a kernel module package...
  1279.                 IFS=$ifss
  1280.                 continue
  1281.             fi
  1282.             if echo $p | grep -q "\-source\-";then
  1283.                 # a kernel source package...
  1284.                 IFS=$ifss
  1285.                 continue
  1286.             fi
  1287.             VERSION=$(/usr/bin/basename $kversion)
  1288.             echo "Stripping kernel $p: Image [$kiwi_iname]..."
  1289.             #==========================================
  1290.             # run depmod, deps should be up to date
  1291.             #------------------------------------------
  1292.             if [ ! -f /boot/System.map-$VERSION ];then
  1293.                 # no system map for kernel
  1294.                 echo "no system map for kernel: $p found... skip it"
  1295.                 IFS=$ifss
  1296.                 continue
  1297.             fi
  1298.             /sbin/depmod -F /boot/System.map-$VERSION $VERSION
  1299.             #==========================================
  1300.             # check for modules.order and backup it
  1301.             #------------------------------------------
  1302.             if [ -f $kversion/modules.order ];then
  1303.                 mv $kversion/modules.order /tmp
  1304.             fi
  1305.             #==========================================
  1306.             # strip the modules but take care for deps
  1307.             #------------------------------------------
  1308.             stripdir=/tmp/stripped_modules
  1309.             IFS=,
  1310.             for mod in \
  1311.                 $kiwi_usbdrivers $kiwi_scsidrivers \
  1312.                 $kiwi_netdrivers $kiwi_drivers
  1313.             do
  1314.                 local path=`/usr/bin/dirname $mod`
  1315.                 local base=`/usr/bin/basename $mod`
  1316.                 for d in kernel updates weak-updates;do
  1317.                     if [ "$base" = "*" ];then
  1318.                         if test -d $kversion/$d/$path ; then
  1319.                             mkdir -pv $stripdir$kversion/$d/$path
  1320.                             cp -avl $kversion/$d/$path/* \
  1321.                                 $stripdir$kversion/$d/$path
  1322.                         fi
  1323.                     else
  1324.                         if test -f $kversion/$d/$mod ; then
  1325.                             mkdir -pv $stripdir$kversion/$d/$path
  1326.                             cp -avl $kversion/$d/$mod \
  1327.                                 $stripdir$kversion/$d/$mod
  1328.                         elif test -L $kversion/$d/$base ; then
  1329.                             mkdir -pv $stripdir$kversion/$d
  1330.                             cp -avl $kversion/$d/$base \
  1331.                                 $stripdir$kversion/$d
  1332.                         elif test -f $kversion/$d/$base ; then
  1333.                             mkdir -pv $stripdir$kversion/$d
  1334.                             cp -avl $kversion/$d/$base \
  1335.                                 $stripdir$kversion/$d
  1336.                         fi
  1337.                     fi
  1338.                 done
  1339.             done
  1340.             IFS=$ifss
  1341.             for mod in `find $stripdir -name "*.ko"`;do
  1342.                 d=`/usr/bin/basename $mod`
  1343.                 i=`/sbin/modprobe \
  1344.                     --set-version $VERSION \
  1345.                     --ignore-install \
  1346.                     --show-depends \
  1347.                     ${d%.ko} | sed -ne 's:.*insmod /\?::p'`
  1348.                 for d in $i; do
  1349.                     case "$d" in
  1350.                         *=*) ;;
  1351.                         *)
  1352.                         if ! test -f $stripdir/$d ; then
  1353.                             echo "Fixing kernel module Dependency: $d"
  1354.                             mkdir -vp `/usr/bin/dirname $stripdir/$d`
  1355.                             cp -flav $d $stripdir/$d
  1356.                         fi
  1357.                         ;;
  1358.                     esac
  1359.                 done
  1360.             done
  1361.             rm -rf $kversion
  1362.             mv -v $stripdir/$kversion $kversion
  1363.             rm -rf $stripdir
  1364.             if [ -f /tmp/modules.order ];then
  1365.                 mv /tmp/modules.order $kversion
  1366.             fi
  1367.             #==========================================
  1368.             # run depmod
  1369.             #------------------------------------------
  1370.             /sbin/depmod -F /boot/System.map-$VERSION $VERSION
  1371.             #==========================================
  1372.             # create common kernel files, last wins !
  1373.             #------------------------------------------
  1374.             pushd /boot
  1375.             if [ -f vmlinux-$VERSION.gz ];then
  1376.                 mv vmlinux-$VERSION.gz vmlinux.gz
  1377.                 mv vmlinuz-$VERSION vmlinuz
  1378.             elif [ -f vmlinuz-$VERSION ];then
  1379.                 mv vmlinuz-$VERSION vmlinuz
  1380.             else
  1381.                 rm -f vmlinux
  1382.                 cp vmlinux-$VERSION vmlinux
  1383.                 mv vmlinux-$VERSION vmlinuz
  1384.             fi
  1385.             popd
  1386.         done
  1387.     done
  1388. }
  1389.  
  1390. #======================================
  1391. # suseSetupProduct
  1392. #--------------------------------------
  1393. function suseSetupProduct {
  1394.     # /.../
  1395.     # This function will create the /etc/products.d/baseproduct
  1396.     # link pointing to the product referenced by either
  1397.     # the /etc/SuSE-brand file or the latest .prod file
  1398.     # available in /etc/products.d
  1399.     # ----
  1400.     local prod=undef
  1401.     if [ -f /etc/SuSE-brand ];then
  1402.         prod=$(head /etc/SuSE-brand -n 1)
  1403.     fi
  1404.     pushd /etc/products.d
  1405.     if [ -f $prod.prod ];then
  1406.         ln -sf $prod.prod baseproduct
  1407.     else
  1408.         prod=$(ls -1t *.prod 2>/dev/null | tail -n 1)
  1409.         if [ -f $prod ];then
  1410.             ln -sf $prod baseproduct
  1411.         fi
  1412.     fi
  1413.     popd
  1414. }
  1415.  
  1416. #======================================
  1417. # suseRemovePackagesMarkedForDeletion
  1418. #--------------------------------------
  1419. function suseRemovePackagesMarkedForDeletion {
  1420.     # /.../
  1421.     # This function removes all packages which are
  1422.     # added into the <packages type="delete"> section
  1423.     # ----
  1424.     rpm -e --nodeps \
  1425.         $(rpm -q `baseGetPackagesForDeletion` | grep -v "is not installed")
  1426. }
  1427.