Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

Stuff
Monday, December 3rd, 2007 at 10:36:40pm UTC 

  1. #!/bin/bash
  2. buildpkgver=1.4.0
  3. startdir="$(pwd)"
  4.  
  5. err()
  6. {
  7.         echo "$1"
  8.         exit 1
  9. }
  10.  
  11. help_msg()
  12. {
  13. cat <<EOHELP
  14.  
  15. Usage: buildpkg [OPTIONS] [prototype]
  16.  
  17. OPTIONS:
  18.  
  19.   no option                   creates build-\$pkgname.sh
  20.  
  21.   -g, --generate [prototype]  copy a ZENBUILD prototype
  22.  
  23.   -c, --clean-dirs            remove pkg and src directories
  24.  
  25.   -x, --execute               creates build-\$pkgname.sh, then executes it
  26.  
  27.   -X, --x-and-clean           combines -x and -c together
  28.  
  29.   -v, --version               outputs the version
  30.  
  31.   -h, --help                  display this message
  32.  
  33. Report bugs or suggestions to [email protected]
  34.  
  35. EOHELP
  36. exit 1
  37. }
  38.  
  39. generate_zenbuild() {
  40.         EXTENSION="$1"
  41.         ACTUALFILE=ZENBUILD
  42.         [ -n "$EXTENSION" ] && ACTUALFILE+=".$EXTENSION"
  43.         TEMPLATE="/etc/buildpkg/$ACTUALFILE"
  44.         if [ ! -f "$TEMPLATE" ]; then
  45.                 err "No $TEMPLATE found in /etc/buildpkg, exiting."
  46.         elif [ -f "$startdir/ZENBUILD" ]; then
  47.                 echo "There is already a ZENBUILD in the current directory."
  48.                 echo -n "Generate ZENBUILD and overwrite it anyways? [y/n] "
  49.                 while :; do #infinitely
  50.                         read answer
  51.                         case $answer in
  52.                                 ''|'y'|'Y'|'yes'|'YES')
  53.                                         rm $startdir/ZENBUILD
  54.                                         cp $TEMPLATE $startdir/ZENBUILD
  55.                                         echo "ZENBUILD created."
  56.                                         exit
  57.                                         ;;
  58.                                 'n'|'N'|'no'|'NO')
  59.                                         echo "Not creating ZENBUILD, exiting."
  60.                                         exit
  61.                                         ;;
  62.                                 *)
  63.                                         echo -n "Incorrect response, reply y or n: "
  64.                         esac
  65.                 done
  66.         else
  67.                 cp $TEMPLATE $startdir/ZENBUILD
  68.                 exit
  69.         fi
  70. }
  71.  
  72. #Set Options
  73. unset EXECUTE
  74. unset GENERATE
  75. unset REMOVEDIRS
  76. SHORTOPTS="hXxg::cv"
  77. LONGOPTS="help,version,x-and-clean,execute,generate::,clean-dirs"
  78. # Note that we use `"[email protected]"' to let each command-line parameter expand to a
  79. # separate word. The quotes around `[email protected]' are essential!
  80. # We need TEMP as the `eval set --' would nuke the return value of getopt.
  81. #TEMP=`getopt -o $SHORTOPTS --long $LONGOPTS -n build --"[email protected]"`
  82. TEMP=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "[email protected]")
  83.  
  84. # Note the quotes around `$TEMP': they are essential!
  85. eval set -- "$TEMP"
  86. while [ $# -gt 0 ]; do
  87.         case $1 in
  88.                 '-h'|'--help')
  89.                         help_msg
  90.                         exit
  91.                         ;;
  92.                 '-X'|'--x-and-clean')
  93.                         EXECUTE='1'
  94.                         REMOVEDIRS='1'
  95.                         ;;
  96.                 '-x'|'--execute')
  97.                         EXECUTE='1'
  98.                         ;;
  99.                 '-g'|'--generate')
  100.                         GENERATE='1'
  101.                         generate_zenbuild "$2"
  102.                         exit
  103.                         ;;
  104.                 '-c'|'--clean-dirs')
  105.                         REMOVEDIRS='1'
  106.                         ;;
  107.                 '-v'|'--version')
  108.                         echo "buildpkg version: $buildpkgver"
  109.                         exit
  110.                         ;;
  111.                 '')
  112.                         ;;
  113.                 --)
  114.                         break
  115.                         ;;
  116.                 *)
  117.                         err "Incorrect usage, see buildpkg --help"
  118.         esac
  119.         shift
  120. done
  121. if [ -f "${startdir}/ZENBUILD" ]; then
  122.         unset pkgname pkgver pkgrel zenver arch source extradepends options
  123.         unset dotnew url CFLAGS CXFLAGS slackdesc doinst build docs
  124.         . ${startdir}/ZENBUILD
  125. else
  126.         err "No ZENBUILD found in directory, see buildpkg --help"
  127. fi
  128.  
  129. ##################Sanity Tests Begin######################################
  130. #Check that variables exist
  131. for VAR in pkgname pkgver pkgrel zenver arch slackdesc; do
  132.         [[ ! "${!VAR}" ]] &&
  133.                 err "variable \"${VAR}\" is not set"
  134. done
  135.  
  136. #special source check
  137. if [[ ! "$source" ]]; then
  138.         echo "source should be filled except in rare occassions (cvs,svn,etc.)"
  139. fi
  140.  
  141. #does build() exist?
  142. [[ ! "$(grep '^build\(\)' ${startdir}/ZENBUILD)" ]] &&
  143.         err "No build() function found"
  144.  
  145. #check that variables are sane
  146. [[ "$(echo $pkgver | grep -E '\-|_')" ]] &&
  147.         err "No dashes or underscores allowed in pkgver"
  148.  
  149. [[ "${slackdesc[10]}" ]] &&
  150.         err "No more than 10 lines allowed in slackdesc"
  151.  
  152. if [ "$(grep -e "^#Maintainer: Name <[email protected]>" $startdir/ZENBUILD)" ]; then
  153.                 err "Maintainer isn't set in ZENBUILD, exiting"
  154. fi
  155.  
  156. #Check for numerous commentaries
  157. NUMCOM=$(grep -e "^#[a-zA-Z]*=[a-zA-Z]*" ${startdir}/ZENBUILD | wc -l)
  158. [[ $NUMCOM -ge 2 ]] && echo "WARNING: You appear to have too many commented variables, you should look into it."
  159.  
  160. #source sanity
  161. for SOURCES in "${source[@]}"; do
  162.         if [ ! -f "$(basename $SOURCES)" ]; then
  163.                 protocol=$(echo $SOURCES | sed 's|:.*||')
  164.                 if [ "$protocol" = "http" -o "$protocol" = "https" -o "$protocol" = "ftp" ]; then
  165.                         echo -e "\nDownloading $(basename $SOURCES)\n"
  166.                         wget $SOURCES
  167.                         if [ ! "$?" == "0" ]; then
  168.                                 echo "Download failed"
  169.                                 exit 2
  170.                         fi
  171.                 else
  172.                         err "$SOURCES does not appear to be a url nor is it in the directory"
  173.                 fi
  174.         else
  175.                 echo "$(basename $SOURCES) found in current directory"
  176.         fi
  177. done
  178.  
  179. #slackdesc sanity
  180. for ((LINE=0 ; LINE < 10 ; LINE++)); do
  181.         REALLINE=$(expr $LINE + 1)
  182.         if [ "${#slackdesc[$LINE]}" -gt "70" ] ; then
  183.                 let "extrachar=${#slackdesc[$LINE]}-70"
  184.                 err "Line ${REALLINE}: '${slackdesc[$LINE]}'
  185. is greater than 70 characters, make it $extrachar characters shorter."
  186.         fi
  187. done
  188.  
  189. #clean dotnew
  190. if [[ "$dotnew" ]]; then
  191.         NUM='0'
  192.         for dot in ${dotnew[@]}; do
  193.                 if [ "${dotnew[$NUM]:0:1}" == "/" ]; then
  194.                         dotnew[$NUM]=${dotnew[$NUM]:1}
  195.                 fi
  196.                 let "NUM++"
  197.         done
  198. fi
  199.  
  200. #########Sanity Tests End########################################
  201.  
  202. #options=()
  203. if [ -n "$options" ]; then
  204.         unset NOEXTRACT
  205.         unset NOREQUIREDBUILDER
  206.         unset REQUIREDBUILDERFLATDEPS
  207.         unset NOSTRIP
  208.         unset KEEPDEPFILE
  209.         for opts in ${options[@]}; do
  210.                 case $opts in
  211.                         noextract)
  212.                                 echo "Setting option noextract"
  213.                                 NOEXTRACT='1'
  214.                                 ;;
  215.                         norequiredbuilder)
  216.                                 echo "Setting option norequiredbuilder"
  217.                                 NOREQUIREDBUILDER='1'
  218.                                 ;;
  219.                         nostrip)
  220.                                 echo "Setting option nostrip"
  221.                                 NOSTRIP='1'
  222.                                 ;;
  223.                         requiredbuilderflatdeps)
  224.                                 echo "Setting option requiredbuilderflatdeps"
  225.                                 REQUIREDBUILDERFLATDEPS='1'
  226.                                 ;;
  227.                         keepdepfile)
  228.                                 echo "Setting option keepdepfile"
  229.                                 KEEPDEPFILE='1'
  230.                                 ;;
  231.                         *)
  232.                                 echo "$opts is not a correct option, exiting."
  233.                                 exit 2
  234.                                 ;;
  235.                 esac
  236.         done
  237. fi
  238.  
  239. #######Generate Build Script#####################################
  240. cat <<EOA > ${startdir}/build-${pkgname}.sh
  241. #!/bin/bash
  242. #Automatically Created by buildpkg $buildpkgver
  243. EOA
  244. if [ "$(grep -e "^#Maintainer" $startdir/ZENBUILD)" ]; then
  245.         grep -e "^#Maintainer" $startdir/ZENBUILD >> $startdir/build-$pkgname.sh
  246. fi
  247. [[ "$(grep -e "^#Former Maintainer(s)" $startdir/ZENBUILD)" ]] &&
  248.         grep -e "^#Former Maintainer(s)" $startdir/ZENBUILD >> $startdir/build-$pkgname.sh
  249. [[ "$url" ]] && echo "#url: $url" >> $startdir/build-$pkgname.sh
  250. [[ "$KEEPDEPFILE" ]] && echo "KEEPDEPFILE='1'" >> $startdir/build-$pkgname.sh
  251.  
  252. cat <<"EOREDUNDANT" >> $startdir/build-$pkgname.sh
  253.  
  254. ######Begin Redundant Code######################################
  255. check_for_root() {
  256.         if [ "$UID" != "0" ]; then
  257.                 echo "You need to be root"
  258.                 exit 1
  259.         fi
  260. }
  261.  
  262. clean_dirs () {
  263.         for COMPLETED in src pkg; do
  264.                 if [ -e $COMPLETED ]; then
  265.                         rm -rf $COMPLETED
  266.                 fi
  267.         done
  268. }
  269.  
  270. clean_old_builds () {
  271.         for COMPLETED in $package.{tgz,md5,dep}; do
  272.                 if [ "$KEEPDEPFILE" = "1" ] && [ $COMPLETED = $package.dep ]; then
  273.                         continue
  274.                 elif [ -e $COMPLETED ]; then
  275.                         rm -rf $COMPLETED
  276.                 fi
  277.         done
  278.         clean_dirs
  279. }
  280.  
  281. set_pre_permissions() {
  282.         cd $startdir/src
  283.         find . -perm 664 -exec chmod 644 {} \;
  284.         find . -perm 600 -exec chmod 644 {} \;
  285.         find . -perm 444 -exec chmod 644 {} \;
  286.         find . -perm 400 -exec chmod 644 {} \;
  287.         find . -perm 440 -exec chmod 644 {} \;
  288.         find . -perm 777 -exec chmod 755 {} \;
  289.         find . -perm 775 -exec chmod 755 {} \;
  290.         find . -perm 511 -exec chmod 755 {} \;
  291.         find . -perm 711 -exec chmod 755 {} \;
  292.         find . -perm 555 -exec chmod 755 {} \;
  293. }
  294.  
  295.  
  296. check_for_menu_compliance() {
  297.         if [ -d "$startdir/pkg/usr/share/applications" ]; then
  298.                 cd $startdir/pkg/usr/share/applications
  299.                 for desktop in *.desktop; do
  300.                         Icon=$(grep -e "^Icon=" $desktop | sed 's/Icon=//')
  301.                         if [[ "$Icon" ]]; then
  302.                                 if [ ! "$Icon" == "${Icon%.*}" ]; then
  303.                                         sed '/Icon/s/\..*$//' -i $desktop
  304.                                         Icon=$(grep -e "^Icon=" $desktop | sed 's/Icon=//')
  305.                                 fi
  306.                                 if [ -d "$startdir/pkg/usr/share/pixmaps" ]; then
  307.                                         cd $startdir/pkg/usr/share/pixmaps
  308.                                         for pixmaps in *; do
  309.                                                 [ -d $pixmaps ] && continue
  310.                                                 [ ! "${pixmaps##*.}" == "png" -a ! "${pixmaps##*.}" == "svg" ] && continue
  311.                                                 if [ "${pixmaps%.*}" == "$Icon" ]; then
  312.                                                         DIR=$(file $pixmaps | awk -F, '{print $2}' | sed 's/ //g')
  313.                                                         [ o"$DIR" == "o" ] && DIR="scalable"
  314.                                                         mkdir -p $startdir/pkg/usr/share/icons/hicolor/$DIR/apps
  315.                                                         mv $pixmaps $startdir/pkg/usr/share/icons/hicolor/$DIR/apps
  316.                                                         if [[ ! "$(ls $startdir/pkg/usr/share/pixmaps)" ]]; then
  317.                                                                 rm -rf $startdir/pkg/usr/share/pixmaps
  318.                                                         fi
  319.                                                 fi
  320.                                         done
  321.                                 fi
  322.                                 if [ -d "$startdir/pkg/usr/share/icons" ]; then
  323.                                         cd $startdir/pkg/usr/share/icons
  324.                                         for icons in *; do
  325.                                                 if [ "${icons%.*}" == "$Icon" ]; then
  326.                                                         [ ! "${pixmaps##*.}" == "png" -a ! "${pixmaps##*.}" == "svg" ] && continue
  327.                                                         DIR=$(file $icons | awk -F, '{print $2}' | sed 's/ //g')
  328.                                                         [ o"$DIR" == "o" ] && DIR="scalable"
  329.                                                         mkdir -p $startdir/pkg/usr/share/icons/hicolor/$DIR/apps
  330.                                                         mv $icons $startdir/pkg/usr/share/icons/hicolor/$DIR/apps
  331.                                                 fi
  332.                                         done
  333.                                 fi
  334.                         fi
  335.                 done
  336.         fi
  337. }
  338.  
  339.  
  340. gzip_man_and_info_pages() {
  341.         for DOCS in man info; do
  342.                 if [ -d "$startdir/pkg/usr/share/$DOCS" ]; then
  343.                         mv $startdir/pkg/usr/share/$DOCS $startdir/pkg/usr/$DOCS
  344.                         if [[ ! "$(ls $startdir/pkg/usr/share)" ]]; then
  345.                                 rm -rf $startdir/pkg/usr/share
  346.                         fi
  347.                 fi
  348.                 if [ -d "$startdir/pkg/usr/$DOCS" ]; then
  349.                         # I've never seen symlinks in info pages....
  350.                         if [ "$DOCS" == "man" ]; then
  351.                                 (cd $startdir/pkg/usr/$DOCS
  352.                                 for manpagedir in $(find . -type d -name "man*" 2> /dev/null) ; do
  353.                                         ( cd $manpagedir
  354.                                         for eachpage in $( find . -type l -maxdepth 1 2> /dev/null) ; do
  355.                                                 ln -s $( readlink $eachpage ).gz $eachpage.gz
  356.                                                 rm $eachpage
  357.                                         done )
  358.                                 done)
  359.                         fi
  360.                         find $startdir/pkg/usr/$DOCS -type f -exec gzip -9 '{}' \;
  361.                 fi
  362.         done
  363. }
  364.  
  365. set_post_permissions() {
  366.         for DIRS in usr/share/icons usr/doc; do
  367.                 if [ -d "$startdir/pkg/$DIRS" ]; then
  368.                         if [ "$DIRS" == "usr/doc" ]; then
  369.                                 find $startdir/pkg/$DIRS -type f -exec chmod 644 {} \;
  370.                                 find $startdir/pkg/$DIRS -type d -exec chmod 755 {} \;
  371.                         fi
  372.                 fi
  373.                 [ -d $startdir/pkg/$DIRS ] && chown root:root -R $startdir/pkg/$DIRS
  374.         done
  375.         [ -d $startdir/pkg/usr/bin ] && find $startdir/pkg/usr/bin -user root -group bin -exec chown root:root {} \;
  376. }
  377.  
  378. copy_build_script() {
  379.         mkdir -p $startdir/pkg/usr/src/$pkgname-$pkgver/
  380.         cp $startdir/build-$pkgname.sh $startdir/pkg/usr/src/$pkgname-$pkgver/build-$pkgname.sh
  381.         [ -f $startdir/ZENBUILD ] && cp $startdir/ZENBUILD $startdir/pkg/usr/src/$pkgname-$pkgver/ZENBUILD
  382. }
  383.  
  384. create_package() {
  385.         cd $startdir/pkg
  386.         /sbin/makepkg -l y -c n $startdir/$package.tgz
  387.         cd $startdir
  388.         md5sum $package.tgz > $startdir/$package.md5
  389. }
  390.  
  391. EOREDUNDANT
  392.  
  393. if [ -z "$NOSTRIP" ]; then
  394. cat <<"EOREDUNDANT1" >> $startdir/build-$pkgname.sh
  395. strip_binaries() {
  396.         cd $startdir/pkg
  397.         find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | \
  398.         xargs strip --strip-unneeded 2> /dev/null
  399.         find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | \
  400.         xargs strip --strip-unneeded 2> /dev/null
  401. }
  402. EOREDUNDANT1
  403. fi
  404.  
  405. cat <<"EOREDUNDANT2" >> $startdir/build-$pkgname.sh
  406. #########End Redundant Code#####################################
  407. #########Begin Non Redundant Code##############################
  408.  
  409. EOREDUNDANT2
  410.  
  411. if [[ "$source" ]]; then
  412. cat <<EOPREPAREDIRECTORY >>$startdir/build-$pkgname.sh
  413. prepare_directory() {
  414.         mkdir \$startdir/src
  415.         mkdir -p \$startdir/pkg/usr/src/\$pkgname-\$pkgver
  416.         for SOURCES in \${source[@]}; do
  417.                 protocol=\$(echo \$SOURCES | sed 's|:.*||')
  418.                 if [ ! -f "\$(basename \$SOURCES)" ]; then
  419.                         if [ "\$protocol" = "http" -o "\$protocol" = "https" -o "\$protocol" = "ftp" ]; then
  420.                                 echo -e "\nDownloading \$(basename \$SOURCES)\n"
  421.                                 wget \$SOURCES
  422.                                 if [ ! "\$?" == "0" ]; then
  423.                                         echo "Download failed"
  424.                                         exit 2
  425.                                 fi
  426.                         else
  427.                                 echo "\$SOURCES does not appear to be a url nor is it in the directory"
  428.                                 exit 2
  429.                         fi
  430.                 fi
  431.                 cp -R \$(basename \$SOURCES) \$startdir/src
  432.                 if ! [ "\$protocol" = "http" -o "\$protocol" = "https" -o "\$protocol" = "ftp" ]; then
  433.                         cp -R \$startdir/\$(basename \$SOURCES) \$startdir/pkg/usr/src/\$pkgname-\$pkgver/
  434.                 fi
  435.                 if [ "\${SOURCES##*.}" == "desktop" ]; then
  436.                         [[ "\$(grep -e "^Categories=[a-zA-Z]*;" \$(basename \$SOURCES))" ]] && install -D \$startdir/\$(basename \$SOURCES) $startdir/pkg/usr/share/applications/\$(basename \$SOURCES)
  437.                 fi
  438.         done
  439. }
  440.  
  441. EOPREPAREDIRECTORY
  442.  
  443. else
  444. cat <<"EOPREPAREDIRECTORY" >>$startdir/build-$pkgname.sh
  445. prepare_directory() {
  446.         mkdir $startdir/src
  447.         mkdir $startdir/pkg
  448. }
  449.  
  450. EOPREPAREDIRECTORY
  451. fi
  452.  
  453. if [ -z "$NOEXTRACT" ]; then
  454. cat <<EOEXTRACTSOURCES >>$startdir/build-$pkgname.sh
  455. extract_source() {
  456.         cd \$startdir/src
  457.         if [[ "\$(ls \$startdir/src)" ]]; then
  458.                 for FILES in \${source[@]}; do
  459.                         FILES="\$(basename \$FILES)"
  460.                         file_type=\$(file -biz "\$FILES")
  461.                         unset cmd
  462.                         case "\$file_type" in
  463.                                 *application/x-tar*)
  464.                                         cmd="tar -xf" ;;
  465.                                 *application/x-zip*)
  466.                                         cmd="unzip" ;;
  467.                                 *application/x-gzip*)
  468.                                         cmd="gunzip -d -f" ;;
  469.                                 *application/x-bzip*)
  470.                                         cmd="bunzip2 -f" ;;
  471.                         esac
  472.                         if [ "\$cmd" != "" ]; then
  473.                                 echo "\$cmd \$FILES"
  474.                                 \$cmd \$FILES
  475.                         fi
  476.                 done
  477.         elif [ ! "\$source" ]; then
  478.                 echo -n "" # lame fix
  479.         else
  480.                 echo "no files in the src directory \$startdir/src"
  481.                 exit 2
  482.         fi
  483. }
  484.  
  485. EOEXTRACTSOURCES
  486. fi
  487.  
  488. sed -n '/^build()/,/^}$/p' $startdir/ZENBUILD >> $startdir/build-$pkgname.sh
  489.  
  490. cat <<EOM >>$startdir/build-$pkgname.sh
  491.  
  492. create_slackdesc() {
  493. mkdir \$startdir/pkg/install
  494. cat <<"EODESC" >\$startdir/pkg/install/slack-desc
  495. $pkgname: ${slackdesc[0]}
  496. $pkgname:
  497. $pkgname: ${slackdesc[1]}
  498. $pkgname: ${slackdesc[2]}
  499. $pkgname: ${slackdesc[3]}
  500. $pkgname: ${slackdesc[4]}
  501. $pkgname: ${slackdesc[5]}
  502. $pkgname: ${slackdesc[6]}
  503. $pkgname: ${slackdesc[7]}
  504. $pkgname: ${slackdesc[8]}
  505. $pkgname: ${slackdesc[9]}
  506. EODESC
  507. }
  508.  
  509. EOM
  510.  
  511. if [[ "$dotnew" ]]; then
  512.         cat<<EOP >>$startdir/build-${pkgname}.sh
  513. setup_dotnew() {
  514.         for files in ${dotnew[@]} ; do
  515.                 fullfile="\${startdir}/pkg/\${files}"
  516.                 if [ -e "\$fullfile" ]; then
  517.                         mv \$fullfile \${fullfile}.new
  518.                 else
  519.                         echo "\$fullfile was not found"
  520.                         exit 2
  521.                 fi
  522.         done
  523.         cat<<"EODOTNEW" >\$startdir/pkg/install/doinst.sh
  524. #Added by buildpkg $buildpkgver
  525. dotnew() {
  526.         NEW="\${1}.new"
  527.         OLD="\$1"
  528.         if [ ! -e \$OLD ]; then
  529.                 mv \$NEW \$OLD
  530.         elif [ -z "\$(cmp \$NEW \$OLD)" ]; then
  531.                 rm \$NEW
  532.         fi
  533. }
  534. EOP
  535.  
  536. for i in ${dotnew[@]}; do
  537. echo "dotnew $i" >> $startdir/build-$pkgname.sh
  538. done
  539. cat <<"EOQ" >>$startdir/build-$pkgname.sh
  540. EODOTNEW
  541. }
  542.  
  543. EOQ
  544. fi
  545.  
  546. if [[ "$(grep '^doinst\(\)' $startdir/ZENBUILD)" ]]; then
  547.         cat <<EOPOSTINSTALL >>$startdir/build-$pkgname.sh
  548. setup_doinst() {
  549. cat <<"EODOINST" >>\$startdir/pkg/install/doinst.sh
  550. $(sed -n '/doinst()/,/^}$/p' $startdir/ZENBUILD)
  551. doinst
  552. EODOINST
  553. }
  554. EOPOSTINSTALL
  555. fi
  556.  
  557. if [[ "$docs" ]]; then
  558. cat <<EOEXTRADOCS >> $startdir/build-$pkgname.sh
  559. copy_docs() {
  560.         for stuff in \${docs[@]}; do
  561.                 if [ ! -d "\$startdir/pkg/usr/doc/\$pkgname-\$pkgver" ]; then
  562.                         mkdir -p \$startdir/pkg/usr/doc/\$pkgname-\$pkgver
  563.                 fi
  564.                 find \$startdir/src -type f -iname "\$stuff" -exec cp -R '{}' \$startdir/pkg/usr/doc/\$pkgname-\$pkgver \;
  565.         done
  566. }
  567. EOEXTRADOCS
  568. fi
  569.  
  570. if [[ "$extradepends" ]]; then
  571.         unset FIRST
  572.         for deps in ${extradepends[@]} ; do
  573.                 if [[ ! "$FIRST" ]]; then
  574.                         depstring=",${deps}"
  575.                         FIRST="1"
  576.                         continue
  577.                 fi
  578.                 depstring="${depstring},${deps}"
  579.         done
  580. fi
  581. cat <<EODEPS1 >>$startdir/build-$pkgname.sh
  582. detect_dependencies() {
  583.         echo "Detecting dependencies..."
  584. EODEPS1
  585.  
  586. if [ -z "$NOREQUIREDBUILDER" ]; then
  587.         if [ -z "$REQUIREDBUILDERFLATDEPS" ]; then
  588.                 echo '  depends=$(requiredbuilder -z $startdir/$package.tgz)' >> $startdir/build-$pkgname.sh
  589.         else
  590.                 echo '  depends=$(requiredbuilder -r -z $startdir/$package.tgz)' >> $startdir/build-$pkgname.sh
  591.         fi
  592. else
  593.         echo '  depends=""' >> $startdir/build-$pkgname.sh
  594. fi
  595.  
  596. if [[ "$lessdepends" ]]; then
  597.                 for deps in ${lessdepends[@]}; do
  598. cat <<EODEPS2 >>$startdir/build-$pkgname.sh
  599.         depends="\$(echo \$depends | sed -e 's/\<${deps}\>//' -e 's/,,/,/')"
  600. EODEPS2
  601.         done
  602. fi
  603. cat <<EODEPS3>>$startdir/build-$pkgname.sh
  604.  
  605.         depstring=\$depends$depstring
  606.         unset FIRST
  607.         for deps in \$(echo "\${depstring}" | sed 's/,/\n/g' | sort -u); do
  608.                 if [[ ! "\$FIRST" ]]; then
  609.                         finaldeps=\$deps,
  610.                         FIRST='1'
  611.                         continue
  612.                 fi
  613.                 finaldeps=\${finaldeps}\${deps},
  614.         done
  615.         echo "\$finaldeps" | sed -e 's/^,//' -e 's/,$//' > \$startdir/\$package.dep
  616. }
  617. EODEPS3
  618.  
  619. cat <<EOVARIABLES >>$startdir/build-$pkgname.sh
  620.  
  621. ####End Non Redundant Code############################
  622.  
  623. #Variables
  624.  
  625. startdir=\$(pwd)
  626. SRC=\$startdir/src
  627. PKG=\$startdir/pkg
  628.  
  629. pkgname=$pkgname
  630. pkgver=$pkgver
  631. pkgrel=$pkgrel
  632. zenver=$zenver
  633. arch=$arch
  634. package=\$pkgname-\$pkgver-\$arch-\$zenver.\$pkgrel
  635. EOVARIABLES
  636.  
  637. grep -e "^_[a-zA-Z]*=[a-zA-Z]*" $startdir/ZENBUILD >> $startdir/build-$pkgname.sh
  638. echo "source=(${source[@]})" >> $startdir/build-$pkgname.sh
  639. echo "docs=(${docs[@]})" >> $startdir/build-$pkgname.sh
  640.  
  641. CFLAGS=${CFLAGS:-"-O2 -march=$arch -mtune=i686"}
  642. CXXFLAGS=${CFLAGS:-"-O2 -march=$arch -mtune=i686"}
  643.  
  644. for FLAGS in CFLAGS CXXFLAGS; do
  645.         echo "export $FLAGS=\"${!FLAGS}\"" >>$startdir/build-$pkgname.sh
  646. done
  647.  
  648. cat <<"EOEXECUTION1" >> $startdir/build-$pkgname.sh
  649.  
  650. #Execution
  651.  
  652. check_for_root
  653. clean_old_builds
  654. prepare_directory
  655. EOEXECUTION1
  656. [ -z "$NOEXTRACT" ] && echo "extract_source" >>$startdir/build-$pkgname.sh
  657. cat <<"EOEXECUTION2">>$startdir/build-$pkgname.sh
  658. set_pre_permissions
  659. build
  660. if [ ! "$?" = "0" ]; then
  661.         echo "build() failed."
  662.         exit 2
  663. fi
  664. create_slackdesc
  665. EOEXECUTION2
  666.  
  667. [[ "$dotnew" ]] && echo "setup_dotnew" >>$startdir/build-$pkgname.sh
  668. [[ "$(grep '^doinst\(\)' $startdir/ZENBUILD)" ]] && echo "setup_doinst" >>$startdir/build-$pkgname.sh
  669. [[ "$docs" ]] && echo "copy_docs" >>$startdir/build-$pkgname.sh
  670.  
  671. cat <<"EOEXECUTION31" >> $startdir/build-$pkgname.sh
  672. check_for_menu_compliance
  673. EOEXECUTION31
  674. [ -z "$NOSTRIP" ] && echo "strip_binaries" >>$startdir/build-$pkgname.sh
  675. cat <<"EOEXECUTION32" >> $startdir/build-$pkgname.sh
  676. gzip_man_and_info_pages
  677. set_post_permissions
  678. copy_build_script
  679. create_package
  680. EOEXECUTION32
  681. [[ -z "$KEEPDEPFILE" ]] && echo "detect_dependencies" >> $startdir/build-$pkgname.sh
  682. cat <<"EOEXECUTION31" >> $startdir/build-$pkgname.sh
  683. echo "Package has been built."
  684. EOEXECUTION31
  685. if [ "$REMOVEDIRS" == "1" ]; then
  686.         echo 'echo "Cleaning pkg and src directories"' >> $startdir/build-$pkgname.sh
  687.         echo "clean_dirs" >> $startdir/build-$pkgname.sh
  688. fi
  689.  
  690. chmod +x $startdir/build-$pkgname.sh
  691. echo "build-$pkgname.sh has been created"
  692. if [ "$EXECUTE" == "1" ]; then
  693.         ./build-$pkgname.sh 2>&1 | tee build-$pkgname.log
  694. fi

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right