diff --git a/buildpkg b/buildpkg index e8690c0..3b2859d 100755 --- a/buildpkg +++ b/buildpkg @@ -191,10 +191,6 @@ loadspkgbuild() { if [ -f $BUILD_SCRIPT ]; then getpkginfo - if [ "${#options[@]}" -gt 0 ]; then - OPTIONS=($(echo ${options[@]})) - getoptions - fi else msgerr "No $BUILD_SCRIPT found." exitscript1 @@ -235,37 +231,30 @@ packaging() { pushd $PKG - #if [ -f usr/share/info/dir ]; then - #rm usr/share/info/dir - #fi - - if [ "$REMOVE_EMPTYDIRS" ]; then - removeemptydirs - fi - - if [ "$REMOVE_DOCS" ]; then - removedocs - fi - - if [ "$PURGE_FILES" ]; then + if check_options purge y; then purgefiles fi - if [ "$REMOVE_LIBTOOL" ]; then + if check_options !emptydirs y; then + removeemptydirs + fi + + if check_options !docs y && [[ -n ${DOC_DIRS[*]} ]]; then + removedocs + fi + + if check_options !libtool y; then removelibtool fi - if [ "$STRIP_PKG" ]; then + if check_options strip y; then strip_files fi - if [ "$COMPRESS_MAN" ]; then + if check_options zipman y && [[ -n ${MAN_DIRS[*]} ]]; then compressinfomanpages fi - #compressinfomanpages - #purgefiles - echo "# Generated by buildpkg" > .pkginfo echo "# `date`" >> .pkginfo echo "name = $name" >> .pkginfo @@ -308,64 +297,6 @@ packaging() { } -removeemptydirs() { - - msg2 "Removing empty directories..." - find . -type d -empty -delete - -} - -removedocs() { - - msg2 "Removing docs..." - for dir in ${DOC_DIRS[@]}; do - [ -d $dir ] && rm -fr $dir - done - -} - -removelibtool() { - - msg2 "Removing libtool files..." - find . -name "*.la" -delete - -} - -purgefiles() { - - for option in ${PURGE_FILES[@]}; do - if [ -e $option ]; then - msg2 "Purging $option..." - rm -fr $option - fi - done -} - -strip_files() { - - msg2 "Stripping binaries & libraries..." - find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null - find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null - -} - -compressinfomanpages() { - - msg2 "Compressing man & info pages..." - if [ -d usr/share/man ]; then - ( cd usr/share/man - find . -type f ! -name "*.gz" -exec gzip -9 -f {} \; - for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done - ) - fi - - if [ -d usr/share/info ]; then - ( cd usr/share/info - find . -name "*.info*" -exec gzip -9 {} \; - ) - fi -} - buildpkg() { getsource @@ -386,6 +317,14 @@ buildpkg() { NO_PREINSTALL=yes fi + if check_options makeflags n; then + unset MAKEFLAGS + fi + + if check_options buildflags n; then + unset CFLAGS CXXFLAGS + fi + buildpackage if [ "$FORCE_REBUILD" ]; then @@ -519,43 +458,6 @@ removemakedepends() { [ "$ORPHAN" = "yes" ] && [ -d $INDEX_DIR/$1 ] && saferemove+=($1) } -getoptions() { - - for opt in ${OPTIONS[@]}; do - case $opt in - libtool) - REMOVE_LIBTOOL="" ;; - !libtool) - REMOVE_LIBTOOL=yes ;; - emptydirs) - REMOVE_EMPTYDIRS="" ;; - !emptydirs) - REMOVE_EMPTYDIRS=yes ;; - strip) - STRIP_PKG=yes ;; - !strip) - STRIP_PKG="" ;; - docs) - REMOVE_DOCS="" ;; - !docs) - REMOVE_DOCS=yes ;; - zipman) - COMPRESS_MAN=yes ;; - !zipman) - COMPRESS_MAN="" ;; - purge) - PURGE_FILES=yes ;; - !purge) - PURGE_FILES="" ;; - !buildflags) - CFLAGS=""; CXXFLAGS="" ;; - !makeflags) - MAKEFLAGS="" - esac - done - -} - clearworkdir() { if [ ! "$KEEP_WORK" ]; then @@ -665,9 +567,6 @@ parse_options() { -kw|--keep-work) KEEP_WORK=yes ;; - -ns|--no-strip) - NO_STRIP=yes - ;; -rd|--redownload) REDOWNLOAD_SOURCE=yes ;; @@ -707,10 +606,6 @@ main() { . /usr/share/scratchpkg/functions || exit 1 - loadconfigfile - - getoptions - parse_options "$@" ### DISABLE COLOR ### diff --git a/functions/color b/functions/color new file mode 100644 index 0000000..c242f94 --- /dev/null +++ b/functions/color @@ -0,0 +1,38 @@ +#!/bin/bash + +### SET COLOUR CODE ### +color_red='\e[0;31m' #Red +color_green='\e[0;32m' #Green +color_yellow='\e[0;33m' #Yellow +color_blue='\e[0;34m' #Blue +color_purple='\e[0;35m' #Purple +color_cyan='\e[0;36m' #Cyan +color_gray='\e[0;37m' #Gray +color_bred='\e[1;31m' #Bold red +color_bgreen='\e[1;32m' #Bold green +color_byellow='\e[1;33m' #Bold yellow +color_bblue='\e[1;34m' #Bold blue +color_bpurple='\e[1;35m' #Bold purple +color_bcyan='\e[1;36m' #Bold cyan +color_bgray='\e[1;37m' #Bold gray +color_reset='\e[0m' #Reset color + +nocolor() { + + color_red='' + color_green='' + color_yellow='' + color_blue='' + color_purple='' + color_cyan='' + color_gray='' + color_bred='' + color_bgreen='' + color_byellow='' + color_bblue='' + color_bpurple='' + color_bcyan='' + color_bgray='' + color_reset='' + +} diff --git a/functions b/functions/functions similarity index 81% rename from functions rename to functions/functions index b61748d..3cc1ff1 100644 --- a/functions +++ b/functions/functions @@ -1,22 +1,5 @@ #!/bin/bash -### SET COLOUR CODE ### -color_red='\e[0;31m' #Red -color_green='\e[0;32m' #Green -color_yellow='\e[0;33m' #Yellow -color_blue='\e[0;34m' #Blue -color_purple='\e[0;35m' #Purple -color_cyan='\e[0;36m' #Cyan -color_gray='\e[0;37m' #Gray -color_bred='\e[1;31m' #Bold red -color_bgreen='\e[1;32m' #Bold green -color_byellow='\e[1;33m' #Bold yellow -color_bblue='\e[1;34m' #Bold blue -color_bpurple='\e[1;35m' #Bold purple -color_bcyan='\e[1;36m' #Bold cyan -color_bgray='\e[1;37m' #Bold gray -color_reset='\e[0m' #Reset color - ### SET SOME VALUE ### CONF_FILE="/etc/scratchpkg.conf" BUILD_SCRIPT="spkgbuild" @@ -26,6 +9,18 @@ INDEX_DIR=/var/spkg/index BACKUP_DIR=/var/spkg/backup REJECTED_DIR=/var/spkg/rejected +if [ -f $CONF_FILE ]; then + . $CONF_FILE +else + msgerr "Configuration file not found." + exit 1 +fi + +FUNCTIONS=${FUNCTIONS:-'/usr/share/scratchpkg'} + +source "$FUNCTIONS/options" +source "$FUNCTIONS/color" + ### SET BSDTAR FOR EXTRACT PROGRAM IF LIBARCHIVE IS INSTALLED ### if [ -d $INDEX_DIR/libarchive ]; then EXTPROG=bsdtar @@ -79,26 +74,6 @@ rm_silent() { command rm "$@" 2> /dev/null } -nocolor() { - - color_red='' - color_green='' - color_yellow='' - color_blue='' - color_purple='' - color_cyan='' - color_gray='' - color_bred='' - color_bgreen='' - color_byellow='' - color_bblue='' - color_bpurple='' - color_bcyan='' - color_bgray='' - color_reset='' - -} - updatesystemdb() { # update desktop database @@ -170,17 +145,6 @@ getpkginfofrompkg() { } -loadconfigfile() { - - if [ -f $CONF_FILE ]; then - . $CONF_FILE - else - msgerr "Configuration file not found." - exit 1 - fi - -} - createtemplate() { if [ -d $TEMPLATE_NAME ]; then @@ -198,6 +162,7 @@ createtemplate() { name=$TEMPLATE_NAME version= release=1 +options=() source=() build() { diff --git a/functions/options b/functions/options new file mode 100644 index 0000000..032087d --- /dev/null +++ b/functions/options @@ -0,0 +1,121 @@ +#!/bin/bash + +opt_array() { + + if [[ -n "${options[@]}" ]]; then + for num in $(seq 0 $((${#options[@]} - 1))); do + opt=${options[num]} + if [ "$opt" = "$1" ]; then + return 0 + elif [ "$opt" = "!$1" ]; then + return 1 + fi + done + fi + if [[ -n "${OPTIONS[@]}" ]]; then + for num in $(seq 0 $((${#OPTIONS[@]} - 1))); do + opt=${OPTIONS[num]} + if [ "$opt" = "$1" ]; then + return 0 + elif [ "$opt" = "!$1" ]; then + return 1 + fi + done + fi + return 100 + +} + +check_options() { + + opt_array $1 + + case $? in + 0) + [ "$2" = "y" ] + return ;; + 1) + [ "$2" = "n" ] + return + esac + + return 100 +} + +removedocs() { + + msg2 "Removing docs..." + for dir in ${DOC_DIRS[@]}; do + [ -d $dir ] && rm -fr $dir + done + +} + +removeemptydirs() { + + msg2 "Removing empty directories..." + find . -type d -empty -delete + +} + +removelibtool() { + + msg2 "Removing libtool files..." + find . ! -type d -name "*.la" -delete + +} + +purgefiles() { + + msg2 "Purging unwanted files..." + for option in ${PURGE_FILES[@]}; do + if [ -e $option ]; then + rm -fr $option + fi + done +} + +strip_files() { + + msg2 "Stripping binaries & libraries..." + find . -type f 2>/dev/null | while read -r binary ; do + case "$(file -bi "$binary")" in + *application/x-sharedlib*) # Libraries (.so) + strip --strip-unneeded "$binary" ;; + *application/x-archive*) # Libraries (.a) + strip --strip-debug "$binary" ;; + *application/x-object*) + case "$binary" in + *.ko) # Kernel module + strip --strip-unneeded "$binary" ;; + *) + continue;; + esac;; + *application/x-executable*) # Binaries + strip --strip-all "$binary" ;; + *) + continue ;; + esac + done +} + +compressinfomanpages() { + + msg2 "Compressing man & info pages..." + for mandir in ${MAN_DIRS[@]}; do + if [ -d $mandir ]; then + (cd $mandir + find . -type f ! -name "*.gz" -exec gzip -9 -f {} \; 2>/dev/null + for i in $(find . -type l) ; do ln -s $(readlink $i).gz $i.gz ; rm $i ; done + ) + fi + done + + if [ -d usr/share/info ]; then + (cd usr/share/info + find usr/share/info -name "*.info*" -exec gzip -9 {} \; + ) + fi +} + + diff --git a/installpkg b/installpkg index d30d9b6..b9c530d 100755 --- a/installpkg +++ b/installpkg @@ -80,37 +80,7 @@ installpkg() { fi if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - - TMP_TARLIST="/tmp/$name.tarlist.spkg" - tar -tf "$PKGNAME" --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} > $TMP_TARLIST - - msg2 "Removing old files..." - grep -v '/$' $INDEX_DIR/$name/.files | while read line; do - if [ ! "$(grep -Fx "$line" $TMP_TARLIST)" ]; then - pushd $ROOT_DIR - if [ "$VERBOSE_INSTALL" = "yes" ]; then - rm_silent "$line" && echo "$line" && OLDFILEREMOVE=yes || msgwarn "Failed remove $line" - else - rm_silent "$line" && OLDFILEREMOVE=yes || msgwarn "Failed remove $line" - fi - popd - fi - done - - msg2 "Removing old dirs..." - while IFS=' ' read -r line; do - if [ ! "$(tac $TMP_TARLIST | grep -x "$line")" ] && [ ! "$(grep -Rx --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then - pushd $ROOT_DIR - if [ "$VERBOSE_INSTALL" = "yes" ]; then - rmdir_silent "$line" && echo "$line" || msgwarn "Failed remove $line" - else - rmdir_silent "$line" || msgwarn "Failed remove $line" - fi - popd - fi - done < <(tac $INDEX_DIR/$name/.files | grep '/$') - - rm $TMP_TARLIST + removeoldfiles fi registerpkg @@ -153,6 +123,40 @@ installpkg() { spkglock } +removeoldfiles() { + + TMP_TARLIST="/tmp/$name.tarlist.spkg" + tar -tf "$PKGNAME" --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} > $TMP_TARLIST + + msg2 "Removing old files & dirs..." + grep -v '/$' $INDEX_DIR/$name/.files | while read line; do + if [ ! "$(grep -Fx "$line" $TMP_TARLIST)" ]; then + pushd $ROOT_DIR + if [ "$VERBOSE_INSTALL" = "yes" ]; then + rm_silent "$line" && echo "$line" && OLDFILEREMOVE=yes || msgwarn "Failed remove $line" + else + rm_silent "$line" && OLDFILEREMOVE=yes || msgwarn "Failed remove $line" + fi + popd + fi + done + + while IFS=' ' read -r line; do + if [ ! "$(tac $TMP_TARLIST | grep -x "$line")" ] && [ ! "$(grep -Rx --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then + pushd $ROOT_DIR + if [ "$VERBOSE_INSTALL" = "yes" ]; then + rmdir_silent "$line" && echo "$line" || msgwarn "Failed remove $line" + else + rmdir_silent "$line" || msgwarn "Failed remove $line" + fi + popd + fi + done < <(tac $INDEX_DIR/$name/.files | grep '/$') + + rm $TMP_TARLIST + +} + registerpkg() { [ ! -d $INDEX_DIR/$name ] && mkdir $INDEX_DIR/$name @@ -483,8 +487,6 @@ main() { nocolor fi - loadconfigfile - ### SHOW HELP ### if [ "$SHOW_HELP" ]; then help diff --git a/removepkg b/removepkg index 652945c..edd1008 100755 --- a/removepkg +++ b/removepkg @@ -251,8 +251,6 @@ main() { nocolor fi - loadconfigfile - if [ -z $RMNAME ]; then msgerr "Please state package name for remove." exit 1 diff --git a/scratch b/scratch index 7d2fcdf..5e1e46c 100755 --- a/scratch +++ b/scratch @@ -643,8 +643,6 @@ main() { nocolor fi - loadconfigfile - ### LIST PACKAGES & SOURCE CACHE ### if [ $PKG_CACHE ]; then pkgcache diff --git a/scratchpkg.conf b/scratchpkg.conf index 8926e4d..f2e3842 100644 --- a/scratchpkg.conf +++ b/scratchpkg.conf @@ -11,12 +11,11 @@ WORK_DIR="/tmp" PORT_REPO=(/usr/ports/base /usr/ports/blfs /usr/ports/xorg - /usr/ports/extra) + /usr/ports/extra + /home/emmett/github/scratchpkgscripts/lfs-8.1/ports/wip) NO_EXTRACT=(usr/share/locale) - -OPTIONS=(!libtool emptydirs strip docs purge zipman buildflags makeflags) - -PURGE_FILES=(usr/share/info/dir usr/info/dir) +OPTIONS=(libtool emptydirs strip docs purge zipman buildflags makeflags) +PURGE_FILES=(usr/{,share/}info/dir) DOC_DIRS=(usr/{,local/}{,share/}{doc,gtk-doc} opt/*/{doc,gtk-doc}) -MAN_DIRS=({usr{,/local}{,/share},opt/*}/{man,info}) +MAN_DIRS=({usr{,/local}{,/share},opt/*}/man) diff --git a/spkgbuild.proto b/spkgbuild.proto index 8eb8ba3..f4194dd 100644 --- a/spkgbuild.proto +++ b/spkgbuild.proto @@ -10,6 +10,7 @@ name= version= release=1 +options=() source=() build() {