Changeset - b34547147a36
[Not reviewed]
0 1 0
Branko Majic (branko) - 22 months ago 2024-02-10 11:10:11
branko@majic.rs
MAR-193: Fix some linting errors reported by shellcheck.
1 file changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
roles/common/files/pip_check_requirements_upgrades.sh
Show inline comments
 
@@ -95,25 +95,25 @@ $program
 
| GNU General Public License for more details.                          |
 
|                                                                       |
 
| You should have received a copy of the GNU General Public License     |
 
| along with this program.  If not, see <http://www.gnu.org/licenses/>. |
 
+-----------------------------------------------------------------------+
 

	
 
EOF
 
}
 

	
 
# Set-up colours for message printing if we're not piping and terminal is
 
# capable of outputting the colors.
 
_color_terminal=$(tput colors 2>&1)
 
if [[ -t 1 ]] && (( ${_color_terminal} > 0 )); then
 
if [[ -t 1 ]] && (( _color_terminal > 0 )); then
 
    _text_bold=$(tput bold)
 
    _text_white=$(tput setaf 7)
 
    _text_blue=$(tput setaf 6)
 
    _text_green=$(tput setaf 2)
 
    _text_yellow=$(tput setaf 3)
 
    _text_red=$(tput setaf 1)
 
    _text_reset=$(tput sgr0)
 
else
 
    _text_bold=""
 
    _text_white=""
 
    _text_blue=""
 
    _text_green=""
 
@@ -170,47 +170,48 @@ while getopts "V:qdvh" opt; do
 
        V) virtualenv="$OPTARG";;
 
        q) quiet=1;;
 
        d) debug=1;;
 
        v) version
 
           exit "$SUCCESS";;
 
        h) usage
 
           exit "$SUCCESS";;
 
        *) usage
 
           exit "$ERROR_ARGUMENTS";;
 
    esac
 
done
 
i=$OPTIND
 
shift $(($i-1))
 
shift $(( i-1 ))
 

	
 

	
 
if [[ ${#@} == 0 ]]; then
 
    error "Must pass configuration directory."
 
    usage
 
    exit "$ERROR_ARGUMENTS"
 
fi
 

	
 
# Verify positional arguments.
 
config_dir="$1"
 
if [[ ! -d $config_dir ]]; then
 
    error "No such directory: $config_dir"
 
    exit "$ERROR_ARGUMENTS"
 
fi
 

	
 
# Make sure virtual environment exists.
 
if [[ -n $virtualenv && ! -f $virtualenv/bin/activate ]]; then
 
    error "Invalid virtual environment specified: $virtualenv"
 
    exit "$ERROR_ARGUMENTS"
 
fi
 

	
 
# Activate the virtual environment if it was specified.
 
# shellcheck disable=SC1090 # no point in validating external script
 
[[ -n $virtualenv ]] && source "$virtualenv/bin/activate"
 

	
 
# Verify pip-compile is available.
 
if ! which pip-compile >/dev/null 2>&1; then
 
    error "Could not find command pip-compile from packagep pip-tools. Package might not be available in the virtual environment."
 
    exit "$ERROR_PIP_TOOLS_MISSING"
 
fi
 

	
 
# Process each environment.
 
for environment in "$config_dir"/*; do
 
    # Empty directory.
 
    if [[ ! -e $environment ]]; then
 
@@ -262,26 +263,26 @@ for environment in "$config_dir"/*; do
 
        )
 

	
 
        # Calculate up-to-date requirements.
 
        if ! new=$("${pip_compile_invocation[@]}"); then
 
            error "Failed while running pip-compile command against (see error stack trace above): $req_in"
 
            continue
 
        fi
 

	
 
        # Clean up the new requirements to contain only package
 
        # versioning information.
 
        new=$(echo "$new" | sed -e 's/[[:blank:]]*#.*//' | grep -v "^$" | sort -u)
 

	
 
        debug "Current requirements:\n$(echo "$current")"
 
        debug "New requirements:\n$(echo "$new")"
 
        debug "Current requirements:\n$current\n"
 
        debug "New requirements:\n$new\n"
 

	
 
        # Run diff, storing the output and result.
 
        # This is using Bash process substitution, which helps avoid
 
        # creating and keeping track of temporary files (since diff
 
        # must be fed with two input files). E.g. the <() will
 
        # essentially be path to a Bash-created/managed temporary
 
        # file.
 
        diff=$(diff -u <(echo "$current") <(echo "$new"))
 
        result="$?"
 

	
 
        # Show warning about available updates.
 
        if [[ $result == 0 ]]; then
0 comments (0 inline, 0 general)