diff --git a/lib/bash/tools.sh b/lib/bash/tools.sh index 83b2aed..ab8ce10 100644 --- a/lib/bash/tools.sh +++ b/lib/bash/tools.sh @@ -1,69 +1,75 @@ #!/bin/bash function replace_in_file() { local pattern=$1 string=$2 filename=$3 sed "s?$pattern?$string?g" $filename > /tmp/sed.tmp.$$ mv /tmp/sed.tmp.$$ $filename return 0 } function get_file_encoding() { local filename=$1 local output=$(file --brief $filename) case $output in *ASCII*) echo "unicode" return 0;; *UTF-8*) echo "unicode" return 0;; *8859*) echo "iso" return 0;; "*") echo "unknown";; esac return 1 } function function_exists() { if [ $(type "$1" 2>&1 | grep -c "$1"' is a function') -eq 1 ]; then return 0 else return 1 fi } function check_OS() { OS=$(uname | tr "[A-Z]" "[a-z]") if [ "$OS" == "linux" ]; then return 0; fi if [ "$OS" == "darwin" ]; then return 0; fi OS="unknown" return 1 } function check_OS_subtype() { OS_SUBTYPE="unknown" if [ -r /etc/gentoo-release ]; then OS_SUBTYPE="gentoo"; return 0; fi + if [ -r /usr/bin/lsb_release ]; then + if [ $(lsb_release -d | grep -ic 'buntu') -gt 0 ]; then OS_SUBTYPE="Ubuntu"; return 0; fi + fi return 1 } function check_AMC_version() { AMC_VERSION="unknown" which auto-multiple-choice > /dev/null 2>&1 if [ $? -gt 0 ]; then AMC_VERSION="none" return 1 fi case $OS in "linux") case $OS_SUBTYPE in "gentoo") AMC_VERSION=$(eix --xml auto-multiple-choice | grep 'installed="1"' | tr " " "\n" | grep '^id' | cut -d '"' -f 2) return 0;; + "Ubuntu") + AMC_VERSION=$(dpkg -s auto-multiple-choice | grep '^Version:' | cut -c 10-) + return 0;; esac esac return 1 } # EOF