From 9455f3a70e98bcdf52afcd257e978f48d8b80d07 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 09:49:46 -0500 Subject: [PATCH 01/33] Imprived help output --- SOURCES/rpmbuilder | 82 +++++++++++++++++++++++----------------------- rpmbuilder.spec | 5 ++- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 87c579b..7a7a96b 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1,7 +1,7 @@ #!/usr/bin/env bash APP="RPMBuilder" -VER="1.1.5" +VER="1.1.6" #################################################################### @@ -110,7 +110,7 @@ SHORT_ARGS="r:remote P:!parallel hh:host uu:user pp:pass kk:key sd:source_dir INSPEC_ARGS="git svn hg bzr branch revision tag svn_user svn_pass github bitbucket launchpad qa_rpaths pedantic strict no_lint relative_pack" -MERGEABLE_ARGS="pack with without enable_repo disable_repo" +MERGEABLE_ARGS="pack with without enable_repo disable_repo define" KEEP_ARGS=true @@ -2575,33 +2575,33 @@ usage() { show "" show "Source packaging:" $BOLD show "" - show " ${CL_GREEN}--pack, -p${CL_NORM} ${CL_DARK}files${CL_NORM} Pack specified files to tgz archive with default source name ${CL_CYAN}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--pack, -p${CL_NORM} ${CL_GREY}files${CL_NORM} Pack specified files to tgz archive with default source name ${CL_DARK}(mergeable)${CL_NORM}" show " ${CL_GREEN}--relative-pack, -R${CL_NORM} Use relative path in source archive instead of absolute" - show " ${CL_GREEN}--source-dir, -sd${CL_NORM} ${CL_DARK}path${CL_NORM} Path to directory which contains source files specified in spec file" - show " ${CL_GREEN}--source-list, -sl${CL_NORM} ${CL_DARK}file${CL_NORM} Path to file which contains list of source files specified in spec file," + show " ${CL_GREEN}--source-dir, -sd${CL_NORM} ${CL_GREY}path${CL_NORM} Path to directory which contains source files specified in spec file" + show " ${CL_GREEN}--source-list, -sl${CL_NORM} ${CL_GREY}file${CL_NORM} Path to file which contains list of source files specified in spec file," show " and will be packed to tgz archive with default source name" - show " ${CL_GREEN}--dlcache, -dc${CL_NORM} ${CL_DARK}path${CL_NORM} Path to directory for downloads caching" - show " ${CL_GREEN}--download, -dl${CL_NORM} ${CL_DARK}path${CL_NORM} Download all remote sources to specified directory" + show " ${CL_GREEN}--dlcache, -dc${CL_NORM} ${CL_GREY}path${CL_NORM} Path to directory for downloads caching" + show " ${CL_GREEN}--download, -dl${CL_NORM} ${CL_GREY}path${CL_NORM} Download all remote sources to specified directory" show "" - show " ${CL_GREEN}--git${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from Git repository ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--svn${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from SVN repository ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--hg${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from Mercurial repository ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--bzr${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from Bazar repository ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--path, -rp${CL_NORM} ${CL_DARK}path${CL_NORM} Path to directory with sources in repo" - show " ${CL_GREEN}--branch, -rb${CL_NORM} ${CL_DARK}name${CL_NORM} Use specified repository branch ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--revision, -rr${CL_NORM} ${CL_DARK}name${CL_NORM} Use specified revision" - show " ${CL_GREEN}--tag, -rt${CL_NORM} ${CL_DARK}name${CL_NORM} Use specified tag ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--svn-user, -su${CL_NORM} ${CL_DARK}username${CL_NORM} Username for access to svn repository" - show " ${CL_GREEN}--svn-pass, -sp${CL_NORM} ${CL_DARK}password${CL_NORM} Password for access to svn repository" + show " ${CL_GREEN}--git${CL_NORM} ${CL_GREY}url${CL_NORM} Fetch sources from Git repository ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--svn${CL_NORM} ${CL_GREY}url${CL_NORM} Fetch sources from SVN repository ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--hg${CL_NORM} ${CL_GREY}url${CL_NORM} Fetch sources from Mercurial repository ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--bzr${CL_NORM} ${CL_GREY}url${CL_NORM} Fetch sources from Bazar repository ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--path, -rp${CL_NORM} ${CL_GREY}path${CL_NORM} Path to directory with sources in repo" + show " ${CL_GREEN}--branch, -rb${CL_NORM} ${CL_GREY}name${CL_NORM} Use specified repository branch ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--revision, -rr${CL_NORM} ${CL_GREY}name${CL_NORM} Use specified revision" + show " ${CL_GREEN}--tag, -rt${CL_NORM} ${CL_GREY}name${CL_NORM} Use specified tag ${CL_DARK}(macro supported)${CL_NORM}" + show " ${CL_GREEN}--svn-user, -su${CL_NORM} ${CL_GREY}username${CL_NORM} Username for access to svn repository" + show " ${CL_GREEN}--svn-pass, -sp${CL_NORM} ${CL_GREY}password${CL_NORM} Password for access to svn repository" show "" - show " ${CL_GREEN}--github, -gh${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from github.com repository by url ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--github, -gh${CL_NORM} ${CL_DARK}user:project${CL_NORM} Fetch sources from github.com repository by user and project" - show " ${CL_GREEN}--github, -gh${CL_NORM} ${CL_DARK}user/project${CL_NORM} Fetch sources from github.com repository by user and project" - show " ${CL_GREEN}--bitbucket, -bb${CL_NORM} ${CL_DARK}url${CL_NORM} Fetch sources from bitbucket.org repository by url ${CL_CYAN}(macro supported)${CL_NORM}" - show " ${CL_GREEN}--bitbucket, -bb${CL_NORM} ${CL_DARK}user>::,,...\"${CL_NORM} Ignoring rpaths check" + show " ${CL_GREEN}--arch, -a${CL_NORM} ${CL_GREY}arch${CL_NORM} Override target arch for build" + show " ${CL_GREEN}--qa-rpaths${CL_NORM}${CL_GREY}=\",,...\"${CL_NORM} Ignoring rpaths check" show "" show "Arguments passing:" $BOLD show "" - show " ${CL_GREEN}--with, -w${CL_NORM} ${CL_DARK}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_CYAN}(mergeable)${CL_NORM}" - show " ${CL_GREEN}--without, -W${CL_NORM} ${CL_DARK}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_CYAN}(mergeable)${CL_NORM}" - show " ${CL_GREEN}--define, -D${CL_NORM} ${CL_DARK}\"\"${CL_NORM} Define MACRO with value (exist macro will be not redefined)" + show " ${CL_GREEN}--with, -w${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--without, -W${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--define, -D${CL_NORM} ${CL_GREY}\"\"${CL_NORM} Define MACRO with value (exist macro will be not redefined) ${CL_DARK}(mergeable)${CL_NORM}" show "" show " Examples:" $BOLD show "" @@ -2673,11 +2673,11 @@ usage() { show "Other:" $BOLD show "" show " ${CL_GREEN}--sign, -s${CL_NORM} Sign package after build" - show " ${CL_GREEN}--dest, --dest-dir, -d${CL_NORM} ${CL_DARK}path${CL_NORM} Save builded packages to specified directory" + show " ${CL_GREEN}--dest, --dest-dir, -d${CL_NORM} ${CL_GREY}path${CL_NORM} Save builded packages to specified directory" show " ${CL_GREEN}--keep-log, -kl${CL_NORM} Save build log after unsuccessful build" show " ${CL_GREEN}--bump, -b${CL_NORM} Bump release in spec file after successful package build" - show " ${CL_GREEN}--bump-comment, -bc${CL_NORM} ${CL_DARK}comment${CL_NORM} Comment which will be added while release bump" - show " ${CL_GREEN}--tmp${CL_NORM} ${CL_DARK}path${CL_NORM} Path to temporary directory" + show " ${CL_GREEN}--bump-comment, -bc${CL_NORM} ${CL_GREY}comment${CL_NORM} Comment which will be added while release bump" + show " ${CL_GREEN}--tmp${CL_NORM} ${CL_GREY}path${CL_NORM} Path to temporary directory" show " ${CL_GREEN}--verbose, -V${CL_NORM} Verbose output" show " ${CL_GREEN}--help, --usage, -h${CL_NORM} Show this help message" show " ${CL_GREEN}--ver, --version, -v${CL_NORM} Show information about version" diff --git a/rpmbuilder.spec b/rpmbuilder.spec index 1dbd6bd..37a7c45 100644 --- a/rpmbuilder.spec +++ b/rpmbuilder.spec @@ -2,7 +2,7 @@ Summary: RPM package build helper Name: rpmbuilder -Version: 1.1.5 +Version: 1.1.6 Release: 0%{?dist} License: EKOL Group: Development/Tools @@ -51,6 +51,9 @@ rm -rf %{buildroot} ############################################################################### %changelog +* Mon Nov 14 2016 Anton Novojilov - 1.1.6-0 +- Improved help output + * Sun Sep 25 2016 Anton Novojilov - 1.1.5-0 - UI improvements - Fixed typos in help output From f864a5a894a89287bafb178eff592a80577b77ab Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 09:54:14 -0500 Subject: [PATCH 02/33] Typo fixed --- SOURCES/rpmbuilder | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 7a7a96b..f2b22ad 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -129,7 +129,7 @@ LONG_BUILD=300 BUILD_LOCK=".buildlock" BUILD_LOCK_LOCAL="/tmp/rpmbuilder-local-lock" -BUILD_LOCK_PARALELL="/tmp/rpmbuilder-paralell-lock" +BUILD_LOCK_PARALLEL="/tmp/rpmbuilder-parallel-lock" LOCK_TIME_MAX_DIFF=10800 # 3 Hours SSH_BASE_OPTS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet" @@ -297,13 +297,13 @@ checkParalellBuildAvailability() { return fi - local cdt=$(stat $BUILD_LOCK_PARALELL -c "%Y") + local cdt=$(stat $BUILD_LOCK_PARALLEL -c "%Y") local ct=$(now) local cdf=$(( $ct - $cdt )) if [[ $cdf -gt $LOCK_TIME_MAX_DIFF ]] ; then show "We found lock file created more than 3 hours ago. It's too much time for usual build process." - show "If another build process does not occur, you must remove file $BUILD_LOCK_PARALELL manually." + show "If another build process does not occur, you must remove file $BUILD_LOCK_PARALLEL manually." show "We will continue build when this file will be removed." $BROWN else show "Another parallel build process in progress." $BROWN @@ -320,9 +320,9 @@ checkParalellBuildAvailability() { } hasParalellLock() { - [[ ! -f $BUILD_LOCK_PARALELL ]] && return 1 + [[ ! -f $BUILD_LOCK_PARALLEL ]] && return 1 - local pid=$(cat $BUILD_LOCK_PARALELL) + local pid=$(cat $BUILD_LOCK_PARALLEL) [[ ! -d /proc/$pid ]] && removeParalellLock && return 1 @@ -330,17 +330,17 @@ hasParalellLock() { } createParalellLock() { - echo $$ > $BUILD_LOCK_PARALELL - chmod 666 $BUILD_LOCK_PARALELL + echo $$ > $BUILD_LOCK_PARALLEL + chmod 666 $BUILD_LOCK_PARALLEL } removeParalellLock() { - if [[ -f $BUILD_LOCK_PARALELL ]] ; then + if [[ -f $BUILD_LOCK_PARALLEL ]] ; then local cur_user=$(whoami) - local lock_owner=$(stat $BUILD_LOCK_PARALELL -c "%U") + local lock_owner=$(stat $BUILD_LOCK_PARALLEL -c "%U") if [[ "$cur_user" == "$lock_owner" ]] ; then - rm -f $BUILD_LOCK_PARALELL &> /dev/null + rm -f $BUILD_LOCK_PARALLEL &> /dev/null fi fi } From ad3f0293c9d066af1bad31c8d7ca364aa50dc66e Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 10:59:21 -0500 Subject: [PATCH 03/33] RPMB-113 Multiple macro definition support --- .codeclimate.yml | 12 ++++++++++++ SOURCES/rpmbuilder | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 0000000..abe8026 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,12 @@ +engines: + shellcheck: + enabled: true + checks: + SC2034: + enabled: false + SC2154: + enabled: false + +ratings: + paths: + - "SOURCES/kaosv" diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index f2b22ad..44f9fc8 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -2244,9 +2244,16 @@ getBuildArgs() { [[ $arch ]] && args="$args --target=$arch" [[ $with ]] && args=$(getBuildArgsWith "$args") [[ $without ]] && args=$(getBuildArgsWithout "$args") - [[ $define ]] && args="$args --define=\"$define\"" [[ $verbose ]] && args="$args --verbose" + local def + + if [[ $define ]] ; then + for def in $define ; do + args="$args --define=$def" + done + fi + echo "$args" } From 04d1a4c4ff1cba79ea0367787edd46a6613795ac Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 11:01:11 -0500 Subject: [PATCH 04/33] Fixed check paths in codeclimate config --- .codeclimate.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index abe8026..77f8df0 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -9,4 +9,6 @@ engines: ratings: paths: - - "SOURCES/kaosv" + - "SOURCES/rpmbuilder" + - "SOURCES/rpmunbuilder" + - "SOURCES/buildmon" From 7edf8aeb9f5a075aae0cef7192dd5710a36c3e67 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 12:05:33 -0500 Subject: [PATCH 05/33] buildmon refactoring --- SOURCES/buildmon | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/SOURCES/buildmon b/SOURCES/buildmon index dbcca26..405ebc3 100755 --- a/SOURCES/buildmon +++ b/SOURCES/buildmon @@ -1,7 +1,7 @@ #!/usr/bin/env bash -APP="BuildMonitor" -VER="1.0" +APP="RPMBuilder Node Monitor" +VER="1.1.0" ############################################################################### @@ -13,7 +13,7 @@ CLEAN_DELAY=600 KEEP_DAYS=7 # 1 Week DIR_LIST="BUILD BUILDROOT RPMS SOURCES SPECS SRPMS" -CWD=`pwd` +CWD=$(pwd) ############################################################################### @@ -25,12 +25,14 @@ main() { check() { local has_lock - local dl=0 + local dl + + dl=0 while : ; do sleep 1 - if [[ `ps -U $BUILDER_USER | grep -v grep | grep rpmbuild` ]] ; then + if [[ $(pgrep -U $BUILDER_USER rpmbuild) ]] ; then touch $BUILD_LOCK has_lock=true else @@ -49,31 +51,15 @@ check() { } clean() { - local keep_sec=$(( $KEEP_DAYS * 86400 )) - local now=`date +%s` - - local dirname dir target mdate datediff - - for dirname in $DIR_LIST ; do - local dir=$BUILDER_DIR/rpmbuild/$dirname - - for target in `ls -1 $dir` ; do - mdate=`stat -c %Y $BUILDER_DIR/rpmbuild/$dirname/$target` - - datediff=$(( $now - $mdate )) - - if [[ $datediff -gt $keep_sec ]] ; then - rm -rf $BUILDER_DIR/rpmbuild/$dirname/$target - fi - done - done + local rbdir="$BUILDER_DIR/rpmbuild" + find $rbdir -maxdepth 1 -type d -mtime +$KEEP_DAYS -delete } doExit() { - rm -f $BUILD_LOCK + rm -f "$BUILD_LOCK" exit 0 } ############################################################################### -main $0 +main "$0" From be0a302f180805ab16c9c1037c8a117f31474f17 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 13:04:33 -0500 Subject: [PATCH 06/33] rpmunbuilder refactoring --- SOURCES/rpmunbuilder | 158 +++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 75 deletions(-) diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index 42e791a..b897edd 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -1,7 +1,11 @@ #!/usr/bin/env bash +######################################################################################## + APP="RPMUnBuilder" -VER="1.0.0" +VER="1.1.0" + +######################################################################################## NORM=0 BOLD=1 @@ -13,6 +17,7 @@ BLUE=34 MAG=35 CYAN=36 GREY=37 +DARK=90 CL_NORM="\e[${NORM}m" CL_BOLD="\e[${BOLD}m" @@ -24,6 +29,7 @@ CL_BLUE="\e[${BLUE}m" CL_MAG="\e[${MAG}m" CL_CYAN="\e[${CYAN}m" CL_GREY="\e[${GREY}m" +CL_DARK="\e[${DARK}m" CL_BL_RED="\e[${RED};1m" CL_BL_GREEN="\e[${GREEN};1m" CL_BL_BROWN="\e[${BROWN};1m" @@ -31,6 +37,7 @@ CL_BL_BLUE="\e[${BLUE};1m" CL_BL_MAG="\e[${MAG};1m" CL_BL_CYAN="\e[${CYAN};1m" CL_BL_GREY="\e[${GREY};1m" +CL_BL_DARK="\e[${DARK};1m" CL_UL_RED="\e[${RED};4m" CL_UL_GREEN="\e[${GREEN};4m" CL_UL_BROWN="\e[${BROWN};4m" @@ -38,6 +45,7 @@ CL_UL_BLUE="\e[${BLUE};4m" CL_UL_MAG="\e[${MAG};4m" CL_UL_CYAN="\e[${CYAN};4m" CL_UL_GREY="\e[${GREY};4m" +CL_UL_DARK="\e[${DARK};4m" CL_BG_RED="\e[${RED};7m" CL_BG_GREEN="\e[${GREEN};7m" CL_BG_BROWN="\e[${BROWN};7m" @@ -45,26 +53,27 @@ CL_BG_BLUE="\e[${BLUE};7m" CL_BG_MAG="\e[${MAG};7m" CL_BG_CYAN="\e[${CYAN};7m" CL_BG_GREY="\e[${GREY};7m" +CL_BG_DARK="\e[${DARK};7m" -SUPPORTED_ARGS="help usage" -SHORT_ARGS="h:help" +SUPPORTED_ARGS="help usage ver version" +SHORT_ARGS="h:help v:version" DEPS="rpm rpm2cpio cpio" -#################################################################### +######################################################################################## main() { - if [[ $# -eq 0 || $help || $usage ]] ; then - usage + if [[ $ver || $version ]] ; then + about exit 0 fi - if [[ $ver || $version ]] ; then - about + if [[ $# -eq 0 || $help || $usage ]] ; then + usage exit 0 fi - if [[ ! `checkDeps $DEPS` ]] ; then + if [[ ! $(checkDeps $DEPS) ]] ; then show "For usage this utility install this packages first: $DEPS" $BROWN exit 2 fi @@ -72,20 +81,20 @@ main() { local pkg="$1" local path="$2" - if [[ ! `isRPMPackage "$pkg"` ]] ; then + if [[ ! $(isRPMPackage "$pkg") ]] ; then show "Error! [$pkg] is not a rpm package!" $RED exit 1 fi if [[ -n "$path" ]] ; then - if [[ ! `checkPerms "$path" "DWX"` ]] ; then + if [[ ! $(checkPerms "$path" "DWX") ]] ; then show "Error! Please check permissions for directory [$path]." $RED exit 3 fi else - path=`pwd` - - if [[ ! `checkPerms "$path" "DWX"` ]] ; then + path=$(pwd) + + if [[ ! $(checkPerms "$path" "DWX") ]] ; then show "Error! Please check permissions for directory [$path]." $RED exit 3 fi @@ -97,19 +106,20 @@ main() { processPackage() { local pkg="$1" local path="$2" - + showm "Unbuilding package: " $BOLD - local src_name - local src_list=`rpm2cpio $pkg | cpio -div --quiet 2>&1 | grep -v "cpio:"` + local src_name src_list + + src_list=$(rpm2cpio $pkg | cpio -div --quiet 2>&1 | grep -v "cpio:") - mkdir -p $path/SOURCES + mkdir -p "$path/SOURCES" for src_name in $src_list ; do if [[ $src_name =~ .spec ]] ; then - mv $src_name $path &> /dev/null + mv "$src_name" "$path" &> /dev/null else - mv $src_name $path/SOURCES &> /dev/null + mv "$src_name" "$path/SOURCES" &> /dev/null fi done @@ -117,7 +127,7 @@ processPackage() { } isRPMPackage() { - if [[ ! `LC_ALL=C rpm -K $1 | grep "error"` ]] ; then + if [[ ! $(LC_ALL=C rpm -K $1 | grep "error") ]] ; then echo 1 && return 0 else echo "" && return 1 @@ -126,9 +136,11 @@ isRPMPackage() { checkPerms() { local path="$1" - local perms=`echo $2 | tr [a-z] [A-Z]` - - for perm in `echo $perms | fold -w1` ; do + local perms + + perms=$(echo $2 | tr [a-z] [A-Z]) + + for perm in $(echo $perms | fold -w1) ; do case $perm in "R") [[ ! -r $path ]] && echo "" && return 1 ;; "W") [[ ! -w $path ]] && echo "" && return 1 ;; @@ -141,18 +153,18 @@ checkPerms() { *) echo "" && return 1 esac done - + echo 1 return 0 } #################################################################### -checkDeps() { - for app in $@ ; do - type -P $app &> /dev/null - - if [[ $? -eq 1 ]] ; then +checkDeps() { + for app in "$@" ; do + type -P "$app" &> /dev/null + + if [[ $? -eq 1 ]] ; then echo "" return 1 fi @@ -162,24 +174,20 @@ checkDeps() { return 0 } -show() { - if [[ $2 ]] ; then - echo -e "\e["$2"m"$1"${CL_NORM}" - else - echo -e "$@" +show() { + if [[ -n "$2" ]] ; then + echo -e "\e[${2}m${1}${CL_NORM}" + else + echo -e "$*" fi } showm() { - local message - - if [[ $2 ]] ; then - message=`echo "\e["$2"m"$1"${CL_NORM}"` - else - message="$@" + if [[ -n "$2" ]] ; then + echo -e -n "\e[${2}m${1}${CL_NORM}" + else + echo -e -n "$*" fi - - printf "$message" } showArgWarn() { @@ -192,37 +200,37 @@ usage() { } about() { - show "${CL_BL_CYAN}$APP${CL_NORM} ${CL_CYAN}$VER${CL_NORM} - Source rpm package unbuilder" + show "${CL_BL_CYAN}$APP${CL_NORM} ${CL_CYAN}$VER${CL_NORM} - Source RPM unbuilder" show "" - show "Copyright (C) 2009-2016 Essential Kaos LLC" $GREY - show "Essential Kaos Open Source License " $GREY + show "Copyright (C) 2009-2016 ESSENTIAL KAOS" $DARK + show "Essential Kaos Open Source License " $DARK } ## ARGUMENTS PARSING ########################################################## - + [[ $# -eq 0 ]] && main && exit - + unset arg argn argm argv argt - -argv="$@" + +argv="$*" argt="" - + while [[ -n "$1" ]] ; do if [[ "$1" =~ ' ' && -n "$argn" ]] ; then declare $argn="$1" - + unset argn shift && continue elif [[ $1 =~ ^-{1}[a-zA-Z0-9]{1,2}+.*$ ]] ; then argm=${1:1} - - if [[ " $SHORT_ARGS " =~ \ ${argm}:([a-zA-Z0-9_]*) ]] ; then + + if [[ " $SHORT_ARGS " =~ \ ${argm}:([a-zA-Z0-9_]*) ]] ; then arg="${BASH_REMATCH[1]}" else showArgWarn "-${argm}" 2> /dev/null || : shift && continue fi - + if [[ -z "$argn" ]] ; then argn=$arg else @@ -230,33 +238,33 @@ while [[ -n "$1" ]] ; do unset argn argn=$arg fi - + if [[ ! "$SUPPORTED_ARGS " =~ "$argn " ]] ; then showArgWarn "-${argm}" 2> /dev/null || : shift && continue fi - + shift && continue - elif [[ "$1" =~ ^-{2}[a-zA-Z]{1}[a-zA-Z0-9_-]+.*$ ]] ; then + elif [[ "$1" =~ ^-{2}[a-zA-Z]{1}[a-zA-Z0-9_-]+.*$ ]] ; then arg=${1:2} - + if [[ $arg == *=* ]] ; then IFS="=" arg=($arg) - + argm="${arg[0]}" ; argm=${argm//-/_} - + if [[ ! "$SUPPORTED_ARGS " =~ "${arg[0]} " ]] ; then showArgWarn "--${arg[0]//_/-}" 2> /dev/null || : shift && continue fi - + [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ "${argm} " ]] && declare ${argm}="${!argm} ${arg[@]:1:99}" || declare ${argm}="${arg[@]:1:99}" - + unset argm shift && continue - else + else arg=${arg//-/_} - + if [[ -z "$argn" ]] ; then argn=$arg else @@ -264,32 +272,32 @@ while [[ -n "$1" ]] ; do unset argn argn=$arg fi - + if [[ ! "$SUPPORTED_ARGS " =~ "$argn " ]] ; then showArgWarn "--${argn//_/-}" 2> /dev/null || : shift && continue fi - + shift && continue fi else if [[ -n "$argn" ]] ; then [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ "${argn} " ]] && declare $argn="${!argn} $1" || declare $argn="$1" - + unset argn shift && continue fi fi - + argt="$argt $1" shift - + done - + [[ -n "$argn" ]] && declare $argn=true - -unset arg argn argm - + +unset arg argn argm + [[ -n "$KEEP_ARGS" ]] && main $argv || main $argt - + ############################################################################### From 11c8375fe4eaaed67f26c5f815e23a9902f08c28 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 13:12:55 -0500 Subject: [PATCH 07/33] rpmunbuilder refactoring --- SOURCES/rpmunbuilder | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index b897edd..b62e591 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -73,7 +73,7 @@ main() { exit 0 fi - if [[ ! $(checkDeps $DEPS) ]] ; then + if [[ ! $(checkDeps "$DEPS") ]] ; then show "For usage this utility install this packages first: $DEPS" $BROWN exit 2 fi @@ -111,7 +111,7 @@ processPackage() { local src_name src_list - src_list=$(rpm2cpio $pkg | cpio -div --quiet 2>&1 | grep -v "cpio:") + src_list=$(rpm2cpio "$pkg" | cpio -div --quiet 2>&1 | grep -v "cpio:") mkdir -p "$path/SOURCES" @@ -127,7 +127,7 @@ processPackage() { } isRPMPackage() { - if [[ ! $(LC_ALL=C rpm -K $1 | grep "error") ]] ; then + if [[ ! $(LC_ALL=C rpm -K "$1" | grep "error") ]] ; then echo 1 && return 0 else echo "" && return 1 @@ -138,9 +138,9 @@ checkPerms() { local path="$1" local perms - perms=$(echo $2 | tr [a-z] [A-Z]) + perms=$(echo "$2" | tr [a-z] [A-Z]) - for perm in $(echo $perms | fold -w1) ; do + for perm in $(echo "$perms" | fold -w1) ; do case $perm in "R") [[ ! -r $path ]] && echo "" && return 1 ;; "W") [[ ! -w $path ]] && echo "" && return 1 ;; @@ -217,7 +217,7 @@ argt="" while [[ -n "$1" ]] ; do if [[ "$1" =~ ' ' && -n "$argn" ]] ; then - declare $argn="$1" + declare "$argn=$1" unset argn shift && continue @@ -234,7 +234,7 @@ while [[ -n "$1" ]] ; do if [[ -z "$argn" ]] ; then argn=$arg else - declare $argn=true + declare "$argn=true" unset argn argn=$arg fi @@ -258,7 +258,7 @@ while [[ -n "$1" ]] ; do shift && continue fi - [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ "${argm} " ]] && declare ${argm}="${!argm} ${arg[@]:1:99}" || declare ${argm}="${arg[@]:1:99}" + [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ "${argm} " ]] && declare "${argm}=${!argm} ${arg[@]:1:99}" || declare "${argm}=${arg[@]:1:99}" unset argm shift && continue @@ -268,7 +268,7 @@ while [[ -n "$1" ]] ; do if [[ -z "$argn" ]] ; then argn=$arg else - declare $argn=true + declare "$argn=true" unset argn argn=$arg fi @@ -282,7 +282,7 @@ while [[ -n "$1" ]] ; do fi else if [[ -n "$argn" ]] ; then - [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ "${argn} " ]] && declare $argn="${!argn} $1" || declare $argn="$1" + [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ "${argn} " ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" unset argn shift && continue @@ -294,7 +294,7 @@ while [[ -n "$1" ]] ; do done -[[ -n "$argn" ]] && declare $argn=true +[[ -n "$argn" ]] && declare "$argn=true" unset arg argn argm From 4e2394fd2fb7287c7fe7a87814c124773975ecb7 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 16:53:46 -0500 Subject: [PATCH 08/33] rpmunbuilder refactoring --- SOURCES/rpmunbuilder | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index b62e591..855a122 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -127,7 +127,9 @@ processPackage() { } isRPMPackage() { - if [[ ! $(LC_ALL=C rpm -K "$1" | grep "error") ]] ; then + LC_ALL=C rpm -K "$1" &> /dev/null + + if [[ $? -eq 0 ]] ; then echo 1 && return 0 else echo "" && return 1 @@ -138,7 +140,7 @@ checkPerms() { local path="$1" local perms - perms=$(echo "$2" | tr [a-z] [A-Z]) + perms=$(echo "$2" | tr "[a-z]" "[A-Z]") for perm in $(echo "$perms" | fold -w1) ; do case $perm in @@ -161,7 +163,7 @@ checkPerms() { #################################################################### checkDeps() { - for app in "$@" ; do + for app in $@ ; do type -P "$app" &> /dev/null if [[ $? -eq 1 ]] ; then @@ -203,7 +205,7 @@ about() { show "${CL_BL_CYAN}$APP${CL_NORM} ${CL_CYAN}$VER${CL_NORM} - Source RPM unbuilder" show "" show "Copyright (C) 2009-2016 ESSENTIAL KAOS" $DARK - show "Essential Kaos Open Source License " $DARK + show "Essential Kaos Open Source License " $DARK } ## ARGUMENTS PARSING ########################################################## @@ -216,7 +218,7 @@ argv="$*" argt="" while [[ -n "$1" ]] ; do - if [[ "$1" =~ ' ' && -n "$argn" ]] ; then + if [[ "$1" =~ \ && -n "$argn" ]] ; then declare "$argn=$1" unset argn @@ -239,7 +241,7 @@ while [[ -n "$1" ]] ; do argn=$arg fi - if [[ ! "$SUPPORTED_ARGS " =~ "$argn " ]] ; then + if [[ ! "$SUPPORTED_ARGS " =~ $argn\ ]] ; then showArgWarn "-${argm}" 2> /dev/null || : shift && continue fi @@ -253,12 +255,12 @@ while [[ -n "$1" ]] ; do argm="${arg[0]}" ; argm=${argm//-/_} - if [[ ! "$SUPPORTED_ARGS " =~ "${arg[0]} " ]] ; then + if [[ ! "$SUPPORTED_ARGS " =~ ${arg[0]}\ ]] ; then showArgWarn "--${arg[0]//_/-}" 2> /dev/null || : shift && continue fi - [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ "${argm} " ]] && declare "${argm}=${!argm} ${arg[@]:1:99}" || declare "${argm}=${arg[@]:1:99}" + [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ ${argm}\ ]] && declare "${argm}=${!argm} ${arg[@]:1:99}" || declare "${argm}=${arg[@]:1:99}" unset argm shift && continue @@ -273,7 +275,7 @@ while [[ -n "$1" ]] ; do argn=$arg fi - if [[ ! "$SUPPORTED_ARGS " =~ "$argn " ]] ; then + if [[ ! "$SUPPORTED_ARGS " =~ $argn\ ]] ; then showArgWarn "--${argn//_/-}" 2> /dev/null || : shift && continue fi @@ -282,7 +284,7 @@ while [[ -n "$1" ]] ; do fi else if [[ -n "$argn" ]] ; then - [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ "${argn} " ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" + [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ ${argn}\ ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" unset argn shift && continue From 2e0ea14d78ce8b91f0a0aad0b9643d1ee282adab Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 16:58:05 -0500 Subject: [PATCH 09/33] rpmunbuilder refactoring --- SOURCES/rpmunbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index 855a122..11f703e 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -140,7 +140,7 @@ checkPerms() { local path="$1" local perms - perms=$(echo "$2" | tr "[a-z]" "[A-Z]") + perms=$(echo "$2" | tr "a-z" "A-Z") for perm in $(echo "$perms" | fold -w1) ; do case $perm in From 4086794d2128c614ac6ccfe542cd86bce5f1e051 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 17:32:32 -0500 Subject: [PATCH 10/33] rpmbuilder refactoring --- .codeclimate.yml | 2 ++ SOURCES/rpmbuilder | 45 ++++++++++++++++++++++----------------------- rpmbuilder.spec | 5 +++-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 77f8df0..1a8f278 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -6,6 +6,8 @@ engines: enabled: false SC2154: enabled: false + SC2162: + enabled: false ratings: paths: diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 44f9fc8..7422057 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1,7 +1,7 @@ #!/usr/bin/env bash APP="RPMBuilder" -VER="1.1.6" +VER="1.2.0" #################################################################### @@ -88,7 +88,7 @@ SEPARATOR="--------------------------------------------------------------------- ############################################################################### -PREFS_FILE="~/.rpmbuilder" +PREFS_FILE="$HOME/.rpmbuilder" SUPPORTED_ARGS="remote !parallel host user pass key source_dir source_list !sign !no_build !no_clean !no_deps !no_lint !no_source pack !pedantic !strict @@ -187,15 +187,16 @@ main() { checkArgs - if [[ $parallel && $(cat $remote | wc -l) -gt 1 ]] ; then + if [[ $parallel && $(cat "$remote" | wc -l) -gt 1 ]] ; then parallelBuild $@ else - local start_ts=$(now) + local start_ts + start_ts=$(now) [[ $dest ]] && dest_dir="$dest" - [[ $dest_dir ]] && dest_dir=$(getAbsPath $dest_dir) - [[ $dlcache ]] && dlcache=$(getAbsPath $dlcache) - [[ $download ]] && dlcache=$(getAbsPath $download) + [[ $dest_dir ]] && dest_dir=$(getAbsPath "$dest_dir") + [[ $dlcache ]] && dlcache=$(getAbsPath "$dlcache") + [[ $download ]] && dlcache=$(getAbsPath "$download") makeTemp @@ -237,9 +238,11 @@ main() { notify() { [[ $notify ]] && bell && return - local start_ts=$1 - local end_ts=$(now) - local time_diff=$(( $end_ts - $start_ts )) + local start_ts end_ts time_diff + + start_ts=$1 + end_ts=$(now) + time_diff=$(( end_ts - start_ts )) [[ $time_diff -ge $LONG_BUILD ]] && bell } @@ -275,17 +278,17 @@ parallelBuild() { local serv sess while read serv ; do - local serv_name=$(echo $serv | cut -f2 -d"@") + local serv_name=$(echo "$serv" | cut -f2 -d"@") if [[ ! $sess ]] ; then - tmux new-session -s "rpmbuilder" -d "$0 $args -r $serv --tmuxl" 2>&1 1>/dev/null + tmux new-session -s "rpmbuilder" -d "$0 $args -r $serv --tmuxl" >/dev/null 2>&1 sess=true else - tmux split-window "$0 $args -r $serv --tmuxl" 2>&1 1>/dev/null + tmux split-window "$0 $args -r $serv --tmuxl" >/dev/null 2>&1 fi - done < $remote + done < "$remote" - tmux attach-session -t "rpmbuilder" 2>&1 1>/dev/null + tmux attach-session -t "rpmbuilder" >/dev/null 2>&1 removeParalellLock @@ -2521,20 +2524,16 @@ show() { if [[ $2 ]] ; then echo -e "\e[${2}m${1}\e[0m" else - echo -e "$@" + echo -e "$*" fi } showm() { - local message - - if [[ $2 ]] ; then - message=$(echo "\e[${2}m${1}\e[0m") + if [[ -n "$2" ]] ; then + echo -e -n "\e[${2}m${1}${CL_NORM}" else - message="$@" + echo -e -n "$*" fi - - printf "$message" } showt() { diff --git a/rpmbuilder.spec b/rpmbuilder.spec index 37a7c45..45799c8 100644 --- a/rpmbuilder.spec +++ b/rpmbuilder.spec @@ -2,7 +2,7 @@ Summary: RPM package build helper Name: rpmbuilder -Version: 1.1.6 +Version: 1.2.0 Release: 0%{?dist} License: EKOL Group: Development/Tools @@ -51,7 +51,8 @@ rm -rf %{buildroot} ############################################################################### %changelog -* Mon Nov 14 2016 Anton Novojilov - 1.1.6-0 +* Mon Nov 14 2016 Anton Novojilov - 1.2.0-0 +- Code refactoring - Improved help output * Sun Sep 25 2016 Anton Novojilov - 1.1.5-0 From 0b853b383f06c9cbb0eee3e65958c7b09c86ff09 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 17:39:32 -0500 Subject: [PATCH 11/33] rpmbuilder refactoring --- SOURCES/rpmunbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index 11f703e..77e33d4 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -140,7 +140,7 @@ checkPerms() { local path="$1" local perms - perms=$(echo "$2" | tr "a-z" "A-Z") + perms=$(echo "$2" | tr "[:lower:]" "[:upper:]") for perm in $(echo "$perms" | fold -w1) ; do case $perm in From 82e5ee319bc2e3af3c11b69a0eae550430d59f7c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 18:00:41 -0500 Subject: [PATCH 12/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 86 +++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 7422057..ec38af6 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -275,7 +275,7 @@ parallelBuild() { createParalellLock - local serv sess + local serv serv_name sess while read serv ; do local serv_name=$(echo "$serv" | cut -f2 -d"@") @@ -300,9 +300,11 @@ checkParalellBuildAvailability() { return fi - local cdt=$(stat $BUILD_LOCK_PARALLEL -c "%Y") - local ct=$(now) - local cdf=$(( $ct - $cdt )) + local cdt ct cdf + + cdt=$(stat $BUILD_LOCK_PARALLEL -c "%Y") + ct=$(now) + cdf=$(( ct - cdt )) if [[ $cdf -gt $LOCK_TIME_MAX_DIFF ]] ; then show "We found lock file created more than 3 hours ago. It's too much time for usual build process." @@ -333,17 +335,19 @@ hasParalellLock() { } createParalellLock() { - echo $$ > $BUILD_LOCK_PARALLEL - chmod 666 $BUILD_LOCK_PARALLEL + echo "$$" > $BUILD_LOCK_PARALLEL + chmod 666 "$BUILD_LOCK_PARALLEL" } removeParalellLock() { + local cur_user lock_owner + if [[ -f $BUILD_LOCK_PARALLEL ]] ; then - local cur_user=$(whoami) - local lock_owner=$(stat $BUILD_LOCK_PARALLEL -c "%U") + cur_user=$(whoami) + lock_owner=$(stat "$BUILD_LOCK_PARALLEL" -c "%U") if [[ "$cur_user" == "$lock_owner" ]] ; then - rm -f $BUILD_LOCK_PARALLEL &> /dev/null + rm -f "$BUILD_LOCK_PARALLEL" &> /dev/null fi fi } @@ -453,22 +457,17 @@ readInspecArgs() { argn="${arg[0]//-/_}" if [[ -z "${!argn}" && $INSPEC_ARGS\ =~ $argn\ ]] ; then - eval $argn='${arg[@]:1:99}' + eval "$argn=${arg[@]:1:99}" fi - done < <(grep "$INSPEC_ARG_PREFIX" $spec | sed "s/# \?$INSPEC_ARG_PREFIX//g" | tr -s " ") + done < <(grep "$INSPEC_ARG_PREFIX" "$spec" | sed "s/# \?$INSPEC_ARG_PREFIX//g" | tr -s " ") } processGithubSource() { - local github_user - local github_repo - local github_tag - local github_branch - local github_act + local github_user github_repo github_tag github_branch github_act local delim - local is_branch - local is_tag + local is_branch is_tag if [[ $branch ]] ; then is_branch=true @@ -477,30 +476,30 @@ processGithubSource() { fi if [[ "$github" =~ (http|https) ]] ; then - github_user=$(echo $github | cut -f4 -d"/") - github_repo=$(echo $github | cut -f5 -d"/") - github_act=$(echo $github | cut -f6 -d"/") + github_user=$(echo "$github" | cut -f4 -d"/") + github_repo=$(echo "$github" | cut -f5 -d"/") + github_act=$(echo "$github" | cut -f6 -d"/") if [[ "$github_act" =~ (zip|tar)ball ]] ; then - github_tag=$(echo $github | cut -f7 -d"/") + github_tag=$(echo "$github" | cut -f7 -d"/") [[ $is_tag ]] && tag="$github_tag" [[ $is_branch ]] && branch="$github_tag" elif [[ "$github_act" == "tree" ]] ; then - github_branch=$(echo $github | cut -f7 -d"/") + github_branch=$(echo "$github" | cut -f7 -d"/") branch="$github_branch" fi else - if [[ "$github" =~ ":" ]] ; then + if [[ "$github" =~ : ]] ; then delim=":" - elif [[ "$github" =~ "/" ]] ; then + elif [[ "$github" =~ / ]] ; then delim="/" else return 1 fi - github_user=$(echo $github | cut -f1 -d"$delim") - github_repo=$(echo $github | cut -f2 -d"$delim") + github_user=$(echo "$github" | cut -f1 -d"$delim") + github_repo=$(echo "$github" | cut -f2 -d"$delim") [[ -z "$github_user" || -z "$github_repo" ]] && return fi @@ -509,18 +508,11 @@ processGithubSource() { } processBitbucketSource() { - local bitbucket_user - local bitbucket_repo - local bitbucket_tag - local bitbucket_branch - local bitbucket_act + local bitbucket_user bitbucket_repo bitbucket_tag bitbucket_branch bitbucket_act local delim - - local is_branch - local is_tag - local is_git - local is_hg + + local is_branch is_tag is_git is_hg if [[ $hg ]] ; then is_hg=true @@ -529,12 +521,12 @@ processBitbucketSource() { fi if [[ "$bitbucket" =~ (http|https) ]] ; then - bitbucket_user=$(echo $bitbucket | cut -f4 -d"/") - bitbucket_repo=$(echo $bitbucket | cut -f5 -d"/") - bitbucket_act=$(echo $bitbucket | cut -f6 -d"/") + bitbucket_user=$(echo "$bitbucket" | cut -f4 -d"/") + bitbucket_repo=$(echo "$bitbucket" | cut -f5 -d"/") + bitbucket_act=$(echo "$bitbucket" | cut -f6 -d"/") if [[ "$bitbucket_act" == "get" ]] ; then - bitbucket_tag=$(echo $bitbucket | cut -f7 -d"/" | sed 's/.zip\|.tar.gz\|.tar.bz2//g') + bitbucket_tag=$(echo "$bitbucket" | cut -f7 -d"/" | sed 's/.zip\|.tar.gz\|.tar.bz2//g') if [[ $branch ]] ; then is_branch=true @@ -544,8 +536,8 @@ processBitbucketSource() { [[ $is_tag ]] && tag="$bitbucket_tag" [[ $is_branch ]] && branch="$bitbucket_tag" - elif [[ "$bitbucket" =~ "?at=" ]] ; then - bitbucket_branch=$(echo $bitbucket | cut -f2 -d"=") + elif [[ "$bitbucket" =~ ?at= ]] ; then + bitbucket_branch=$(echo "$bitbucket" | cut -f2 -d"=") if [[ $tag ]] ; then is_tag=true @@ -557,16 +549,16 @@ processBitbucketSource() { [[ $is_branch ]] && branch="$bitbucket_branch" fi else - if [[ "$bitbucket" =~ ":" ]] ; then + if [[ "$bitbucket" =~ : ]] ; then delim=":" - elif [[ "$bitbucket" =~ "/" ]] ; then + elif [[ "$bitbucket" =~ / ]] ; then delim="/" else return 1 fi - bitbucket_user=$(echo $bitbucket | cut -f1 -d"$delim") - bitbucket_repo=$(echo $bitbucket | cut -f2 -d"$delim") + bitbucket_user=$(echo "$bitbucket" | cut -f1 -d"$delim") + bitbucket_repo=$(echo "$bitbucket" | cut -f2 -d"$delim") [[ -z "$bitbucket_user" || -z "$bitbucket_repo" ]] && return fi From 6dbb23b0ab3deb0b73fc9700af01bbaf6de0087c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 18:14:22 -0500 Subject: [PATCH 13/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index ec38af6..56c600c 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -278,7 +278,7 @@ parallelBuild() { local serv serv_name sess while read serv ; do - local serv_name=$(echo "$serv" | cut -f2 -d"@") + serv_name=$(echo "$serv" | cut -f2 -d"@") if [[ ! $sess ]] ; then tmux new-session -s "rpmbuilder" -d "$0 $args -r $serv --tmuxl" >/dev/null 2>&1 @@ -327,9 +327,10 @@ checkParalellBuildAvailability() { hasParalellLock() { [[ ! -f $BUILD_LOCK_PARALLEL ]] && return 1 - local pid=$(cat $BUILD_LOCK_PARALLEL) + local pid + pid=$(cat "$BUILD_LOCK_PARALLEL") - [[ ! -d /proc/$pid ]] && removeParalellLock && return 1 + [[ ! -d "/proc/$pid" ]] && removeParalellLock && return 1 return 0 } @@ -571,10 +572,12 @@ processBitbucketSource() { } processLaunchpadSource() { + local launchpad_repo + if [[ "$launchpad" =~ (http|https) ]] ; then - local launchpad_repo=$(echo "$launchpad" | cut -d"/" -f4-99) + launchpad_repo=$(echo "$launchpad" | cut -d"/" -f4-99) - if [[ "$launchpad_repo" =~ "revision/" ]] ; then + if [[ "$launchpad_repo" =~ revision/ ]] ; then bzr=$(echo "$launchpad_repo" | cut -f1-3 -d"/") revision=$(echo "$launchpad_repo" | cut -f5 -d"/") else @@ -587,13 +590,15 @@ processLaunchpadSource() { parseSourceURL() { local spec="$1" - local url=$(getSpecValue "$MACRO_URL" "$spec") + + local url + url=$(getSpecValue "$MACRO_URL" "$spec") - if [[ "$url" =~ "github" ]] ; then + if [[ "$url" =~ github ]] ; then github="$url" - elif [[ "$url" =~ "bitbucket" ]] ; then + elif [[ "$url" =~ bitbucket ]] ; then bitbucket="$url" - elif [[ "$url" =~ "launchpad" ]] ; then + elif [[ "$url" =~ launchpad ]] ; then launchpad="$url" else return 1 @@ -625,16 +630,18 @@ downloadRemoteSources() { showSeparator "DOWNLOADING" - local source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") - local patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") + local source_file source_list patch_list files - local files="$source_list $patch_list" + source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") + patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") + + files="$source_list $patch_list" for source_file in $files ; do if [[ "$source_file" =~ ^(http|https|ftp) ]] ; then local source_file_name=$(basename "$source_file") - if [[ -f $download/$source_file_name ]] ; then + if [[ -f "$download/$source_file_name" ]] ; then show "File ${CL_CYAN}${source_file_name}${CL_NORM} already downloaded." continue fi From 6ef0e817c3b68a3d8dc33d2e22ca8573fd7a1fdc Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 18:26:45 -0500 Subject: [PATCH 14/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 80 ++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 56c600c..028926d 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -630,7 +630,7 @@ downloadRemoteSources() { showSeparator "DOWNLOADING" - local source_file source_list patch_list files + local source_file source_list source_file_name patch_list files source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") @@ -639,7 +639,7 @@ downloadRemoteSources() { for source_file in $files ; do if [[ "$source_file" =~ ^(http|https|ftp) ]] ; then - local source_file_name=$(basename "$source_file") + source_file_name=$(basename "$source_file") if [[ -f "$download/$source_file_name" ]] ; then show "File ${CL_CYAN}${source_file_name}${CL_NORM} already downloaded." @@ -699,18 +699,20 @@ remoteBuild() { remoteRunMultibuild() { local spec="$1" - local build_hosts=$(cat $remote) - local protect_user protect_pass protect_arch + local build_hosts protect_user protect_pass protect_arch + local host_info r_user r_pass r_arch + + build_hosts=$(cat "$remote") for build_host in $build_hosts ; do - local host_info=($(getURLVars "$build_host")) + host_info=($(getURLVars "$build_host")) host="${host_info[0]/-/}" - local r_user="${host_info[1]/-/}" - local r_pass="${host_info[2]/-/}" - local r_arch="${host_info[3]/-/}" + r_user="${host_info[1]/-/}" + r_pass="${host_info[2]/-/}" + r_arch="${host_info[3]/-/}" [[ ! $protect_user ]] && user="$r_user" [[ ! $protect_pass ]] && pass="$r_pass" @@ -723,27 +725,29 @@ remoteRunMultibuild() { remoteRunBuild() { local spec="$1" + local host_info r_file r_line r_arch tlines + if [[ "$remote" =~ :[0-9]{1,}$ ]] ; then - local r_file=$(echo "$remote" | cut -f1 -d":") - local r_line=$(echo "$remote" | cut -f2 -d":") - local tlines=$(cat $r_file | wc -l) + r_file=$(echo "$remote" | cut -f1 -d":") + r_line=$(echo "$remote" | cut -f2 -d":") + tlines=$(cat $r_file | wc -l) if [[ $r_line -gt $tlines ]] ; then show "\nError - file $r_file don't contain line with number $r_line." $RED return 1 fi - remote=$(sed -n ${r_line}p $r_file) + remote=$(sed -n "${r_line}p" "$r_file") fi if [[ "$remote" =~ @|~i ]] ; then - local host_info=($(getURLVars "$remote")) + host_info=($(getURLVars "$remote")) host="${host_info[0]/-/}" - local r_user="${host_info[1]/-/}" - local r_pass="${host_info[2]/-/}" - local r_arch="${host_info[3]/-/}" + r_user="${host_info[1]/-/}" + r_pass="${host_info[2]/-/}" + r_arch="${host_info[3]/-/}" user="${r_user:-$user}" pass="${r_pass:-$pass}" @@ -792,12 +796,14 @@ remoteCheckEnv() { remoteDepsInstall() { local spec="$1" - local rpmbuild_dir=$(getRPMBuildDir) - local specs_dir="$rpmbuild_dir/SPECS" + local rpmbuild_dir specs_dir yum_opts + + rpmbuild_dir=$(getRPMBuildDir) + specs_dir="$rpmbuild_dir/SPECS" show "Installing required packages for build...\n" - local yum_opts=$(getYumOpts "$verbose") + yum_opts=$(getYumOpts "$verbose") sshCommand "$user@$host" "sudo yum $yum_opts clean expire-cache && cd $specs_dir && sudo yum-builddep $yum_opts -y $spec" @@ -809,10 +815,12 @@ remoteDepsInstall() { remoteSpecValidate() { local spec="$1" - local rpmbuild_dir=$(getRPMBuildDir) - local specs_dir="$rpmbuild_dir/SPECS" + local rpmbuild_dir specs_dir result - local result=$(sshCommand "$user@$host" "cd $specs_dir && rpmlint $spec" 2> /dev/null) + rpmbuild_dir=$(getRPMBuildDir) + specs_dir="$rpmbuild_dir/SPECS" + + result=$(sshCommand "$user@$host" "cd $specs_dir && rpmlint $spec" 2> /dev/null) show "Spec file check result:" $CYAN show "$result" @@ -836,12 +844,14 @@ remoteSpecValidate() { remoteBuildProcess() { local spec="$1" - local spec_name=$(basename $spec) - local build_args=$(getBuildArgs) - local build_prfx=$(getBuildPrfx) - local rpmbuild_dir=$(getRPMBuildDir) - local specs_dir="$rpmbuild_dir/SPECS" + local spec_name build_args build_prfx rpmbuild_dir specs_dir + + spec_name=$(basename $spec) + build_args=$(getBuildArgs) + build_prfx=$(getBuildPrfx) + rpmbuild_dir=$(getRPMBuildDir) + specs_dir="$rpmbuild_dir/SPECS" if [[ ! $no_lint ]] ; then showSeparator "VALIDATION" @@ -865,23 +875,25 @@ remoteBuildProcess() { stopStatusObserver show "" - local has_errors=$(tail -1 $tmp_file | grep -v "exit 0") + local has_errors bld_time grc_time packages package_name + + has_errors=$(tail -1 "$tmp_file" | grep -v "exit 0") if [[ ! $has_errors ]] ; then build_end=$(now) - local bld_time=$(($build_end - $build_start)) - local grc_time=$(getGraceTime "$bld_time") + bld_time=$(( build_end - build_start )) + grc_time=$(getGraceTime "$bld_time") show "Build complete! Build took $grc_time." $GREEN showSeparator "PACKAGE PROCESSING" - local packages=$(cat $tmp_file | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") + packages=$(cat "$tmp_file" | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") for package in $packages ; do - package=$(echo $package | tr -dc '[:print:]') + package=$(echo "$package" | tr -dc '[:print:]') - local package_name=$(basename $package) + package_name=$(basename "$package") if [[ $sign ]] ; then show "Signing package ${CL_CYAN}$package_name${CL_NORM}..." @@ -931,7 +943,7 @@ remoteBuildProcess() { show "Last $LOG_QUOTE_SIZE lines from build log:" $RED showSeparator - tail -${LOG_QUOTE_SIZE} $tmp_file + tail -${LOG_QUOTE_SIZE} "$tmp_file" showSeparator fi From a73f61ce301d638d7a35b642060627764c1d0e0b Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 18:36:30 -0500 Subject: [PATCH 15/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 028926d..161cb8b 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -730,7 +730,7 @@ remoteRunBuild() { if [[ "$remote" =~ :[0-9]{1,}$ ]] ; then r_file=$(echo "$remote" | cut -f1 -d":") r_line=$(echo "$remote" | cut -f2 -d":") - tlines=$(cat $r_file | wc -l) + tlines=$(cat "$r_file" | wc -l) if [[ $r_line -gt $tlines ]] ; then show "\nError - file $r_file don't contain line with number $r_line." $RED @@ -847,7 +847,7 @@ remoteBuildProcess() { local spec_name build_args build_prfx rpmbuild_dir specs_dir - spec_name=$(basename $spec) + spec_name=$(basename "$spec") build_args=$(getBuildArgs) build_prfx=$(getBuildPrfx) rpmbuild_dir=$(getRPMBuildDir) @@ -867,9 +867,9 @@ remoteBuildProcess() { startStatusObserver if [[ $verbose ]] ; then - sshCommand "$user@$host" "cd $specs_dir && $build_prfx rpmbuild $spec_name $build_args" | tee $tmp_file &> $verb_output + sshCommand "$user@$host" "cd $specs_dir && $build_prfx rpmbuild $spec_name $build_args" | tee "$tmp_file" &> $verb_output else - sshCommand "$user@$host" "cd $specs_dir && $build_prfx rpmbuild $spec_name $build_args" 1> $tmp_file 2> /dev/null + sshCommand "$user@$host" "cd $specs_dir && $build_prfx rpmbuild $spec_name $build_args" 1> "$tmp_file" 2> /dev/null fi stopStatusObserver @@ -948,10 +948,12 @@ remoteBuildProcess() { fi if [[ $keep_log ]] ; then - local ldate=$(getLogDate) - local lname="${spec_name/.spec/}+$host+$ldate.log" + local ldate lname - cp $tmp_file $CWD/$lname + ldate=$(getLogDate) + lname="${spec_name/.spec/}+$host+$ldate.log" + + cp "$tmp_file" "$CWD/$lname" show "Build log saved to current dir as $lname" $BROWN fi @@ -1029,7 +1031,8 @@ localDepsInstall() { show "Installing required packages for build...\n" - local yum_opts=$(getYumOpts "$verbose") + local yum_opts + yum_opts=$(getYumOpts "$verbose") if [[ "$user" == "root" ]] ; then yum $yum_opts clean expire-cache @@ -1056,7 +1059,9 @@ localSpecValidate() { fi local spec="$1" - local result=$(rpmlint $spec) + + local result + local result=$(rpmlint "$spec") show "Spec file check result:" $CYAN show "$result" From 185bc04ee71038f2276422e77a8414c877661b73 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 18:55:00 -0500 Subject: [PATCH 16/33] rpmbuilder refactoring --- .codeclimate.yml | 2 ++ SOURCES/rpmbuilder | 42 +++++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 1a8f278..64529ca 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -8,6 +8,8 @@ engines: enabled: false SC2162: enabled: false + SC2163: + enabled: false ratings: paths: diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 161cb8b..1130f41 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -963,7 +963,9 @@ remoteBuildProcess() { } checkRemoteAvailability() { - local remote_available=$(sshCommand "$user@$host" "stat $BUILD_LOCK &> /dev/null || echo 1") + local remote_available + + remote_available=$(sshCommand "$user@$host" "stat $BUILD_LOCK &> /dev/null || echo 1") if [[ ! $remote_available ]] ; then showt "\r${CL_GREEN}Executing:${CL_NORM} ${CL_BROWN}waiting in queue${CL_NORM}" @@ -1010,7 +1012,7 @@ localBuild() { [[ $pack || $source_list ]] && packSources "$spec" - processSpec $spec + processSpec "$spec" show "All source files are ready for build." $GREEN @@ -1061,7 +1063,7 @@ localSpecValidate() { local spec="$1" local result - local result=$(rpmlint "$spec") + result=$(rpmlint "$spec") show "Spec file check result:" $CYAN show "$result" @@ -1085,14 +1087,16 @@ localSpecValidate() { localBuildProcess() { local spec="$1" - local spec_name=$(basename $spec) - local build_args=$(getBuildArgs) - local build_prfx=$(getBuildPrfx) - local rpmbuild_dir=$(getRPMBuildDir) - local specs_dir="$rpmbuild_dir/SPECS" + local spec_name build_args build_prfx rpmbuild_dir specs_dir + + spec_name=$(basename "$spec") + build_args=$(getBuildArgs) + build_prfx=$(getBuildPrfx) + rpmbuild_dir=$(getRPMBuildDir) + specs_dir="$rpmbuild_dir/SPECS" - local has_errors="" + local has_errors pushd $specs_dir &> /dev/null if [[ ! $no_lint ]] ; then @@ -1113,14 +1117,16 @@ localBuildProcess() { # We use eval in this case because using --define, contains quotes # and if we simply run command, we will get error + local exit_status pipe_status + if [[ $verbose ]] ; then export $build_prfx - eval "rpmbuild $build_args $spec_name" | tee $tmp_file &> $verb_output - local pipe_status=${PIPESTATUS[0]} + eval "rpmbuild $build_args $spec_name" | tee "$tmp_file" &> $verb_output + pipe_status=${PIPESTATUS[0]} else export $build_prfx - eval "rpmbuild $build_args $spec_name" &> $tmp_file - local exit_status=$? + eval "rpmbuild $build_args $spec_name" &> "$tmp_file" + exit_status=$? fi if [[ $verbose ]] ; then @@ -1141,15 +1147,17 @@ localBuildProcess() { show "Last $LOG_QUOTE_SIZE lines from build log:" $RED showSeparator - tail -${LOG_QUOTE_SIZE} $tmp_file + tail -${LOG_QUOTE_SIZE} "$tmp_file" showSeparator fi if [[ $keep_log ]] ; then - local ldate=$(getLogDate) - local lname="${spec_name/.spec/}+$ldate.log" + local ldate lname + + ldate=$(getLogDate) + lname="${spec_name/.spec/}+$ldate.log" - cp $tmp_file $CWD/$lname + cp "$tmp_file" "$CWD/$lname" show "Build log saved to current dir as $lname" $BROWN fi From 8882b8a070bf7adbb49e9edd571e9d9c2513f77e Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 19:03:14 -0500 Subject: [PATCH 17/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 70 ++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 1130f41..fcc387e 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -512,7 +512,7 @@ processBitbucketSource() { local bitbucket_user bitbucket_repo bitbucket_tag bitbucket_branch bitbucket_act local delim - + local is_branch is_tag is_git is_hg if [[ $hg ]] ; then @@ -590,7 +590,7 @@ processLaunchpadSource() { parseSourceURL() { local spec="$1" - + local url url=$(getSpecValue "$MACRO_URL" "$spec") @@ -876,7 +876,7 @@ remoteBuildProcess() { show "" local has_errors bld_time grc_time packages package_name - + has_errors=$(tail -1 "$tmp_file" | grep -v "exit 0") if [[ ! $has_errors ]] ; then @@ -964,7 +964,7 @@ remoteBuildProcess() { checkRemoteAvailability() { local remote_available - + remote_available=$(sshCommand "$user@$host" "stat $BUILD_LOCK &> /dev/null || echo 1") if [[ ! $remote_available ]] ; then @@ -1038,10 +1038,10 @@ localDepsInstall() { if [[ "$user" == "root" ]] ; then yum $yum_opts clean expire-cache - yum-builddep $yum_opts -y $spec + yum-builddep $yum_opts -y "$spec" else sudo yum $yum_opts clean expire-cache - sudo yum-builddep $yum_opts -y $spec + sudo yum-builddep $yum_opts -y "$spec" fi show "" @@ -1061,7 +1061,7 @@ localSpecValidate() { fi local spec="$1" - + local result result=$(rpmlint "$spec") @@ -1089,7 +1089,7 @@ localBuildProcess() { local spec="$1" local spec_name build_args build_prfx rpmbuild_dir specs_dir - + spec_name=$(basename "$spec") build_args=$(getBuildArgs) build_prfx=$(getBuildPrfx) @@ -1098,7 +1098,7 @@ localBuildProcess() { local has_errors - pushd $specs_dir &> /dev/null + pushd "$specs_dir" &> /dev/null if [[ ! $no_lint ]] ; then showSeparator "VALIDATION" localSpecValidate "$spec_name" @@ -1167,20 +1167,22 @@ localBuildProcess() { stopStatusObserver show "" + local bld_time grc_time package packages package_name + build_end=$(now) - local bld_time=$(($build_end - $build_start)) - local grc_time=$(getGraceTime "$bld_time") + bld_time=$(($build_end - $build_start)) + grc_time=$(getGraceTime "$bld_time") show "Build complete! Build took $grc_time." $GREEN showSeparator "PACKAGE PROCESSING" - local packages=$(cat $tmp_file | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") + packages=$(cat $tmp_file | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") rm -f $tmp_file for package in $packages ; do - local package_name=$(basename $package) + package_name=$(basename "$package") if [[ $sign ]] ; then localSign "$package" @@ -1189,9 +1191,9 @@ localBuildProcess() { fi if [[ $dest_dir ]] ; then - mv $package $dest_dir + mv "$package" "$dest_dir" else - mv $package $CWD + mv "$package" "$CWD" fi done @@ -1233,9 +1235,11 @@ checkLocalBuildAvailability() { return fi - local cdt=$(stat $BUILD_LOCK_LOCAL -c "%Y") - local ct=$(now) - local cdf=$(( $ct - $cdt )) + local cdt ct cdf + + cdt=$(stat "$BUILD_LOCK_LOCAL" -c "%Y") + ct=$(now) + cdf=$(( ct - cdt )) if [[ $cdf -gt $LOCK_TIME_MAX_DIFF ]] ; then show "We found lock file created more than 3 hours ago. It's too much time for usual build process." @@ -1257,27 +1261,30 @@ checkLocalBuildAvailability() { } hasLocalLock() { - [[ ! -f $BUILD_LOCK_LOCAL ]] && return 1 + [[ ! -f "$BUILD_LOCK_LOCAL" ]] && return 1 - local pid=$(cat $BUILD_LOCK_LOCAL) + local pid + pid=$(cat "$BUILD_LOCK_LOCAL") - [[ ! -d /proc/$pid ]] && removeLocalLock && return 1 + [[ ! -d "/proc/$pid" ]] && removeLocalLock && return 1 return 0 } createLocalLock() { - echo $$ > $BUILD_LOCK_LOCAL - chmod 666 $BUILD_LOCK_LOCAL + echo "$$" > $BUILD_LOCK_LOCAL + chmod 666 "$BUILD_LOCK_LOCAL" } removeLocalLock() { + local cur_user lock_owner + if [[ -f $BUILD_LOCK_LOCAL ]] ; then - local cur_user=$(whoami) - local lock_owner=$(stat $BUILD_LOCK_LOCAL -c "%U") + cur_user=$(whoami) + lock_owner=$(stat "$BUILD_LOCK_LOCAL" -c "%U") if [[ "$cur_user" == "$lock_owner" ]] ; then - rm -f $BUILD_LOCK_LOCAL &> /dev/null + rm -f "$BUILD_LOCK_LOCAL" &> /dev/null fi fi } @@ -1285,12 +1292,12 @@ removeLocalLock() { localSign() { local package="$1" - show "Signing package ${CL_CYAN}$package_name${CL_NORM}..." + show "Signing package ${CL_CYAN}${package_name}${CL_NORM}..." if [[ $verbose ]] ; then - rpm --addsign $package | tee $tmp_file &> $verb_output + rpm --addsign "$package" | tee "$tmp_file" &> $verb_output else - rpm --addsign $package &> $tmp_file + rpm --addsign "$package" &> $tmp_file fi if [[ $? -ne 0 ]] ; then @@ -1302,9 +1309,9 @@ releaseBump() { local spec="$1" if [[ $bump_comment ]] ; then - rpmdev-bumpspec -c "$bump_comment" $spec + rpmdev-bumpspec -c "$bump_comment" "$spec" else - rpmdev-bumpspec $spec + rpmdev-bumpspec "$spec" fi if [[ $? -ne 0 ]] ; then @@ -1314,6 +1321,7 @@ releaseBump() { prepareDeps() { local deps=$(echo "$@" | sed 's/ \(>\|>=\|=\) /\1/g') + local dep fdep result for dep in $deps ; do From d31a3a9a8fe7614220256fc84179b47178f4d80f Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 19:12:11 -0500 Subject: [PATCH 18/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index fcc387e..35bc516 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1177,7 +1177,7 @@ localBuildProcess() { showSeparator "PACKAGE PROCESSING" - packages=$(cat $tmp_file | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") + packages=$(cat "$tmp_file" | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") rm -f $tmp_file @@ -1197,7 +1197,7 @@ localBuildProcess() { fi done - pushd $CWD &> /dev/null + pushd "$CWD" &> /dev/null if [[ $post ]] ; then show "Executing post-build script..." @@ -1297,7 +1297,7 @@ localSign() { if [[ $verbose ]] ; then rpm --addsign "$package" | tee "$tmp_file" &> $verb_output else - rpm --addsign "$package" &> $tmp_file + rpm --addsign "$package" &> "$tmp_file" fi if [[ $? -ne 0 ]] ; then @@ -1320,9 +1320,9 @@ releaseBump() { } prepareDeps() { - local deps=$(echo "$@" | sed 's/ \(>\|>=\|=\) /\1/g') + local dep deps fdep result - local dep fdep result + deps=$(echo "$*" | sed 's/ \(>\|>=\|=\) /\1/g') for dep in $deps ; do if [[ $dep =~ :: ]] ; then @@ -1341,8 +1341,8 @@ prepareDeps() { uploadPackages() { local packages_dir="$1" local packages="$2" - local package_name - local package_list + + local package_name package_list target has_errors for package in $packages ; do package_name=$(basename $package) @@ -1353,20 +1353,21 @@ uploadPackages() { if [[ -f $upload ]] ; then if [[ -r $upload ]] ; then - local has_errors="" + has_errors="" + while read line ; do - local target=$(echo $line | cut -f1 -d":") + local target=$(echo "$line" | cut -f1 -d":") uploadPackagesToServer "$line" "$package_list" [[ $? -ne 0 ]] && has_errors=true - done < $upload + done < "$upload" show "" if [[ $has_errors ]] ; then show "All rpm packages saved to directory ${CL_CYAN}$packages_dir${CL_NORM}." else - rm -f $package_list + rm -f "$package_list" show "All rpm packages uploaded to all remote servers!" $GREEN fi else @@ -1375,14 +1376,14 @@ uploadPackages() { show "All rpm packages saved to directory ${CL_CYAN}$packages_dir${CL_NORM}." fi else - local target=$(echo $upload | cut -f1 -d":") + target=$(echo "$upload" | cut -f1 -d":") uploadPackagesToServer "$upload" "$package_list" show "" if [[ $? -eq 0 ]] ; then - rm -f $package_list + rm -f "$package_list" show "All rpm packages uploaded to remote server!" $GREEN else show "All rpm packages saved to directory ${CL_CYAN}$packages_dir${CL_NORM}." @@ -1393,29 +1394,28 @@ uploadPackages() { uploadPackagesToServer() { local url="$1" - if [[ $(echo $url | tr -dc ":" | wc -c) == "2" ]] ; then - local url_user_host=$(echo $url | cut -f1-2 -d":") - local url_user=$(echo $url_user_host | cut -f1 -d"@" | cut -f1 -d":") - local url_host=$(echo $url_user_host | cut -f2 -d"@") - local url_path=$(echo $url | cut -f2 -d":") + local url_user_host url_user url_host url_path package package_list package_name has_errors + + if [[ $(echo "$url" | tr -dc ":" | wc -c) == "2" ]] ; then + url_user_host=$(echo "$url" | cut -f1-2 -d":") + url_user=$(echo "$url_user_host" | cut -f1 -d"@" | cut -f1 -d":") + url_host=$(echo "$url_user_host" | cut -f2 -d"@") + url_path=$(echo "$url" | cut -f2 -d":") else - local url_user_host=$(echo $url | cut -f1 -d":") - local url_user=$(echo $url_user_host | cut -f1 -d"@") - local url_host=$(echo $url_user_host | cut -f2 -d"@") - local url_path=$(echo $url | cut -f2 -d":") + url_user_host=$(echo "$url" | cut -f1 -d":") + url_user=$(echo "$url_user_host" | cut -f1 -d"@") + url_host=$(echo "$url_user_host" | cut -f2 -d"@") + url_path=$(echo "$url" | cut -f2 -d":") fi - local package_list="$2" - local package_name - - show "Connecting to remote server ${CL_CYAN}$url_host${CL_NORM}..." + show "Connecting to remote server ${CL_CYAN}${url_host}${CL_NORM}..." if isRemoteServerReachable "$url_host" ; then if isSSHConnectionWorks "$url_user" "$url_host" ; then - local has_errors="" + has_errors="" for package in $package_list ; do - local package_name=$(basename $package) + package_name=$(basename "$package") scpCommand "$package" "$url" &> $verb_output From 2340b2e8b5b3b70ee4864284bd9bbe737e72a84f Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 19:32:41 -0500 Subject: [PATCH 19/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 165 +++++++++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 79 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 35bc516..071704a 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1341,11 +1341,11 @@ prepareDeps() { uploadPackages() { local packages_dir="$1" local packages="$2" - + local package_name package_list target has_errors for package in $packages ; do - package_name=$(basename $package) + package_name=$(basename "$package") package_list="$package_list $packages_dir/$package_name" done @@ -1354,9 +1354,9 @@ uploadPackages() { if [[ -f $upload ]] ; then if [[ -r $upload ]] ; then has_errors="" - + while read line ; do - local target=$(echo "$line" | cut -f1 -d":") + target=$(echo "$line" | cut -f1 -d":") uploadPackagesToServer "$line" "$package_list" [[ $? -ne 0 ]] && has_errors=true @@ -1456,10 +1456,12 @@ packSources() { doExit $ERROR_SOURCE fi - pack=$(cat $source_list) + pack=$(cat "$source_list") pack=$(renderMacros "$spec" "$pack") fi + local src_target sources arch_name arch_ext + for src_target in $pack ; do if [[ ! -a $src_target ]] ; then show "Can't pack sources - $src_target not exist or not accesable." $RED @@ -1467,27 +1469,27 @@ packSources() { fi done - local sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - local arch_name=$(getArchName "${sources[0]}") - local arch_ext=$(getArchExt "${sources[0]}") + sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) + arch_name=$(getArchName "${sources[0]}") + arch_ext=$(getArchExt "${sources[0]}") - mkdir -p $tmp_dir/$arch_name + mkdir -p "$tmp_dir/$arch_name" if [[ ! $relative_pack ]] ; then - cp -r $pack $tmp_dir/$arch_name &> /dev/null + cp -r "$pack" "$tmp_dir/$arch_name" &> /dev/null else - cp -r --parents $pack $tmp_dir/$arch_name &> /dev/null + cp -r --parents "$pack" "$tmp_dir/$arch_name" &> /dev/null fi cleanPackDir "$tmp_dir/$arch_name" - pushd $tmp_dir &> /dev/null + pushd "$tmp_dir" &> /dev/null - packDir $tmp_dir/$arch_name $arch_ext + packDir "$tmp_dir/$arch_name" "$arch_ext" popd &> /dev/null - rm -rf $tmp_dir/$arch_name + rm -rf "$tmp_dir/$arch_name" show "All files packed to ${arch_name}.${arch_ext}." $GREEN } @@ -1497,44 +1499,46 @@ packSourcesFromGit() { show "Fetching sources from git repo ${CL_CYAN}$git${CL_NORM}..." - local sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - local source_name=$(getArchName "${sources[0]}") - local source_ext=$(getArchExt "${sources[0]}") + local sources source_name source_ext dir_name git_log abs_dir_path - local dir_name=$(mktemp -u $source_name-XXXX) + sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) + source_name=$(getArchName "${sources[0]}") + source_ext=$(getArchExt "${sources[0]}") - local git_log="$tmp_dir/git.log" + dir_name=$(mktemp -u "$source_name-XXXX") - pushd $tmp_dir &> /dev/null + git_log="$tmp_dir/git.log" + + pushd "$tmp_dir" &> /dev/null git=$(renderMacros "$spec" "$git") - [[ $verbose ]] && git clone $git $dir_name | tee -a $git_log || git clone $git $dir_name &> $git_log + [[ $verbose ]] && git clone "$git" "$dir_name" | tee -a "$git_log" || git clone "$git" "$dir_name" &> $git_log if [[ $? -ne 0 ]] ; then show "Can't clone repo - error while cloning." $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($git_log):" - tail -${REPO_LOG_QUOTE_SIZE} $git_log + tail -${REPO_LOG_QUOTE_SIZE} "$git_log" show "" fi doExit $ERROR_SOURCE fi - pushd $tmp_dir/$dir_name &> /dev/null + pushd "$tmp_dir/$dir_name" &> /dev/null if [[ $branch ]] ; then branch=$(renderMacros "$spec" "$branch") - [[ $verbose ]] && git checkout $branch | tee -a $git_log || git checkout $branch &> $git_log + [[ $verbose ]] && git checkout "$branch" | tee -a "$git_log" || git checkout "$branch" &> "$git_log" if [[ $? -ne 0 ]] ; then show "Can't switch branch to $branch:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($git_log):" - tail -${REPO_LOG_QUOTE_SIZE} $git_log + tail -${REPO_LOG_QUOTE_SIZE} "$git_log" show "" fi @@ -1543,14 +1547,14 @@ packSourcesFromGit() { fi if [[ $revision ]] ; then - [[ $verbose ]] && git checkout $revision | tee -a $git_log || git checkout $revision &> $git_log + [[ $verbose ]] && git checkout "$revision" | tee -a "$git_log" || git checkout "$revision" &> "$git_log" if [[ $? -ne 0 ]] ; then show "Can't checkout revision $revision:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($git_log):" - tail -${REPO_LOG_QUOTE_SIZE} $git_log + tail -${REPO_LOG_QUOTE_SIZE} "$git_log" show "" fi @@ -1559,14 +1563,14 @@ packSourcesFromGit() { elif [[ $tag ]] ; then tag=$(renderMacros "$spec" "$tag") - [[ $verbose ]] && git checkout $tag | tee -a $git_log || git checkout $tag &> $git_log + [[ $verbose ]] && git checkout "$tag" | tee -a "$git_log" || git checkout "$tag" &> "$git_log" if [[ $? -ne 0 ]] ; then show "Can't checkout tag $tag:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($git_log):" - tail -${REPO_LOG_QUOTE_SIZE} $git_log + tail -${REPO_LOG_QUOTE_SIZE} "$git_log" show "" fi @@ -1574,26 +1578,26 @@ packSourcesFromGit() { fi fi - rm -rf .git .gitignore $git_log &> /dev/null + rm -rf .git .gitignore "$git_log" &> /dev/null popd &> /dev/null if [[ $path ]] ; then - if [[ ! -d $dir_name/$path ]] ; then + if [[ ! -d "$dir_name/$path" ]] ; then show "Can't find path [$path] in git repository." $RED doExit $ERROR_SOURCE else - mv $dir_name/$path $source_name - rm -rf $dir_name + mv "$dir_name/$path" "$source_name" + rm -rf "$dir_name" fi else - mv $dir_name $source_name + mv "$dir_name" "$source_name" fi - local abs_dir_path=$(getAbsPath $tmp_dir/$source_name) + abs_dir_path=$(getAbsPath "$tmp_dir/$source_name") packDir "$abs_dir_path" "$source_ext" - rm -rf $source_name + rm -rf "$source_name" popd &> /dev/null @@ -1605,44 +1609,46 @@ packSourcesFromHg() { show "Fetching sources from hg repo ${CL_CYAN}$hg${CL_NORM}..." - local sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - local source_name=$(getArchName "${sources[0]}") - local source_ext=$(getArchExt "${sources[0]}") + local sources source_name source_ext dir_name hg_log abs_dir_path - local dir_name=$(mktemp -u $source_name-XXXX) + sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) + source_name=$(getArchName "${sources[0]}") + source_ext=$(getArchExt "${sources[0]}") - local hg_log="$tmp_dir/hg.log" + dir_name=$(mktemp -u "$source_name-XXXX") - pushd $tmp_dir &> /dev/null + hg_log="$tmp_dir/hg.log" + + pushd "$tmp_dir" &> /dev/null hg=$(renderMacros "$spec" "$hg") - [[ $verbose ]] && hg clone $hg $dir_name | tee -a $hg_log || hg clone $hg $dir_name &> $hg_log + [[ $verbose ]] && hg clone "$hg" "$dir_name" | tee -a "$hg_log" || hg clone "$hg" "$dir_name" &> "$hg_log" if [[ $? -ne 0 ]] ; then show "Can't clone repo - error while cloning." $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($hg_log):" - tail -${REPO_LOG_QUOTE_SIZE} $hg_log + tail -${REPO_LOG_QUOTE_SIZE} "$hg_log" show "" fi doExit $ERROR_SOURCE fi - pushd $tmp_dir/$dir_name &> /dev/null + pushd "$tmp_dir/$dir_name" &> /dev/null if [[ $branch ]] ; then branch=$(renderMacros "$spec" "$branch") - [[ $verbose ]] && hg checkout $branch | tee -a $hg_log || hg checkout $branch &> $hg_log + [[ $verbose ]] && hg checkout "$branch" | tee -a "$hg_log" || hg checkout "$branch" &> "$hg_log" if [[ $? -ne 0 ]] ; then show "Can't switch branch to $branch:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($hg_log):" - tail -${REPO_LOG_QUOTE_SIZE} $hg_log + tail -${REPO_LOG_QUOTE_SIZE} "$hg_log" show "" fi @@ -1651,14 +1657,14 @@ packSourcesFromHg() { fi if [[ $revision ]] ; then - [[ $verbose ]] && hg checkout $revision | tee -a $hg_log || hg checkout $revision &> $hg_log + [[ $verbose ]] && hg checkout "$revision" | tee -a "$hg_log" || hg checkout "$revision" &> "$hg_log" if [[ $? -ne 0 ]] ; then show "Can't checkout revision $revision:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($hg_log):" - tail -${REPO_LOG_QUOTE_SIZE} $hg_log + tail -${REPO_LOG_QUOTE_SIZE} "$hg_log" show "" fi @@ -1667,14 +1673,14 @@ packSourcesFromHg() { elif [[ $tag ]] ; then tag=$(renderMacros "$spec" "$tag") - [[ $verbose ]] && hg checkout $tag | tee -a $hg_log || hg checkout $tag &> $hg_log + [[ $verbose ]] && hg checkout "$tag" | tee -a "$hg_log" || hg checkout "$tag" &> "$hg_log" if [[ $? -ne 0 ]] ; then show "Can't checkout tag $tag:" $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($hg_log):" - tail -${REPO_LOG_QUOTE_SIZE} $hg_log + tail -${REPO_LOG_QUOTE_SIZE} "$hg_log" show "" fi @@ -1682,26 +1688,26 @@ packSourcesFromHg() { fi fi - rm -rf .hg .hgignore $hg_log &> /dev/null + rm -rf .hg .hgignore "$hg_log" &> /dev/null popd &> /dev/null if [[ $path ]] ; then - if [[ ! -d $dir_name/$path ]] ; then + if [[ ! -d "$dir_name/$path" ]] ; then show "Can't find path [$path] in git repository." $RED doExit $ERROR_SOURCE else - mv $dir_name/$path $source_name - rm -rf $dir_name + mv "$dir_name/$path" "$source_name" + rm -rf "$dir_name" fi else - mv $dir_name $source_name + mv "$dir_name" "$source_name" fi - local abs_dir_path=$(getAbsPath $tmp_dir/$source_name) + abs_dir_path=$(getAbsPath "$tmp_dir/$source_name") packDir "$abs_dir_path" "$source_ext" - rm -rf $source_name + rm -rf "$source_name" popd &> /dev/null @@ -1709,49 +1715,50 @@ packSourcesFromHg() { } packSourcesFromBzr() { - local spec=$(getAbsPath $1) + local spec=$(getAbsPath "$1") - show "Fetching sources from bzr repo ${CL_CYAN}$bzr${CL_NORM}..." + show "Fetching sources from bzr repo ${CL_CYAN}${bzr}${CL_NORM}..." - local sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - local source_name=$(getArchName ${sources[0]}) - local source_ext=$(getArchExt ${sources[0]}) + local sources source_name source_ext dir_name bzr_log bzr_opts abs_dir_path + + sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) + source_name=$(getArchName ${sources[0]}) + source_ext=$(getArchExt ${sources[0]}) bzr=$(renderMacros "$spec" "$bzr") - local dir_name=$(mktemp -u $source_name-XXXX) - local bzr_log="$tmp_dir/bzr.log" - local bzr_opts + dir_name=$(mktemp -u "$source_name-XXXX") + bzr_log="$tmp_dir/bzr.log" - pushd $tmp_dir &> /dev/null + pushd "$tmp_dir" &> /dev/null [[ $tag ]] && bzr_opts="-r tag:$tag" - [[ $verbose ]] && bzr $bzr_opts branch $bzr $dir_name | tee -a $bzr_log || bzr $bzr_opts branch $bzr $dir_name &> $bzr_log + [[ $verbose ]] && bzr $bzr_opts branch "$bzr" "$dir_name" | tee -a "$bzr_log" || bzr $bzr_opts branch "$bzr" "$dir_name" &> "$bzr_log" if [[ $? -ne 0 ]] ; then show "Can't make a copy of branch." $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($bzr_log):" - tail -${REPO_LOG_QUOTE_SIZE} $bzr_log + tail -${REPO_LOG_QUOTE_SIZE} "$bzr_log" show "" fi doExit $ERROR_SOURCE fi - pushd $tmp_dir/$dir_name &> /dev/null + pushd "$tmp_dir/$dir_name" &> /dev/null if [[ $revision ]] ; then - [[ $verbose ]] && bzr revert -r${revision} | tee -a $bzr_log || bzr revert -r${revision} &> $bzr_log + [[ $verbose ]] && bzr revert -r${revision} | tee -a "$bzr_log" || bzr revert -r${revision} &> "$bzr_log" if [[ $? -ne 0 ]] ; then show "Can't revert to revision [$revision]." $RED if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($bzr_log):" - tail -${REPO_LOG_QUOTE_SIZE} $bzr_log + tail -${REPO_LOG_QUOTE_SIZE} "$bzr_log" show "" fi @@ -1759,26 +1766,26 @@ packSourcesFromBzr() { fi fi - rm -rf .bzr .bzrignore $bzr_log &> /dev/null + rm -rf .bzr .bzrignore "$bzr_log" &> /dev/null popd &> /dev/null if [[ $path ]] ; then - if [[ ! -d $dir_name/$path ]] ; then + if [[ ! -d "$dir_name/$path" ]] ; then show "Can't find path [$path] in bzr repository." $RED doExit $ERROR_SOURCE else - mv $dir_name/$path $source_name - rm -rf $dir_name + mv "$dir_name/$path" "$source_name" + rm -rf "$dir_name" fi else - mv $dir_name $source_name + mv "$dir_name" "$source_name" fi - local abs_dir_path=$(getAbsPath $tmp_dir/$source_name) + abs_dir_path=$(getAbsPath "$tmp_dir/$source_name") packDir "$abs_dir_path" "$source_ext" - rm -rf $source_name + rm -rf "$source_name" popd &> /dev/null From 7ea35dcb2e7df83a5c2dffe244b2c5ec80743ed5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 19:46:43 -0500 Subject: [PATCH 20/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 119 +++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 54 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 071704a..3053e41 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1179,7 +1179,7 @@ localBuildProcess() { packages=$(cat "$tmp_file" | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") - rm -f $tmp_file + rm -f "$tmp_file" for package in $packages ; do package_name=$(basename "$package") @@ -1489,13 +1489,15 @@ packSources() { popd &> /dev/null - rm -rf "$tmp_dir/$arch_name" + rm -rf "${tmp_dir:?}/$arch_name" show "All files packed to ${arch_name}.${arch_ext}." $GREEN } packSourcesFromGit() { - local spec=$(getAbsPath $1) + local spec + + spec=$(getAbsPath "$1") show "Fetching sources from git repo ${CL_CYAN}$git${CL_NORM}..." @@ -1512,7 +1514,7 @@ packSourcesFromGit() { pushd "$tmp_dir" &> /dev/null git=$(renderMacros "$spec" "$git") - [[ $verbose ]] && git clone "$git" "$dir_name" | tee -a "$git_log" || git clone "$git" "$dir_name" &> $git_log + [[ $verbose ]] && git clone "$git" "$dir_name" | tee -a "$git_log" || git clone "$git" "$dir_name" &> "$git_log" if [[ $? -ne 0 ]] ; then show "Can't clone repo - error while cloning." $RED @@ -1605,7 +1607,9 @@ packSourcesFromGit() { } packSourcesFromHg() { - local spec=$(getAbsPath $1) + local spec + + spec=$(getAbsPath "$1") show "Fetching sources from hg repo ${CL_CYAN}$hg${CL_NORM}..." @@ -1715,7 +1719,9 @@ packSourcesFromHg() { } packSourcesFromBzr() { - local spec=$(getAbsPath "$1") + local spec + + spec=$(getAbsPath "$1") show "Fetching sources from bzr repo ${CL_CYAN}${bzr}${CL_NORM}..." @@ -1793,19 +1799,22 @@ packSourcesFromBzr() { } packSourcesFromSvn() { - local spec=$(getAbsPath $1) + local spec + + spec=$(getAbsPath $1) show "Fetching sources from svn repo ${CL_CYAN}$svn${CL_NORM}..." - local sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - local source_name=$(getArchName ${sources[0]}) - local source_ext=$(getArchExt ${sources[0]}) + local sources source_name source_ext svn_opts svn_log abs_dir_path - svn=$(renderMacros "$spec" "$svn") + sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) + source_name=$(getArchName ${sources[0]}) + source_ext=$(getArchExt ${sources[0]}) - local svn_log="$tmp_dir/svn.log" + svn=$(renderMacros "$spec" "$svn") - local svn_opts="--non-interactive --no-auth-cache" + svn_log="$tmp_dir/svn.log" + svn_opts="--non-interactive --no-auth-cache" [[ $svn_user ]] && svn_opts="$svn_opts --username $svn_user" [[ $svn_pass ]] && svn_opts="$svn_opts --password $svn_pass" @@ -1827,18 +1836,18 @@ packSourcesFromSvn() { fi fi - pushd $tmp_dir &> /dev/null + pushd "$tmp_dir" &> /dev/null if [[ $path ]] ; then if [[ $verbose ]] ; then - svn checkout $svn_url ${source_name}_tmp $svn_opts | tee -a $svn_log + svn checkout "$svn_url" "${source_name}_tmp" $svn_opts | tee -a "$svn_log" else - svn checkout $svn_url ${source_name}_tmp $svn_opts &> $svn_log + svn checkout "$svn_url" "${source_name}_tmp" "$svn_opts" &> "$svn_log" fi else if [[ $verbose ]] ; then - svn checkout $svn_url ${source_name} $svn_opts | tee -a $svn_log + svn checkout "$svn_url" "${source_name}" $svn_opts | tee -a "$svn_log" else - svn checkout $svn_url ${source_name} $svn_opts &> $svn_log + svn checkout "$svn_url" "${source_name}" $svn_opts &> "$svn_log" fi fi @@ -1847,27 +1856,27 @@ packSourcesFromSvn() { if [[ ! $verbose ]] ; then show "\nLast ${REPO_LOG_QUOTE_SIZE} lines from log ($svn_log):" - tail -${REPO_LOG_QUOTE_SIZE} $svn_log + tail -${REPO_LOG_QUOTE_SIZE} "$svn_log" show "" fi doExit $ERROR_SOURCE else - rm -f $svn_log &> /dev/null + rm -f "$svn_log" &> /dev/null if [[ $path ]] ; then - if [[ ! -d ${source_name}_tmp/$path ]] ; then + if [[ ! -d "${source_name}_tmp/$path" ]] ; then show "Can't find path [$path] in svn repository." $RED doExit $ERROR_SOURCE else - mv ${source_name}_tmp/$path $source_name - rm -rf ${source_name}_tmp + mv "${source_name}_tmp/$path" "$source_name" + rm -rf "${source_name}_tmp" fi fi - find $source_name -type d -name ".svn" -exec rm -rf {} \; &> /dev/null + find "$source_name" -type d -name ".svn" -exec rm -rf {} \; &> /dev/null - local abs_dir_path=$(getAbsPath $tmp_dir/$source_name) + abs_dir_path=$(getAbsPath "$tmp_dir/$source_name") packDir "$abs_dir_path" "$source_ext" @@ -1882,13 +1891,14 @@ packSourcesFromSvn() { processSpec() { local spec="$1" - local source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") - local patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") + local source_list patch_list files source_file source_num file_name found_source - local files="$source_list $patch_list" + source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") + patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") + + files="$source_list $patch_list" - local source_file - local source_num=0 + source_num=0 for source_file in $files ; do if [[ $svn || $git || $hg || $bzr ]] ; then @@ -1896,21 +1906,20 @@ processSpec() { fi if [[ "$source_file" =~ (http|https|ftp) ]] ; then - local file_name=$(basename $source_file) - - local found_source=$(findSource "$file_name") + file_name=$(basename "$source_file") + found_source=$(findSource "$file_name") if [[ $found_source ]] ; then show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for build." - cp $found_source $tmp_dir - elif [[ -f $tmp_dir/$file_name ]] ; then + cp "$found_source" "$tmp_dir" + elif [[ -f "$tmp_dir/$file_name" ]] ; then show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for build." elif [[ $dlcache ]] ; then - if [[ -f $dlcache/$file_name ]] ; then + if [[ -f "$dlcache/$file_name" ]] ; then show "File ${CL_CYAN}$file_name${CL_NORM} listed in spec and will be used for build." - cp $dlcache/$file_name $tmp_dir + cp "$dlcache/$file_name" "$tmp_dir" else - show "Downloading source file ${CL_CYAN}$source_file${CL_NORM}..." + show "Downloading source file ${CL_CYAN}${source_file}${CL_NORM}..." downloadSource "$source_file" "$dlcache" @@ -1919,10 +1928,10 @@ processSpec() { doExit $ERROR_SOURCE fi - cp $dlcache/$file_name $tmp_dir + cp "$dlcache/$file_name" "$tmp_dir" fi else - show "Downloading source file ${CL_CYAN}$source_file${CL_NORM}..." + show "Downloading source file ${CL_CYAN}${source_file}${CL_NORM}..." downloadSource "$source_file" "$tmp_dir" @@ -1932,36 +1941,38 @@ processSpec() { fi fi else - if [[ -f $tmp_dir/$source_file ]] ; then - show "File ${CL_CYAN}$source_file${CL_NORM} listed in spec and will be used for build." - source_num=$(($source_num + 1)) && continue + if [[ -f "$tmp_dir/$source_file" ]] ; then + show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be used for build." + source_num=$(( source_num + 1 )) && continue fi - local source_ext=$(getArchExt $source_file) - local source_name=$(getArchName $source_file) - local found_dir=$(findSource "$source_name" true) - local found_source=$(findSource "$source_file") + local source_ext source_name found_dir found_source + + source_ext=$(getArchExt "$source_file") + source_name=$(getArchName "$source_file") + found_dir=$(findSource "$source_name" true) + found_source=$(findSource "$source_file") if [[ $source_ext && $found_dir ]] ; then - show "File ${CL_CYAN}$source_file${CL_NORM} listed in spec and will be created from sources directory." + show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be created from sources directory." packDir "$found_dir/$source_name" "$source_ext" - mv $found_dir/$source_file $tmp_dir + mv "$found_dir/$source_file" "$tmp_dir" - source_num=$(($source_num + 1)) && continue + source_num=$(( source_num + 1 )) && continue elif [[ $found_source ]] ; then - show "File ${CL_CYAN}$source_file${CL_NORM} listed in spec and will be used for build." + show "File ${CL_CYAN}${source_file}${CL_NORM} listed in spec and will be used for build." - cp $found_source $tmp_dir + cp "$found_source" "$tmp_dir" - source_num=$(($source_num + 1)) && continue + source_num=$(( source_num + 1 )) && continue else show "Can't use file $source_file for build - file not found in sources directory." $RED doExit $ERROR_SOURCE fi fi - source_num=$(($source_num + 1)) + source_num=$(( source_num + 1 )) done } From 22c2f3ef74fad16af83888cb6a2b9ef1dc5e01fb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:00:44 -0500 Subject: [PATCH 21/33] rpmbuilder refactoring --- .codeclimate.yml | 2 + SOURCES/rpmbuilder | 113 +++++++++++++++++++++++++-------------------- 2 files changed, 64 insertions(+), 51 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 64529ca..5f05919 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -2,6 +2,8 @@ engines: shellcheck: enabled: true checks: + SC2015: + enabled: false SC2034: enabled: false SC2154: diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 3053e41..c058aff 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1728,8 +1728,8 @@ packSourcesFromBzr() { local sources source_name source_ext dir_name bzr_log bzr_opts abs_dir_path sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - source_name=$(getArchName ${sources[0]}) - source_ext=$(getArchExt ${sources[0]}) + source_name=$(getArchName "${sources[0]}") + source_ext=$(getArchExt "${sources[0]}") bzr=$(renderMacros "$spec" "$bzr") @@ -1801,7 +1801,7 @@ packSourcesFromBzr() { packSourcesFromSvn() { local spec - spec=$(getAbsPath $1) + spec=$(getAbsPath "$1") show "Fetching sources from svn repo ${CL_CYAN}$svn${CL_NORM}..." @@ -1880,7 +1880,7 @@ packSourcesFromSvn() { packDir "$abs_dir_path" "$source_ext" - rm -rf $source_name + rm -rf "$source_name" fi popd &> /dev/null @@ -1980,10 +1980,10 @@ findSource() { local name="$1" local get_dir="$2" - local dir + local dir abs_dir if [[ $source_dir ]] ; then - if [[ -r $source_dir/$name ]] ; then + if [[ -r "$source_dir/$name" ]] ; then if [[ $get_dir ]] ; then echo "$source_dir" && return 0 else @@ -1992,9 +1992,9 @@ findSource() { fi else for dir in $SOURCE_PATHS ; do - local abs_dir=$(getAbsPath "$dir") + abs_dir=$(getAbsPath "$dir") - if [[ -r $abs_dir/$name ]] ; then + if [[ -r "$abs_dir/$name" ]] ; then if [[ $get_dir ]] ; then echo "$abs_dir" && return 0 else @@ -2010,21 +2010,21 @@ findSource() { copySourcesToBuildDir() { local spec="$1" - local has_errors="" - local rpmbuild_dir=$(getRPMBuildDir) - local src_dir="$rpmbuild_dir/SOURCES" - local specs_dir="$rpmbuild_dir/SPECS" + local rpmbuild_dir src_dir specs_dir source_file source_files source_file_name has_errors + + rpmbuild_dir=$(getRPMBuildDir) + src_dir="$rpmbuild_dir/SOURCES" + specs_dir="$rpmbuild_dir/SPECS" - if [[ -d $src_dir ]] ; then - local source_files=$(find $tmp_dir -maxdepth 1 -type f) + if [[ -d "$src_dir" ]] ; then + source_files=$(find "$tmp_dir" -maxdepth 1 -type f) for source_file in $source_files ; do - cp $source_file $src_dir &> /dev/null + cp "$source_file" "$src_dir" &> /dev/null if [[ $? -ne 0 ]] ; then - local source_file_name=$(basename $source_file) - show "Can't copy source file $source_file_name to directory $src_dir - error while - copy process." $RED + source_file_name=$(basename "$source_file") + show "Can't copy source file $source_file_name to directory $src_dir - error while copy process." $RED doExit $ERROR_SOURCE fi done @@ -2034,7 +2034,7 @@ copySourcesToBuildDir() { fi if [[ -d $specs_dir ]] ; then - cp $spec $specs_dir + cp "$spec" "$specs_dir" if [[ $? -ne 0 ]] ; then show "Can't copy spec file - error while copy process." @@ -2050,21 +2050,23 @@ copySourcesToBuildDir() { uploadSourcesToRemoteHost() { local spec="$1" - local rmpbuild_dir=$(getRPMBuildDir) - local source_files=$(find $tmp_dir -maxdepth 1 -type f) + local source_file source_files rmpbuild_dir + + rmpbuild_dir=$(getRPMBuildDir) + source_files=$(find "$tmp_dir" -maxdepth 1 -type f) for source_file in $source_files ; do - local source_file_name=$(basename $source_file) + source_file_name=$(basename "$source_file") - showt "${CL_CYAN}$source_file_name${CL_NORM}" 4 + showt "${CL_CYAN}${source_file_name}${CL_NORM}" 4 scpCommand "$source_file" "$user@$host:$rmpbuild_dir/SOURCES/" &> $verb_output show "DONE" $GREEN done - showt "${CL_CYAN}$spec${CL_NORM}" 4 + showt "${CL_CYAN}${spec}${CL_NORM}" 4 if [[ $bump ]] ; then cp $spec $tmp @@ -2072,7 +2074,7 @@ uploadSourcesToRemoteHost() { releaseBump "$tmp/$spec" scpCommand "$tmp/$spec" "$user@$host:$rmpbuild_dir/SPECS/" &> $verb_output - rm -f $tmp/$spec + rm -f "$tmp/$spec" else scpCommand "$spec" "$user@$host:$rmpbuild_dir/SPECS/" &> $verb_output fi @@ -2086,10 +2088,12 @@ downloadFromRemoteHost() { [[ ! $dir ]] && dir="$CWD" - local file_name=$(basename $file) + local file_name mod_ts + + file_name=$(basename "$file") if [[ -f $dir/$file_name ]] ; then - local mod_ts=$(stat -c "%Y" $dir/$file_name) + mod_ts=$(stat -c "%Y" "$dir/$file_name") if [[ $mod_ts -ge $build_start && $mod_ts -le $build_end ]] ; then return 1 @@ -2104,39 +2108,42 @@ downloadFromRemoteHost() { cleanPackDir() { local dir="$1" - find $dir -type d -name ".git" -exec rm -rf {} \; 2> /dev/null - find $dir -type d -name ".hg" -exec rm -rf {} \; 2> /dev/null - find $dir -type d -name ".svn" -exec rm -rf {} \; 2> /dev/null - find $dir -type d -name ".bzr" -exec rm -rf {} \; 2> /dev/null + find "$dir" -type d -name ".git" -exec rm -rf {} \; 2> /dev/null + find "$dir" -type d -name ".hg" -exec rm -rf {} \; 2> /dev/null + find "$dir" -type d -name ".svn" -exec rm -rf {} \; 2> /dev/null + find "$dir" -type d -name ".bzr" -exec rm -rf {} \; 2> /dev/null - find $dir -type f -name ".gitignore" -exec rm -f {} \; 2> /dev/null - find $dir -type f -name ".hgignore" -exec rm -f {} \; 2> /dev/null - find $dir -type f -name ".bzrignore" -exec rm -f {} \; 2> /dev/null - find $dir -type f -name ".gitignore" -exec rm -f {} \; 2> /dev/null + find "$dir" -type f -name ".gitignore" -exec rm -f {} \; 2> /dev/null + find "$dir" -type f -name ".hgignore" -exec rm -f {} \; 2> /dev/null + find "$dir" -type f -name ".bzrignore" -exec rm -f {} \; 2> /dev/null + find "$dir" -type f -name ".gitignore" -exec rm -f {} \; 2> /dev/null } packDir() { local dir="$1" local ext="$2" - local dir_name=$(basename $dir) - local parent_dir=$(dirname $dir) + + local dir_name parent_dir arch_name + + dir_name=$(basename "$dir") + parent_dir=$(dirname "$dir") if [[ $3 ]] ; then - local arch_name="$3" + arch_name="$3" else - local arch_name="$dir_name" + arch_name="$dir_name" fi - pushd $parent_dir &> /dev/null + pushd "$parent_dir" &> /dev/null if [[ "$ext" == "tar.gz" || "$ext" == "tgz" ]] ; then - tar czfv $arch_name.$ext $dir_name &> $verb_output + tar czfv "$arch_name.$ext" "$dir_name" &> $verb_output elif [[ "$ext" == "tar.bz2" || "$ext" == "tbz2" ]]; then - tar cjfv $arch_name.$ext $dir_name &> $verb_output + tar cjfv "$arch_name.$ext" "$dir_name" &> $verb_output elif [[ "$ext" == "tar.bz" || "$ext" == "tbz" ]]; then - tar cjfv $arch_name.$ext $dir_name &> $verb_output + tar cjfv "$arch_name.$ext" "$dir_name" &> $verb_output elif [[ "$ext" == "tar.xz" || "$ext" == "txz" ]] ; then - tar cf - $dir_name | xz -9 -c - > $arch_name.$ext + tar cf - "$dir_name" | xz -9 -c - > "$arch_name.$ext" else show "Error! Unknown archive type." $RED doExit $ERROR_SOURCE @@ -2149,18 +2156,20 @@ downloadSource() { local url="$1" local dir="$2" - local file_name=$(basename $url) + local file_name start end time_diff + + file_name=$(basename "$url") if ! isAccessibleUrl "$url" ; then show "Can't download file $file_name - server return error code." $RED doExit $ERROR_SOURCE else - local start=$(now) + start=$(now) - curl -L --max-redirs 10 --progress-bar $url -o $dir/$file_name + curl -L --max-redirs 10 --progress-bar "$url" -o "$dir/$file_name" - local end=$(now) - local time_diff=$(($end - $start)) + end=$(now) + time_diff=$(( end - start )) if [[ ! $tmuxl && ! $dlcache && $time_diff -gt $LONG_DOWNLOADING ]] ; then show "" @@ -2175,8 +2184,10 @@ getSpecValue() { local value="$1" local spec="$2" - local spec_header=$(grep -v "^#" $spec | grep -n "%prep" | head -1 | cut -f1 -d":") - local result=$(grep -v "^#" $spec | head -$spec_header | egrep "$value*.*:" | sed 's/[\t]/ /g' | tr -s " " | cut -f2-99 -d" " | sed 's/,/ /g') + local spec_header result + + spec_header=$(grep -v "^#" "$spec" | grep -n "%prep" | head -1 | cut -f1 -d":") + result=$(grep -v "^#" "$spec" | head "-$spec_header" | egrep "$value*.*:" | sed 's/[\t]/ /g' | tr -s " " | cut -f2-99 -d" " | sed 's/,/ /g') result=$(renderMacros "$spec" "$result") result=$(echo "$result" | sed 's/ = /=/g' | sed 's/ >= />=/g' | sed 's/ > />/g') From 673ee3bf7c11bd18626010ad63402c34f0ec9d56 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:11:02 -0500 Subject: [PATCH 22/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 106 +++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index c058aff..388589c 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -1808,8 +1808,8 @@ packSourcesFromSvn() { local sources source_name source_ext svn_opts svn_log abs_dir_path sources=($(getSpecValue "$MACRO_SOURCE" "$spec")) - source_name=$(getArchName ${sources[0]}) - source_ext=$(getArchExt ${sources[0]}) + source_name=$(getArchName "${sources[0]}") + source_ext=$(getArchExt" ${sources[0]}") svn=$(renderMacros "$spec" "$svn") @@ -2069,7 +2069,7 @@ uploadSourcesToRemoteHost() { showt "${CL_CYAN}${spec}${CL_NORM}" 4 if [[ $bump ]] ; then - cp $spec $tmp + cp "$spec" "$tmp" releaseBump "$tmp/$spec" scpCommand "$tmp/$spec" "$user@$host:$rmpbuild_dir/SPECS/" &> $verb_output @@ -2225,7 +2225,7 @@ getMacroValue() { if [[ "$MACRO" =~ $macro:([A-Za-z]*) ]] ; then local inner_macro="${BASH_REMATCH[1]}" - result=$(grep -v "^#" $spec | egrep "$inner_macro*.:" | sed 's/[\t]/ /g' | tr -s " " | cut -f2-99 -d" " | sed 's/,/ /g' | sed 's/ $//g' | head -1) + result=$(grep -v "^#" "$spec" | egrep "$inner_macro*.:" | sed 's/[\t]/ /g' | tr -s " " | cut -f2-99 -d" " | sed 's/,/ /g' | sed 's/ $//g' | head -1) fi if [[ ! $result ]] ; then @@ -2235,24 +2235,26 @@ getMacroValue() { fi if [[ ! $result ]] ; then - result=$(grep -v "^#" $spec | egrep "(^%define|^%global)" | sed 's/[\t]/ /g' | tr -s " " | egrep "(^%define|^%global) $macro " | cut -f3-99 -d" ") + result=$(grep -v "^#" "$spec" | egrep "(^%define|^%global)" | sed 's/[\t]/ /g' | tr -s " " | egrep "(^%define|^%global) $macro " | cut -f3-99 -d" ") fi echo "$result" } isAccessibleUrl() { + local status code nosniff size + if [[ "$1" =~ http:|https: ]] ; then - local status=$(curl $1 -LIs --max-redirs 10) - local code=$(echo -e "$status" | grep HTTP | cut -f2 -d" " | tail -1) - local nosniff=$(echo -e "$status" | grep "X-Content-Type-Options: nosniff") + status=$(curl "$1" -LIs --max-redirs 10) + code=$(echo -e "$status" | grep "HTTP" | cut -f2 -d" " | tail -1) + nosniff=$(echo -e "$status" | grep "X-Content-Type-Options: nosniff") # Nosniff mode works on Google Code, if we simple try check status server return # code 404, but we can download this file [[ -n $nosniff || "$code" == "200" ]] && return 0 || return 1 elif [[ "$1" =~ ftp: ]] ; then - local status=$(curl $1 -Is) - local size=$(echo $status | grep Content-Length | cut -f2 -d" ") + status=$(curl "$1" -Is) + size=$(echo "$status" | grep "Content-Length" | cut -f2 -d" ") [[ -n "$size" ]] && return 0 || return 1 else @@ -2265,12 +2267,13 @@ sshCommand() { local comm="$2" local no_pass="$3" - local ssh_opts=$(getSSHOpts) + local ssh_opts + ssh_opts=$(getSSHOpts) if [[ $pass && ! $no_pass ]] ; then - sshpass -p $pass ssh $SSH_BASE_OPTS -t -t -q $ssh_opts $host "$comm" + sshpass -p "$pass" ssh $SSH_BASE_OPTS -t -t -q $ssh_opts "$host" "$comm" else - ssh $SSH_BASE_OPTS -t -t -q $ssh_opts $host "$comm" + ssh $SSH_BASE_OPTS -t -t -q $ssh_opts "$host" "$comm" fi return $? @@ -2280,10 +2283,11 @@ scpCommand() { local from="$1" local to="$2" - local ssh_opts=$(getSSHOpts) + local ssh_opts + ssh_opts=$(getSSHOpts) if [[ $pass ]] ; then - sshpass -p $pass scp $SSH_BASE_OPTS $ssh_opts "$from" "$to" + sshpass -p "$pass" scp $SSH_BASE_OPTS $ssh_opts "$from" "$to" else scp $SSH_BASE_OPTS $ssh_opts "$from" "$to" fi @@ -2314,7 +2318,7 @@ getBuildArgs() { if [[ $define ]] ; then for def in $define ; do - args="$args --define=$def" + args="$args --define=\"$def\"" done fi @@ -2360,13 +2364,13 @@ isSSHConnectionWorks() { isRemoteServerReachable() { local host="$1" - ping -c 1 -w 5 $host &> /dev/null + ping -c 1 -w 5 "$host" &> /dev/null [[ $? -eq 0 ]] && return 0 || return 1 } getSSHOpts() { - local opts="" + local opts if [[ $key ]] ; then opts="$opts -i $key" @@ -2380,12 +2384,10 @@ getSSHOpts() { getYumOpts() { local verb="$1" - local opts + local opts repo [[ -z "$verb" ]] && opts="-q" - local repo - if [[ -n "$enable_repo" ]] ; then for repo in $enable_repo ; do opts="$opts --enablerepo=$repo" @@ -2410,19 +2412,21 @@ getRPMBuildDir() { } getArchName() { - local file_name=$(basename $1) - local arch_type + local file_name arch_type + + file_name=$(basename "$1") for arch_type in $SUPPORTED_ARCH_TYPES ; do - file_name=${file_name/.${arch_type}/} + file_name="${file_name/.${arch_type}/}" done echo $file_name } getArchExt() { - local file_name=$(basename $1) - local arch_type + local file_name arch_type + + file_name=$(basename "$1") for arch_type in $SUPPORTED_ARCH_TYPES ; do if [[ $file_name =~ $arch_type ]] ; then @@ -2436,26 +2440,27 @@ getArchExt() { } isSpecFile() { - [[ ! -r $1 ]] && return 1 - [[ ! $(grep "%prep" $1) ]] && return 1 + [[ ! -r "$1" ]] && return 1 + [[ ! $(grep "%prep" "$1") ]] && return 1 return 0 } getURLVars() { local url="$1" + local user pass user_pass host arch - if [[ "$url" =~ "~" ]] ; then + if [[ "$url" =~ ~ ]] ; then arch=$(echo "$url" | cut -f2 -d"~") url=$(echo "$url" | cut -f1 -d"~") fi - if [[ "$url" =~ "@" ]] ; then + if [[ "$url" =~ @ ]] ; then user_pass=$(echo "$url" | cut -f1 -d"@") host=$(echo "$url" | cut -f2 -d"@") - if [[ "$user_pass" =~ ":" ]] ; then + if [[ "$user_pass" =~ : ]] ; then user=$(echo "$user_pass" | cut -f1 -d":") pass=$(echo "$user_pass" | cut -f2 -d":") else @@ -2471,8 +2476,10 @@ getURLVars() { ############################################################################### checkDeps() { + local app + for app in $@ ; do - type -P $app &> /dev/null + type -P "$app" &> /dev/null [[ $? -eq 1 ]] && return 1 done @@ -2480,7 +2487,7 @@ checkDeps() { } getAbsPath() { - readlink -f $1 + readlink -f "$1" } doExit() { @@ -2499,8 +2506,8 @@ doExit() { } clean() { - rm -rf $tmp_dir - rm -f $tmp_file + rm -rf "${tmp_dir:?}" + rm -f "$tmp_file" } now() { @@ -2518,10 +2525,12 @@ getLogDate() { getGraceTime() { local tim="$1" + local sec min + [[ -z "$tim" || "$tim" == "0" ]] && echo "< 1 sec" && return 0 - local sec=$(($tim % 60)) - local min=$((($tim - $sec)/60)) + sec=$(( tim % 60 )) + min=$(( ( tim - sec ) / 60 )) if [[ $min -eq 0 ]] ; then echo "$sec sec" @@ -2542,8 +2551,8 @@ startStatusObserver() { stopStatusObserver() { [[ $verbose || ! $observer_pid ]] && return 0 - kill $observer_pid &> /dev/null - wait $observer_pid &> /dev/null + kill "$observer_pid" &> /dev/null + wait "$observer_pid" &> /dev/null showm "\r${CL_GREEN}Executing:${CL_NORM} ${CL_CYAN}clean${CL_NORM} " @@ -2551,13 +2560,13 @@ stopStatusObserver() { } statusObserver() { - local prev_status="" + local prev_status status while : ; do - local status=$(grep "Executing" $tmp_file | tail -1 | perl -ne '/Executing\(%(\w*)\)/ && print "$1\n"') + status=$(grep "Executing" $"tmp_file" | tail -1 | perl -ne '/Executing\(%(\w*)\)/ && print "$1\n"') if [[ "$status" == "doc" ]] ; then - [[ $(grep "Checking for unpackaged" $tmp_file) ]] && status="packaging" + [[ $(grep "Checking for unpackaged" "$tmp_file") ]] && status="packaging" fi if [[ "$status" != "$prev_status" ]] ; then @@ -2571,9 +2580,10 @@ statusObserver() { showSeparator() { local name="$1" + local adds if [[ $name ]] ; then - local adds=$((${#SEPARATOR} - ${#name} - 4)) + adds=$(( ${#SEPARATOR} - ${#name} - 4 )) show "\n${CL_GREY}--${CL_NORM} ${CL_BOLD}${name}${CL_NORM} ${CL_GREY}${SEPARATOR:0:$adds}${CL_NORM}\n" else @@ -2598,11 +2608,13 @@ showm() { } showt() { - local message=$(echo -e "$1" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") - local offset="${2-0}" - local spaces=" " + local message offset spaces adds + + message=$(echo -e "$1" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g") + offset="${2-0}" + spaces=" " - local adds=$((${#SEPARATOR} - ${#message} - $offset)) + adds=$((${#SEPARATOR} - ${#message} - $offset)) printf "${1}${spaces:0:$adds}" } From 7a76b856521b8855ef116cebc068b0fa646f5aad Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:16:29 -0500 Subject: [PATCH 23/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 388589c..66afb9b 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -2330,7 +2330,7 @@ getBuildPrfx() { [[ $qa_rpaths ]] && prfx="$prfx QA_RPATHS=$[ ${qa_rpaths//,/|} ]" - echo $prfx + echo "$prfx" } getBuildArgsWith() { @@ -2420,7 +2420,7 @@ getArchName() { file_name="${file_name/.${arch_type}/}" done - echo $file_name + echo "$file_name" } getArchExt() { @@ -2502,7 +2502,7 @@ doExit() { fi fi - exit ${1-0} + exit "${1-0}" } clean() { @@ -2616,7 +2616,7 @@ showt() { adds=$((${#SEPARATOR} - ${#message} - $offset)) - printf "${1}${spaces:0:$adds}" + echo -e -n "${1}${spaces:0:$adds}" } termExit() { @@ -2795,7 +2795,7 @@ argv="$@" ; argt="" while [[ -n "$1" ]] ; do if [[ "$1" =~ \ && -n "$argn" ]] ; then - declare $argn="$1" + declare "$argn=$1" unset argn && shift && continue elif [[ $1 =~ ^-{1}[a-zA-Z0-9]{1,2}+.*$ ]] ; then @@ -2811,7 +2811,7 @@ while [[ -n "$1" ]] ; do if [[ -z "$argn" ]] ; then argn=$arg else - [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare $argn=true + [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare "$argn=true" argn=$arg fi @@ -2821,7 +2821,7 @@ while [[ -n "$1" ]] ; do fi if [[ ${BASH_REMATCH[0]:0:1} == "!" ]] ; then - declare $argn=true ; unset argn ; argk=true + declare "$argn=true" ; unset argn ; argk=true else unset argk fi @@ -2840,7 +2840,7 @@ while [[ -n "$1" ]] ; do shift && continue fi - [[ -n "${!argm}" && $MERGEABLE_ARGS\ =~ $argm\ ]] && declare $argm="${!argm} ${arg[@]:1:99}" || declare $argm="${arg[@]:1:99}" + [[ -n "${!argm}" && $MERGEABLE_ARGS\ =~ $argm\ ]] && declare $argm="${!argm} ${arg[@]:1:99}" || declare "$argm=${arg[@]:1:99}" unset argm && shift && continue else @@ -2849,7 +2849,7 @@ while [[ -n "$1" ]] ; do if [[ -z "$argn" ]] ; then argn=$arg else - [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare $argn=true + [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare "$argn=true" argn=$arg fi @@ -2868,7 +2868,7 @@ while [[ -n "$1" ]] ; do fi else if [[ -n "$argn" ]] ; then - [[ -n "${!argn}" && $MERGEABLE_ARGS\ =~ $argn\ ]] && declare $argn="${!argn} $1" || declare $argn="$1" + [[ -n "${!argn}" && $MERGEABLE_ARGS\ =~ $argn\ ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" unset argn && shift && continue fi @@ -2878,7 +2878,7 @@ while [[ -n "$1" ]] ; do done -[[ -n "$argn" ]] && declare $argn=true +[[ -n "$argn" ]] && declare "$argn=true" unset arg argn argm argk From b0e0999a24c6610bdcbc0998ee4df1748b6e65b8 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:27:47 -0500 Subject: [PATCH 24/33] rpmbuilder refactoring --- .codeclimate.yml | 2 ++ SOURCES/rpmbuilder | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 5f05919..4e68068 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -12,6 +12,8 @@ engines: enabled: false SC2163: enabled: false + SC2143: + enabled: false ratings: paths: diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 66afb9b..f71f60e 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -187,7 +187,7 @@ main() { checkArgs - if [[ $parallel && $(cat "$remote" | wc -l) -gt 1 ]] ; then + if [[ $parallel && $(wc -l "$remote" | cut -f1 -d" ") -gt 1 ]] ; then parallelBuild $@ else local start_ts @@ -730,7 +730,7 @@ remoteRunBuild() { if [[ "$remote" =~ :[0-9]{1,}$ ]] ; then r_file=$(echo "$remote" | cut -f1 -d":") r_line=$(echo "$remote" | cut -f2 -d":") - tlines=$(cat "$r_file" | wc -l) + tlines=$(wc -l "$r_file" | cut -f1 -d" ") if [[ $r_line -gt $tlines ]] ; then show "\nError - file $r_file don't contain line with number $r_line." $RED @@ -1170,14 +1170,14 @@ localBuildProcess() { local bld_time grc_time package packages package_name build_end=$(now) - bld_time=$(($build_end - $build_start)) + bld_time=$(( build_end - build_start )) grc_time=$(getGraceTime "$bld_time") show "Build complete! Build took $grc_time." $GREEN showSeparator "PACKAGE PROCESSING" - packages=$(cat "$tmp_file" | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") + packages=$(egrep "rpmbuild/(S|)RPMS" "$tmp_file" | cut -f2 -d" ") rm -f "$tmp_file" @@ -2192,7 +2192,7 @@ getSpecValue() { result=$(renderMacros "$spec" "$result") result=$(echo "$result" | sed 's/ = /=/g' | sed 's/ >= />=/g' | sed 's/ > />/g') - [[ "$value" == "$MACRO_SOURCE" || "$value" == "$MACRO_PATCH" ]] && echo "$result" | sed 's/ /%20/g' || echo "$result" + [[ "$value" == "$MACRO_SOURCE" || "$value" == "$MACRO_PATCH" ]] && echo "${result// /%20}" || echo "$result" } renderMacros() { From d5e4d3260901a07f4d8c38b648747236ec7eaece Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:32:55 -0500 Subject: [PATCH 25/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index f71f60e..a85d043 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -888,7 +888,7 @@ remoteBuildProcess() { showSeparator "PACKAGE PROCESSING" - packages=$(cat "$tmp_file" | egrep "rpmbuild/(S|)RPMS" | cut -f2 -d" ") + packages=$(egrep "rpmbuild/(S|)RPMS" "$tmp_file" | cut -f2 -d" ") for package in $packages ; do package=$(echo "$package" | tr -dc '[:print:]') @@ -2774,13 +2774,13 @@ about() { unset arg argn argp -PREFS_FILE=${PREFS_FILE//\~/$HOME} +PREFS_FILE="${PREFS_FILE//\~/$HOME}" -if [[ -n "$PREFS_FILE" && -r $PREFS_FILE ]] ; then +if [[ -n "$PREFS_FILE" && -r "$PREFS_FILE" ]] ; then while read arg ; do arg="${arg/: /:}" ; argn="${arg%:*}" ; argp="${arg#*:}" - [[ "$SUPPORTED_ARGS " =~ "$argn " ]] && declare $argn="$argp" - done < <(awk 1 $PREFS_FILE) + [[ "$SUPPORTED_ARGS " =~ $argn\ ]] && declare "$argn=$argp" + done < <(awk 1 "$PREFS_FILE") unset arg argn argp fi @@ -2791,7 +2791,7 @@ fi unset arg argn argm argv argt argk -argv="$@" ; argt="" +argv="$*" ; argt="" while [[ -n "$1" ]] ; do if [[ "$1" =~ \ && -n "$argn" ]] ; then @@ -2840,7 +2840,7 @@ while [[ -n "$1" ]] ; do shift && continue fi - [[ -n "${!argm}" && $MERGEABLE_ARGS\ =~ $argm\ ]] && declare $argm="${!argm} ${arg[@]:1:99}" || declare "$argm=${arg[@]:1:99}" + [[ -n "${!argm}" && $MERGEABLE_ARGS\ =~ $argm\ ]] && declare "$argm=${!argm} ${arg[@]:1:99}" || declare "$argm=${arg[@]:1:99}" unset argm && shift && continue else @@ -2859,7 +2859,7 @@ while [[ -n "$1" ]] ; do fi if [[ ${BASH_REMATCH[0]:0:1} == "!" ]] ; then - declare $argn=true ; unset argn ; argk=true + declare "$argn=true" ; unset argn ; argk=true else unset argk fi From e281f4937c3e0c915c794f83299866b58ad176af Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:43:00 -0500 Subject: [PATCH 26/33] Readme updated --- readme.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index 5b97820..af70259 100644 --- a/readme.md +++ b/readme.md @@ -1,16 +1,16 @@ -### RPMBuilder +## RPMBuilder [![Code Climate](https://codeclimate.com/github/essentialkaos/rpmbuilder/badges/gpa.svg)](https://codeclimate.com/github/essentialkaos/rpmbuilder) `rpmbuilder` is RPM package build helper -#### Usage demo +### Usage demo Building redis rpm on three remote build nodes: [![asciicast](https://essentialkaos.com/github/rpmbuilder-115.gif)](https://asciinema.org/a/90959) -#### Installation +### Installation -###### From ESSENTIAL KAOS Public repo for RHEL6/CentOS6 +##### From ESSENTIAL KAOS Public repo for RHEL6/CentOS6 ``` sudo yum install -y http://release.yum.kaos.io/i386/kaos-repo-6.8-0.el6.noarch.rpm @@ -26,7 +26,7 @@ sudo passwd builder sudo service buildmon start ``` -#### Usage +### Usage ``` Usage: rpmbuilder @@ -148,10 +148,10 @@ Other: ``` -#### Contributing +### Contributing Before contributing to this project please read our [Contributing Guidelines](https://github.com/essentialkaos/contributing-guidelines#contributing-guidelines). -#### License +### License [EKOL](https://essentialkaos.com/ekol) From d6126689e48dab8f1c567d202d7d107a95f7edf0 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:45:13 -0500 Subject: [PATCH 27/33] Readme updated --- readme.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index af70259..94c3c4a 100644 --- a/readme.md +++ b/readme.md @@ -10,16 +10,32 @@ Building redis rpm on three remote build nodes: ### Installation -##### From ESSENTIAL KAOS Public repo for RHEL6/CentOS6 +##### From ESSENTIAL KAOS Public repository for RHEL6/CentOS6 ``` -sudo yum install -y http://release.yum.kaos.io/i386/kaos-repo-6.8-0.el6.noarch.rpm +sudo yum install -y https://yum.kaos.io/6/release/i386/kaos-repo-7.0-0.el6.noarch.rpm sudo yum install rpmbuilder ``` Build node: ``` -sudo yum install -y http://release.yum.kaos.io/i386/kaos-repo-6.8-0.el6.noarch.rpm +sudo yum install -y https://yum.kaos.io/6/release/i386/kaos-repo-7.0-0.el6.noarch.rpm +sudo yum install rpmbuilder-node +sudo passwd builder +... change builder user password here +sudo service buildmon start +``` + +##### From ESSENTIAL KAOS Public repository for RHEL7/CentOS7 + +``` +sudo yum install -y https://yum.kaos.io/7/release/x86_64/kaos-repo-7.0-0.el7.noarch.rpm +sudo yum install rpmbuilder +``` + +Build node: +``` +sudo yum install -y https://yum.kaos.io/7/release/x86_64/kaos-repo-7.0-0.el7.noarch.rpm sudo yum install rpmbuilder-node sudo passwd builder ... change builder user password here From cf7e7a0f56a9b25459111ea93d07abbaa0b569fb Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 14 Nov 2016 20:47:04 -0500 Subject: [PATCH 28/33] Readme updated --- readme.md | 102 +++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/readme.md b/readme.md index 94c3c4a..d488070 100644 --- a/readme.md +++ b/readme.md @@ -45,7 +45,7 @@ sudo service buildmon start ### Usage ``` -Usage: rpmbuilder +Usage: rpmbuilder {spec-file} {options} Spec file: @@ -55,33 +55,33 @@ Spec file: Source packaging: - --pack, -p files Pack specified files to tgz archive with default source name (mergeable) - --relative-pack, -R Use relative path in source archive instead of absolute - --source-dir, -sd path Path to directory which contains source files specified in spec file - --source-list, -sl file Path to file which contains list of source files specified in spec file, - and will be packed to tgz archive with default source name - --dlcache, -dc path Path to directory for downloads caching - --download, -dl path Download all remote sources to specified directory - - --git url Fetch sources from Git repository (macro supported) - --svn url Fetch sources from SVN repository (macro supported) - --hg url Fetch sources from Mercurial repository (macro supported) - --bzr url Fetch sources from Bazar repository (macro supported) - --path, -rp path Path to directory with sources in repo - --branch, -rb name Use specified repository branch (macro supported) - --revision, -rr name Use specified revision - --tag, -rt name Use specified tag (macro supported) - --svn-user, -su username Username for access to svn repository - --svn-pass, -sp password Password for access to svn repository - - --github, -gh url Fetch sources from github.com repository by url (macro supported) - --github, -gh user>:/:/:" Define MACRO with value (exist macro will be not redefined) + --with, -w params Pass conditional parameters into a rpmbuild (mergeable) + --without, -W params Pass conditional parameters into a rpmbuild (mergeable) + --define, -D "" Define MACRO with value (exist macro will be not redefined) (mergeable) Examples: @@ -146,21 +146,21 @@ Arguments passing: Spec validation: - --no-lint, -0 Don't check spec file before package build - --strict, -1 Don't build package if linter found errors in spec file - --pedantic, -2 Don't build package if linter found errors or warnings in spec file + --no-lint, -0 Don't check spec file before package build + --strict, -1 Don't build package if linter found errors in spec file + --pedantic, -2 Don't build package if linter found errors or warnings in spec file Other: - --sign, -s Sign package after build - --dest, --dest-dir, -d path Save builded packages to specified directory - --keep-log, -kl Save build log after unsuccessful build - --bump, -b Bump release in spec file after successful package build - --bump-comment, -bc comment Comment which will be added while release bump - --tmp path Path to temporary directory - --verbose, -V Verbose output - --help, --usage, -h Show this help message - --ver, --version, -v Show information about version + --sign, -s Sign package after build + --dest, --dest-dir, -d path Save builded packages to specified directory + --keep-log, -kl Save build log after unsuccessful build + --bump, -b Bump release in spec file after successful package build + --bump-comment, -bc comment Comment which will be added while release bump + --tmp path Path to temporary directory + --verbose, -V Verbose output + --help, --usage, -h Show this help message + --ver, --version, -v Show information about version ``` From e964d1e4f0e877fc05cf2a7dca8076c057efe5b1 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 15 Nov 2016 05:10:12 -0500 Subject: [PATCH 29/33] rpmbuilder refactoring --- SOURCES/rpmbuilder | 8 ++++---- SOURCES/rpmunbuilder | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index a85d043..ea6da52 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -188,7 +188,7 @@ main() { checkArgs if [[ $parallel && $(wc -l "$remote" | cut -f1 -d" ") -gt 1 ]] ; then - parallelBuild $@ + parallelBuild "$@" else local start_ts start_ts=$(now) @@ -261,7 +261,7 @@ parallelBuild() { local args="" local arg - for arg in $@ ; do + for arg in "$@" ; do [[ "$arg" == "-r" ]] && continue [[ "$arg" == "--remote" ]] && continue [[ "$arg" == "-P" ]] && continue @@ -2478,7 +2478,7 @@ getURLVars() { checkDeps() { local app - for app in $@ ; do + for app in "$@" ; do type -P "$app" &> /dev/null [[ $? -eq 1 ]] && return 1 done @@ -2601,7 +2601,7 @@ show() { showm() { if [[ -n "$2" ]] ; then - echo -e -n "\e[${2}m${1}${CL_NORM}" + echo -e -n "\e[${2}m${1}\e[0m" else echo -e -n "$*" fi diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index 77e33d4..993b078 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -163,7 +163,7 @@ checkPerms() { #################################################################### checkDeps() { - for app in $@ ; do + for app in "$@" ; do type -P "$app" &> /dev/null if [[ $? -eq 1 ]] ; then From 67c2105361d67dd8532c8a4de7f99e69e887cbf6 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 15 Nov 2016 05:57:19 -0500 Subject: [PATCH 30/33] Fixes --- .codeclimate.yml | 2 ++ SOURCES/rpmbuilder | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 4e68068..26b565f 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -14,6 +14,8 @@ engines: enabled: false SC2143: enabled: false + SC2002: + enabled: false ratings: paths: diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index ea6da52..06438d6 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -411,7 +411,7 @@ checkArgs() { doExit $ERROR_DEPS fi - if ! checkDeps "rpmbuild rpmlint" && [[ ! $remote ]] ; then + if ! checkDeps "rpmbuild" "rpmlint" && [[ ! $remote ]] ; then show "Can't start local build process - you must install rpmbuild and rpmlint first." $RED doExit $ERROR_DEPS fi @@ -432,7 +432,7 @@ checkArgs() { fi if [[ $bump ]] ; then - if ! checkDeps "rpmdev-packager rpmdev-bumpspec" ; then + if ! checkDeps "rpmdev-packager" "rpmdev-bumpspec" ; then show "Can't start build process - for automatic release bumping you must install rpmdev-bumpspec and rpmdev-packager (from rpmdevtools package) first." $RED doExit $ERROR_DEPS @@ -606,10 +606,10 @@ parseSourceURL() { } makeTemp() { - tmp_file=$(mktemp $tmp/$tmp_file) - tmp_dir=$(mktemp -d $tmp/$tmp_dir) + tmp_file=$(mktemp "${tmp:?}/$tmp_file") + tmp_dir=$(mktemp -d "${tmp:?}/$tmp_dir") - if [[ ! -f $tmp_file || ! -d $tmp_dir ]] ; then + if [[ ! -f "$tmp_file" || ! -d "$tmp_dir" ]] ; then show "Can't start build process - temp file can't be created." $RED doExit $ERROR_UNKNOWN fi @@ -630,12 +630,12 @@ downloadRemoteSources() { showSeparator "DOWNLOADING" - local source_file source_list source_file_name patch_list files + local source_file sources_list source_file_name patches_list files - source_list=$(getSpecValue "$MACRO_SOURCE" "$spec") - patch_list=$(getSpecValue "$MACRO_PATCH" "$spec") + sources_list=$(getSpecValue "$MACRO_SOURCE" "$spec") + patches_list=$(getSpecValue "$MACRO_PATCH" "$spec") - files="$source_list $patch_list" + files="$sources_list $patches_list" for source_file in $files ; do if [[ "$source_file" =~ ^(http|https|ftp) ]] ; then @@ -1476,9 +1476,14 @@ packSources() { mkdir -p "$tmp_dir/$arch_name" if [[ ! $relative_pack ]] ; then - cp -r "$pack" "$tmp_dir/$arch_name" &> /dev/null + cp -r $pack "$tmp_dir/$arch_name" &> /dev/null else - cp -r --parents "$pack" "$tmp_dir/$arch_name" &> /dev/null + cp -r --parents $pack "$tmp_dir/$arch_name" &> /dev/null + fi + + if [[ $? -ne 0 ]] ; then + show "Can't copy source files to temporary ditrectory" $RED + doExit 1 fi cleanPackDir "$tmp_dir/$arch_name" @@ -2563,7 +2568,7 @@ statusObserver() { local prev_status status while : ; do - status=$(grep "Executing" $"tmp_file" | tail -1 | perl -ne '/Executing\(%(\w*)\)/ && print "$1\n"') + status=$(grep "Executing" "$tmp_file" | tail -1 | perl -ne '/Executing\(%(\w*)\)/ && print "$1\n"') if [[ "$status" == "doc" ]] ; then [[ $(grep "Checking for unpackaged" "$tmp_file") ]] && status="packaging" From bdf43cd14166c15b74792a000c0c23477a1e8131 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 15 Nov 2016 06:54:27 -0500 Subject: [PATCH 31/33] RPMB-113 Multiple macro definition support --- SOURCES/rpmbuilder | 14 +++++++------- readme.md | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/SOURCES/rpmbuilder b/SOURCES/rpmbuilder index 06438d6..690f679 100755 --- a/SOURCES/rpmbuilder +++ b/SOURCES/rpmbuilder @@ -2319,11 +2319,11 @@ getBuildArgs() { [[ $without ]] && args=$(getBuildArgsWithout "$args") [[ $verbose ]] && args="$args --verbose" - local def + local macro_def if [[ $define ]] ; then - for def in $define ; do - args="$args --define=\"$def\"" + for macro_def in $define ; do + args="$args --define=\"${macro_def/=/ }\"" done fi @@ -2735,16 +2735,16 @@ usage() { show "" show "Arguments passing:" $BOLD show "" - show " ${CL_GREEN}--with, -w${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" - show " ${CL_GREEN}--without, -W${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" - show " ${CL_GREEN}--define, -D${CL_NORM} ${CL_GREY}\"\"${CL_NORM} Define MACRO with value (exist macro will be not redefined) ${CL_DARK}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--with, -w${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--without, -W${CL_NORM} ${CL_GREY}params${CL_NORM} Pass conditional parameters into a rpmbuild ${CL_DARK}(mergeable)${CL_NORM}" + show " ${CL_GREEN}--define, -D${CL_NORM} ${CL_GREY}\"macro=value\"${CL_NORM} Define MACRO with value (exist macro will be not redefined) ${CL_DARK}(mergeable)${CL_NORM}" show "" show " Examples:" $BOLD show "" show " rpmbuilder package.spec --with ssl --with ldap" show " rpmbuilder package.spec -w ssl -W ldap" show " rpmbuilder package.spec --with \"ssl ldap\"" - show " rpmbuilder package.spec --define=\"_tmp_dir /some/dir\"" + show " rpmbuilder package.spec --define \"install_dir=/some/dir\" --define \"service_user=someone\"" show "" show " ${CL_BOLD}More info:${CL_NORM} http://rpm5.org/docs/api/conditionalbuilds.html" show "" diff --git a/readme.md b/readme.md index d488070..3f76a83 100644 --- a/readme.md +++ b/readme.md @@ -131,16 +131,16 @@ Build options: Arguments passing: - --with, -w params Pass conditional parameters into a rpmbuild (mergeable) - --without, -W params Pass conditional parameters into a rpmbuild (mergeable) - --define, -D "" Define MACRO with value (exist macro will be not redefined) (mergeable) + --with, -w params Pass conditional parameters into a rpmbuild (mergeable) + --without, -W params Pass conditional parameters into a rpmbuild (mergeable) + --define, -D "macro=value" Define MACRO with value (exist macro will be not redefined) (mergeable) Examples: rpmbuilder package.spec --with ssl --with ldap rpmbuilder package.spec -w ssl -W ldap rpmbuilder package.spec --with "ssl ldap" - rpmbuilder package.spec --define="_tmp_dir /some/dir" + rpmbuilder package.spec --define "install_dir=/some/dir" --define "service_user=someone" More info: http://rpm5.org/docs/api/conditionalbuilds.html From aefb1cda67b0cd3be4a3b251cf28817b2091d5ab Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 15 Nov 2016 17:37:36 -0500 Subject: [PATCH 32/33] Fixes --- .codeclimate.yml | 6 ++-- SOURCES/rpmunbuilder | 75 +++++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index 26b565f..46eea3d 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -19,6 +19,6 @@ engines: ratings: paths: - - "SOURCES/rpmbuilder" - - "SOURCES/rpmunbuilder" - - "SOURCES/buildmon" + - SOURCES/rpmbuilder + - SOURCES/rpmunbuilder + - SOURCES/buildmon diff --git a/SOURCES/rpmunbuilder b/SOURCES/rpmunbuilder index 993b078..5a8380a 100755 --- a/SOURCES/rpmunbuilder +++ b/SOURCES/rpmunbuilder @@ -58,8 +58,6 @@ CL_BG_DARK="\e[${DARK};7m" SUPPORTED_ARGS="help usage ver version" SHORT_ARGS="h:help v:version" -DEPS="rpm rpm2cpio cpio" - ######################################################################################## main() { @@ -73,8 +71,8 @@ main() { exit 0 fi - if [[ ! $(checkDeps "$DEPS") ]] ; then - show "For usage this utility install this packages first: $DEPS" $BROWN + if [[ ! $(checkDeps "rpm" "rpm2cpio" "cpio") ]] ; then + show "For usage this utility install this packages first: rpm rpm2cpio cpio" $BROWN exit 2 fi @@ -178,7 +176,7 @@ checkDeps() { show() { if [[ -n "$2" ]] ; then - echo -e "\e[${2}m${1}${CL_NORM}" + echo -e "\e[${2}m${1}\e[0m" else echo -e "$*" fi @@ -186,7 +184,7 @@ show() { showm() { if [[ -n "$2" ]] ; then - echo -e -n "\e[${2}m${1}${CL_NORM}" + echo -e -n "\e[${2}m${1}\e[0m" else echo -e -n "$*" fi @@ -198,7 +196,7 @@ showArgWarn() { } usage() { - show "${CL_BOLD}Usage:${CL_NORM} rpmunbuilder ${CL_BROWN}${CL_NORM} ${CL_GREEN}${CL_NORM}" + show "${CL_BOLD}Usage:${CL_NORM} rpmunbuilder ${CL_BROWN}{rpm-file}${CL_NORM} ${CL_GREEN}{path}${CL_NORM}" } about() { @@ -208,98 +206,103 @@ about() { show "Essential Kaos Open Source License " $DARK } -## ARGUMENTS PARSING ########################################################## +## ARGUMENTS PARSING 2 ################################################################# -[[ $# -eq 0 ]] && main && exit +[[ $# -eq 0 ]] && main && exit $? -unset arg argn argm argv argt +unset arg argn argm argv argt argk -argv="$*" -argt="" +argv="$*" ; argt="" while [[ -n "$1" ]] ; do if [[ "$1" =~ \ && -n "$argn" ]] ; then declare "$argn=$1" - unset argn - shift && continue + unset argn && shift && continue elif [[ $1 =~ ^-{1}[a-zA-Z0-9]{1,2}+.*$ ]] ; then argm=${1:1} - if [[ " $SHORT_ARGS " =~ \ ${argm}:([a-zA-Z0-9_]*) ]] ; then + if [[ \ $SHORT_ARGS\ =~ \ $argm:!?([a-zA-Z0-9_]*) ]] ; then arg="${BASH_REMATCH[1]}" else - showArgWarn "-${argm}" 2> /dev/null || : + showArgWarn "-$argm" 2> /dev/null || : shift && continue fi if [[ -z "$argn" ]] ; then argn=$arg else - declare "$argn=true" - unset argn + [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare "$argn=true" argn=$arg fi - if [[ ! "$SUPPORTED_ARGS " =~ $argn\ ]] ; then - showArgWarn "-${argm}" 2> /dev/null || : + if [[ ! $SUPPORTED_ARGS\ =~ !?$argn\ ]] ; then + showArgWarn "-$argm" 2> /dev/null || : shift && continue fi + if [[ ${BASH_REMATCH[0]:0:1} == "!" ]] ; then + declare "$argn=true" ; unset argn ; argk=true + else + unset argk + fi + shift && continue elif [[ "$1" =~ ^-{2}[a-zA-Z]{1}[a-zA-Z0-9_-]+.*$ ]] ; then arg=${1:2} if [[ $arg == *=* ]] ; then - IFS="=" arg=($arg) + IFS="=" read -ra arg <<< "$arg" argm="${arg[0]}" ; argm=${argm//-/_} - if [[ ! "$SUPPORTED_ARGS " =~ ${arg[0]}\ ]] ; then + if [[ ! $SUPPORTED_ARGS\ =~ $argm\ ]] ; then showArgWarn "--${arg[0]//_/-}" 2> /dev/null || : shift && continue fi - [[ -n "${!argm}" && "$MERGEABLE_ARGS " =~ ${argm}\ ]] && declare "${argm}=${!argm} ${arg[@]:1:99}" || declare "${argm}=${arg[@]:1:99}" + [[ -n "${!argm}" && $MERGEABLE_ARGS\ =~ $argm\ ]] && declare "$argm=${!argm} ${arg[@]:1:99}" || declare "$argm=${arg[@]:1:99}" - unset argm - shift && continue + unset argm && shift && continue else arg=${arg//-/_} if [[ -z "$argn" ]] ; then argn=$arg else - declare "$argn=true" - unset argn + [[ -z "$argk" ]] && ( showArgValWarn "--$argn" 2> /dev/null || : ) || declare "$argn=true" argn=$arg fi - if [[ ! "$SUPPORTED_ARGS " =~ $argn\ ]] ; then + if [[ ! $SUPPORTED_ARGS\ =~ !?$argn\ ]] ; then showArgWarn "--${argn//_/-}" 2> /dev/null || : shift && continue fi + if [[ ${BASH_REMATCH[0]:0:1} == "!" ]] ; then + declare "$argn=true" ; unset argn ; argk=true + else + unset argk + fi + shift && continue fi else if [[ -n "$argn" ]] ; then - [[ -n "${!argn}" && "$MERGEABLE_ARGS " =~ ${argn}\ ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" + [[ -n "${!argn}" && $MERGEABLE_ARGS\ =~ $argn\ ]] && declare "$argn=${!argn} $1" || declare "$argn=$1" - unset argn - shift && continue + unset argn && shift && continue fi fi - argt="$argt $1" - shift + argt="$argt $1" ; shift done [[ -n "$argn" ]] && declare "$argn=true" -unset arg argn argm +unset arg argn argm argk -[[ -n "$KEEP_ARGS" ]] && main $argv || main $argt +[[ -n "$KEEP_ARGS" ]] && main $argv || main ${argt:1:9999} -############################################################################### +######################################################################################## From 18be6fe1c00e215867b3d220859d8ada2e6f9951 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 15 Nov 2016 19:09:13 -0500 Subject: [PATCH 33/33] rpmbuilder-node version bump --- rpmbuilder-node.spec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rpmbuilder-node.spec b/rpmbuilder-node.spec index 9a7afeb..5cd6af5 100644 --- a/rpmbuilder-node.spec +++ b/rpmbuilder-node.spec @@ -49,8 +49,8 @@ Summary: Configuration package for rpmbuilder node Name: rpmbuilder-node -Version: 1.0.1 -Release: 2%{?dist} +Version: 1.1.0 +Release: 0%{?dist} License: EKOL Group: Development/Tools URL: https://github.com/essentialkaos/rpmbuilder @@ -136,6 +136,9 @@ fi ############################################################################### %changelog +* Wed Nov 16 2016 Anton Novojilov - 1.1.0-0 +- Improvements + * Wed May 11 2016 Anton Novojilov - 1.0.1-2 - Improved spec file