vaab / kal-shlib-common

General purpose bash shell scripting library
GNU General Public License v2.0
4 stars 2 forks source link

Where to contribute? #1

Open szepeviktor opened 7 years ago

szepeviktor commented 7 years ago
# Detect an IPv4 address
is_ipv4() {
    local TOBEIP="$1"
    #             0-9  10-99  100-199   200-249     250-255
    local OCTET="([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"

    [[ "$TOBEIP" =~ ^${OCTET}\.${OCTET}\.${OCTET}\.${OCTET}$ ]]
}

# Detect an IPv4 address range
is_ipv4_range() {
    local TOBEIPRANGE="$1"
    local MASKBITS="${TOBEIPRANGE##*/}"
    local OCTET="([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"

    [[ "$TOBEIPRANGE" =~ ^${OCTET}\.${OCTET}\.${OCTET}\.${OCTET}/[0-9]{1,2}$ ]] \
        && [ "$MASKBITS" -gt 0 ] && [ "$MASKBITS" -le 30 ]
}
szepeviktor commented 7 years ago
# Determine whether a Debian package is installed
dpkg_is_installed() {
    local PKG="$1"

    [ "$(dpkg-query --showformat="\${Status}" --show "$PKG" 2> /dev/null)" == "install ok installed" ]
}
vaab commented 7 years ago

Thanks for your interests ! , I'll keep that open to evaluate it and include it.

To answer your question about where to contribute: I need to think thoroughly to the overall placement of the code as I'm not happy with it. But for now, is_ipv4 would go into libparse.sh and dpkg_is_installed would go into another package... not kal-shlib-common, and probably a file libdpkg.sh.