diff --git a/checkversion b/checkversion index 3ad9b8f..406575b 100755 --- a/checkversion +++ b/checkversion @@ -18,7 +18,7 @@ # specialpkg_check(): Contained in this script, custom version checks go in this function # -cd "${0%/*}" +cd "${0%/*}" || exit script_directory="$PWD" # Directory containing this script script_name="${0//*\/}" # Name of this script package_rootdir="$(readlink -f "$script_directory"/..)" # Directory containing a collection of packages contained in folders @@ -47,7 +47,7 @@ unset c_blue c_white c_yellow c_grey c_red c_green c_reset # SPECIALPKG CHECK: function for custom version check functions function specialpkg_check() { # Enter the package root directory - cd "$package_rootdir" + cd "$package_rootdir" || exit # PKGVER CHECK: terminfo-italics specialpkg=terminfo-italics @@ -55,16 +55,16 @@ function specialpkg_check() { | grep Version \ | sed 's|^[^:]*:\ ||;s|-.*$||') pkgver='' - eval "$(egrep '^\s*pkgver\s*=' $specialpkg/PKGBUILD)" + eval "$(grep -E '^\s*pkgver\s*=' $specialpkg/PKGBUILD)" vercmp_check "$specialpkg" "$upstream_version" "$pkgver" # Return to the script folder - cd "$script_directory" + cd "$script_directory" || exit } # HELPER FUNCTION: Output readible results of a version comparison function vercomp_display() { - printf '%s\n' "$c_blue[$c_white$1$c_blue]$c_reset ${c_yellow}up: $2$c_reset $c_blue|$c_reset $3" + printf '%s\n' "${c_blue}[$c_white$1$c_blue]$c_reset ${c_yellow}up: $2$c_reset $c_blue|$c_reset $3" } # HELPER FUNCTION: Compares versions and handles accordingly @@ -110,7 +110,7 @@ function archversion_check() { > "$temp_config" # Define $package_definition as an empty archversion.conf template then add the $pkg entry from $archversion_conf - if egrep -q "\[\s*$pkg\s*\]" "$archversion_conf"; then + if grep -qE "\[\s*$pkg\s*\]" "$archversion_conf"; then package_definition="$(sed 's|^\s*#\s*||;/\[\s*'"$pkg"'\s*\]/,$!d;/^$/q' "$archversion_conf")" else package_definition="[$pkg]" @@ -121,11 +121,12 @@ function archversion_check() { >> "$temp_config" # Grab the simple archversion output for parsing - archversion_output=$(CONFIG_PACKAGES="$temp_config" CACHE_PACKAGES="$package_cache" \ - archversion $archversion_command) - upstream_version=$(egrep -o 'up: [^ ]*' <<< "$archversion_output" \ + archversion_output=$(CONFIG_PACKAGES="$temp_config" CACHE_PACKAGES="$package_cache" archversion $archversion_command) + + upstream_version=$(grep -oE 'up: [^ ]*' <<< "$archversion_output" \ | sed 's|up: ||') - package_version=$(egrep -o 'aur: [^ ]*' <<< "$archversion_output" \ + + package_version=$(grep -oE 'aur: [^ ]*' <<< "$archversion_output" \ | sed 's|aur: ||' \ | sed 's|^[0-9][0-9]*:||') @@ -133,13 +134,11 @@ function archversion_check() { vercmp_check "$pkg" "$upstream_version" "$package_version" # Add a blank line after each package when running debug for easier parsing - [[ "$archversion_debug" = '1' ]] \ - && printf '\n' + [[ "$archversion_debug" = '1' ]] && printf '\n' # Remove the tmp config - [[ -f "$temp_config" ]] \ - && rm "$temp_config" - done < <(egrep -v '\[DEFAULT\]' "$archversion_conf" | egrep '^\s*\[[^]]*\]' | egrep -o '[^][]*') + [[ -f "$temp_config" ]] && rm "$temp_config" + done < <(grep -vE '\[DEFAULT\]' "$archversion_conf" | grep -E '^\s*\[[^]]*\]' | grep -oE '[^][]*') } # develversion_conf CHECK @@ -156,59 +155,57 @@ function develversion_check() { # Find the current pkgver() of the package in the AUR package_version=$(pacaur -i "$pkg" \ | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' \ - | egrep '^Version' \ + | grep -E '^Version' \ | sed 's|^[^:]*: ||;s|-[0-9]*$||') pkgbuild_file="$package_rootdir/$pkg/PKGBUILD" # Exit and skip this package if either its folder or the PKGBUILD it should contain are missing [[ ! -f "$pkgbuild_file" ]] && { if [[ ! -d "$package_rootdir/$pkg" ]]; then - printf '%s\n' "$c_blue[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: $pkg does not exist in $package_rootdir" >&2 + printf '%s\n' "${c_blue}[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: $pkg does not exist in $package_rootdir" >&2 else - printf '%s\n' "$c_blue[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: $package_rootdir/$pkg does not contain a PKGBUILD" >&2 + printf '%s\n' "${c_blue}[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: $package_rootdir/$pkg does not contain a PKGBUILD" >&2 fi + continue } # Exit and skip this package if a pkgver() function doesn't exist (ie: not VCS) - egrep -q 'pkgver\(' "$pkgbuild_file" || { - printf '%s\n' "$c_blue[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: package doesn't contain a pkgver() function" >&2 + grep -qE 'pkgver\(' "$pkgbuild_file" || { + printf '%s\n' "${c_blue}[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: package doesn't contain a pkgver() function" >&2 continue } # Delete the temporary build folder if it already exists - [[ -d "$temp_directory/build" ]] \ - && rm -rf "$temp_directory/build" + [[ -d "$temp_directory/build" ]] && rm -rf "$temp_directory/build" # Create and enter the temporary build folder, exiting with an error if this fails if install -d "$temp_directory/build"; then - cd "$temp_directory/build" + cd "$temp_directory/build" || exit else printf '%s\n' "${c_red}ERROR$c_reset: Failure to create and enter the temporary build folder @ $temp_directory/build" >&2 exit 1 fi # Link all folders in the package directory except pkg+src to avoid re-cloning repos each check - for dir in $(find "$package_rootdir/$pkg" -maxdepth 1 -mindepth 1 -type d | egrep -v '(src|pkg)'); do + for dir in $(find "$package_rootdir/$pkg" -maxdepth 1 -mindepth 1 -type d | grep -vE '(src|pkg)'); do ln -s "$dir" "$temp_directory/build" done # Copy the package's PKGBUILD to the temporary build folder with its functions stripped out sed '/^.*\(\).*{[^}]*$/,/^[^{]]*}/d' "$pkgbuild_file" \ - | egrep -v '^\s*install\s*=' \ + | grep -vE '^\s*install\s*=' \ > PKGBUILD # Add the package's pkgver() function from the original PKGBUILD into the copy - sed '/pkgver(/,$!d' "$pkgbuild_file" \ - | sed '/^\s*}\s*$/q' \ - >> PKGBUILD + sed '/pkgver(/,$!d' "$pkgbuild_file" | sed '/^\s*}\s*$/q' >> PKGBUILD # Reset the values we'll be using then source the new PKGBUILD unset pkgname epoch pkgver pkgrel source PKGBUILD [[ ! "$pkgname" = "$pkg" ]] && { - printf '%s\n' "$c_blue[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: This pkgname for this package is $pkgname" >&2 + printf '%s\n' "${c_blue}[$c_white$pkg$c_blue]$c_reset ${c_red}ERROR$c_reset: This pkgname for this package is $pkgname" >&2 continue } @@ -228,12 +225,14 @@ function develversion_check() { source_array='source=(' sha512sum_array='sha512sums=(' printf '\n' >> PKGBUILD + for src in "${source[@]}"; do - egrep -q '^\s*(bzr|csv|git|hg|darcs|svn)[^a-zA-Z0-9]' < <(sed 's|^[^:]*::||' <<< "$src") && { + grep -qE '^\s*(bzr|csv|git|hg|darcs|svn)[^a-zA-Z0-9]' < <(sed 's|^[^:]*::||' <<< "$src") && { source_array="$source_array '$src'" sha512sum_array="$sha512sum_array 'SKIP'" } done + sed 's|( |(|' <<< "${source_array})" >> PKGBUILD sed 's|( |(|' <<< "${sha512sum_array})" >> PKGBUILD @@ -242,7 +241,7 @@ function develversion_check() { if [[ $? = 0 ]]; then # Calculate the full package version, including epoch (if applicable), pkgver and pkgrel unset epoch pkgver pkgrel - eval "$(egrep '^\s*(epoch|pkgver|pkgrel)\s*=' PKGBUILD)" + eval "$(grep -E '^\s*(epoch|pkgver|pkgrel)\s*=' PKGBUILD)" [[ -n "$epoch" ]] && epoch="$epoch:" upstream_version="$epoch$pkgver-$pkgrel" @@ -256,10 +255,10 @@ function develversion_check() { # Display an error if the package can't be found in the package root directory printf '%s\n' "${c_red}ERROR$c_reset: Failed to find the package $pkg in $package_rootdir" >&2 fi - done < <(egrep -v '^#' "$develversion_conf") + done < <(grep -vE '^#' "$develversion_conf") # Move back to $script_directory - cd "$script_directory" + cd "$script_directory" || exit } # check_missingpkgsPKG CHECK @@ -267,30 +266,34 @@ function missingpkg_check() { # Create lists of archversion, develversion, specialversion and noversion packages specialversion_packages='terminfo-italics' noversion_packages=$(sed 's|\[||;s|\]||;s|\s*#.*$||' "$noversion_conf") - develversion_packages=$(egrep -v '^\s*#' "$develversion_conf") - archversion_packages=$(egrep -v '^\s*#' "$archversion_conf" \ + develversion_packages=$(grep -vE '^\s*#' "$develversion_conf") + archversion_packages=$(grep -vE '^\s*#' "$archversion_conf" \ | grep -v '[DEFAULT]' \ - | egrep '^\s*\[[^]]*\]' \ + | grep -E '^\s*\[[^]]*\]' \ | sed 's|\[||;s|\]||') # Create a list of packages in the package root directory that aren't in any of the above lists check_missing_pkgs=$( - cd "$package_rootdir" + cd "$package_rootdir" || exit + for pkg in *; do [[ -f "$pkg/PKGBUILD" ]] && { _pkg=$(sed 's|.*\/||' <<< "$pkg") - ! egrep -q "^$_pkg$" <<< "$archversion_packages" \ - && ! egrep -q "^$_pkg$" <<< "$develversion_packages" \ - && ! egrep -q "^$_pkg$" <<< "$specialversion_packages" \ - && ! egrep -q "^$_pkg$" <<< "$noversion_packages" \ + + ! grep -qE "^$_pkg$" <<< "$archversion_packages" \ + && ! grep -qE "^$_pkg$" <<< "$develversion_packages" \ + && ! grep -qE "^$_pkg$" <<< "$specialversion_packages" \ + && ! grep -qE "^$_pkg$" <<< "$noversion_packages" \ && printf '%s\n' "$_pkg" } done - cd "$script_directory" + + cd "$script_directory" || exit ) # Display information about any packages missing from all the package lists - printf '%s' "$c_blue[${c_white}missing-packages$c_blue]$c_reset: " + printf '%s' "${c_blue}[${c_white}missing-packages$c_blue]$c_reset: " + if [[ -n "$check_missing_pkgs" ]]; then # Display how many packages are missing printf '%s\n' "$c_red$(wc -l <<< "$check_missing_pkgs")$c_reset" @@ -342,7 +345,7 @@ check_missingpkgs=0 archversion_debug=0 only_newpkgs=0 # Parse command-line arguments for param in "$@"; do - if egrep -q '^-[a-z][a-z]' <<< "$param"; then + if grep -qE '^-[a-z][a-z]' <<< "$param"; then # Parse the argument character by character while read -r char; do paramparse "$char" @@ -369,5 +372,4 @@ develversion_check specialpkg_check # Cleanup the temp folder -[[ -d "$temp_directory" ]] \ - && rm -rf "$temp_directory" +[[ -d "$temp_directory" ]] && rm -rf "$temp_directory"