<commit_before>#!/bin/bash

# Linux package versions and possible updates - apt, python, pear, pecl, node.js, ruby gems and java JRE
# ------------------------------------------------------------------------------------------------------
#
# monthly mail by cron job
# /usr/local/sbin/package-versions.sh | mailx -s "[admin] package versions and updates" -S from="pkgs <cron.monthly>" root

h1() {
        local MAXWIDTH="$(( 26 - 2 ))"
        local MSG="$*"
        local MSG_SIZE="${#MSG}"
        local LEFT_SIDE="$(( (MAXWIDTH + MSG_SIZE + 1) / 2 ))"
        local RIGHT_SIDE="$(( MAXWIDTH - LEFT_SIDE ))"
        echo
        echo "/************************\\"
        printf "|%*s%*s|\n" "$LEFT_SIDE" "$MSG" "$RIGHT_SIDE" " "
        echo "\\************************/"
}

v() {
    echo -n "[ver] $1"
}

get_java_latest() {
    local BUNDLEURL="$(wget -qO- "https://www.java.com/en/download/linux_manual.jsp" \
        | grep -m1 -i "Linux x64" \
        | grep -o "http://.*download.*?BundleId=[0-9]\+")"

    local JAVAWEBVERSION="$(wget -qS --max-redirect=0 "$BUNDLEURL" 2>&1 \
        | sed -n 's|.* Location: http://.*sun\.com/.*/jre-\([^-]\+\)-linux-x64.tar.gz\?.*|\1|p')"

    local JAVALATEST_MAJOR="1.${JAVAWEBVERSION%%u*}"
    local JAVALATEST_MINOR="0${JAVAWEBVERSION##*u}"
    local JAVALATEST_MINOR="${JAVALATEST_MINOR:(-2)}"

    ## 1.7.0_55, 1.8.0_05
    JAVALATEST="${JAVALATEST_MAJOR}.0_${JAVALATEST_MINOR}"
}

get_java_current() {
    JAVACURRENT="$(java -version 2>&1 \
        | grep "^java version" | cut -d'"' -f2)"
    #'
}

get_java_update() {
    get_java_latest
    get_java_current

    [ -z "$JAVALATEST" ] && return 1
    [ -z "$JAVACURRENT" ] && return 2

    if [ "$JAVALATEST" = "$JAVACURRENT" ]; then
        echo "java-jre (${JAVACURRENT})"
    else
        echo "java-jre==${JAVALATEST} is available (you have ${JAVACURRENT})"
    fi
}

#########################################################

export LC_ALL=C

h1 "system information"
uname --all

h1 "apt"
v; apt-get --version | head -n 1
aptitude update --quiet=2 || echo "apt update failure"
aptitude --disable-columns -F%p search ?upgradable || echo "apt package listing error"

h1 "python"
v; python --version 2>&1
pip-review 2>&1 || echo "python package list error"

h1 "PHP extensions: pear + pecl"
v; pear version | head -n 1
pear update-channels > /dev/null && pear list-upgrades || echo "pear update failure"

h1 "node.js"
v "npm"; npm --version
npm -g outdated 2> /dev/null || echo "node.js update failure"

h1 "ruby gem"
v "gem"; gem --version
gem outdated -u || echo "ruby gem update failure"

h1 "java jre"
get_java_update  || echo "java jre update failure"
<commit_msg>package-versions.sh<commit_after>#!/bin/bash

# Linux package versions and possible updates - apt, python, pear, pecl, node.js, ruby gems and java JRE
# ------------------------------------------------------------------------------------------------------
#
# monthly mail by cron job
# /usr/local/sbin/package-versions.sh | mailx -s "[admin] package versions and updates" -S from="pkgs <cron.monthly>" root

h1() {
        local MAXWIDTH="$(( 26 - 2 ))"
        local MSG="$*"
        local MSG_SIZE="${#MSG}"
        local LEFT_SIDE="$(( (MAXWIDTH + MSG_SIZE + 1) / 2 ))"
        local RIGHT_SIDE="$(( MAXWIDTH - LEFT_SIDE ))"
        echo
        echo "/************************\\"
        printf "|%*s%*s|\n" "$LEFT_SIDE" "$MSG" "$RIGHT_SIDE" " "
        echo "\\************************/"
}

v() {
    echo -n "[ver] $1"
}

get_java_latest() {
    local BUNDLEURL="$(wget -qO- "https://www.java.com/en/download/linux_manual.jsp" \
        | grep -m1 -i "Linux x64" \
        | grep -o "http://.*download.*?BundleId=[0-9]\+")"

    local JAVAWEBVERSION="$(wget -qS --max-redirect=0 "$BUNDLEURL" 2>&1 \
        | sed -n 's|.* Location: http://.*sun\.com/.*/jre-\([^-]\+\)-linux-x64.tar.gz\?.*|\1|p')"

    local JAVALATEST_MAJOR="1.${JAVAWEBVERSION%%u*}"
    local JAVALATEST_MINOR="0${JAVAWEBVERSION##*u}"
    local JAVALATEST_MINOR="${JAVALATEST_MINOR:(-2)}"

    ## 1.7.0_55, 1.8.0_05
    JAVALATEST="${JAVALATEST_MAJOR}.0_${JAVALATEST_MINOR}"
}

get_java_current() {
    JAVACURRENT="$(java -version 2>&1 \
        | grep "^java version" | cut -d'"' -f2)"
    #'
}

get_java_update() {
    get_java_latest
    get_java_current

    [ -z "$JAVALATEST" ] && return 1
    [ -z "$JAVACURRENT" ] && return 2

    if [ "$JAVALATEST" = "$JAVACURRENT" ]; then
        echo "java-jre (${JAVACURRENT})"
    else
        echo "java-jre==${JAVALATEST} is available (you have ${JAVACURRENT})"
    fi
}

#########################################################

export LC_ALL=C

h1 "system information"
uname --all

h1 "apt"
v; apt-get --version | head -n 1
aptitude update --quiet=2 || echo "apt update failure"
aptitude --disable-columns -F%p search ?upgradable || echo "apt package listing error"

h1 "python"
v; python --version 2>&1
pip-review 2>&1 || echo "python package list error"

# pear + pecl
h1 "PHP extensions"
v; pear version | head -n 1
pear update-channels > /dev/null && pear list-upgrades || echo "pear update failure"

h1 "node.js"
v "npm"; npm --version
npm -g outdated 2> /dev/null || echo "node.js update failure"

h1 "ruby gem"
v "gem"; gem --version
gem outdated -u || echo "ruby gem update failure"

h1 "java jre"
get_java_update  || echo "java jre update failure"

{'fraction_non_alphanumeric': 0.2457579712847287, 'fraction_numerical': 0.019392131269811673, 'mean_word_length': 2.65893587994543, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5084318', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1927, 'n_words': 480}