Skip to content

Instantly share code, notes, and snippets.

@AndrDm
Created July 30, 2022 08:04
Show Gist options
  • Save AndrDm/d5b7a1bb1438a5b50877bf9e0b5a27d5 to your computer and use it in GitHub Desktop.
Save AndrDm/d5b7a1bb1438a5b50877bf9e0b5a27d5 to your computer and use it in GitHub Desktop.
LabVIEW 2022 Install Helper modified for Pop!_OS
#!/bin/bash
# Utility Functions
# Error codes
# 1 General Error
# 2 Incompatible Architecture
# 3 Elevation required
# 4 Util Missing
# Codes > 100 are warnings
# 100 pkg already installed
INSTALL_SCRIPT_ERROR_SUCCESS=0
INSTALL_SCRIPT_ERROR_GENERAL=1
INSTALL_SCRIPT_ERROR_INCOMPATIBLE=2
INSTALL_SCRIPT_ERROR_NOT_ROOT=3
INSTALL_SCRIPT_ERROR_MISSING_UTIL=4
INSTALL_SCRIPT_ERROR_PKG_INSTALLED=100
INSTALL_SCRIPT_ERROR_PKG_NOT_INSTALLED=101
error_handler() {
case "$1" in
${INSTALL_SCRIPT_ERROR_SUCCESS}) return ;;
${INSTALL_SCRIPT_ERROR_INCOMPATIBLE})
echo "Sorry, LabVIEW is not currently available for this O/S and architecture."
echo "Visit http://www.ni.com/support/ to search the knowledge base"
echo "or http://www.ni.com/ask/ to obtain e-mail tech. support."
exit $1 ;;
${INSTALL_SCRIPT_ERROR_NOT_ROOT})
echo "*** Sorry, you must have root privileges to run this install script. ***"
echo "Please su or login as root and try again."
exit $1 ;;
${INSTALL_SCRIPT_ERROR_MISSING_UTIL})
echo "Sorry, you must have $2 installed for this particular distribution to use this install script."
exit $1 ;;
*)
echo "An error occurred while running this install script."
exit $1 ;;
esac
}
# get_rpm_transaction_color figures out whether the system RPM is configured
# for colored transactions or uncolored transactions. This impacts
# which style of 32-bit compatibility library gets installed on the
# system.
# Input: None
# Output: rpm_transaction_color
# Returns: 0=uncolored (i.e. use only arch as install hint)
# 1=Elf32 permitted
# 2=Elf64 permitted
# 3=Elf32 and Elf64 permitted
get_rpm_transaction_color() {
rpm_transaction_color=$($RPM --showrc | grep _transaction_color | cut --fields=2)
return $rpm_transaction_color
}
get_bitness() {
if [ -z "${os_bitness}"]; then
case $(uname -m) in
i*86) os_bitness=32 ;;
x86_64) os_bitness=64 ;;
*)
echo "OS Bitness is not supported."
return ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE}
;;
esac
fi
}
get_distro() {
if [ -z "$distro_id" ]; then
if [ -f "/etc/os-release" ]; then
. /etc/os-release
distro_id=${ID}
distro_name=${NAME}
else
# For all distros we support /etc/os-release is the standard
# default install so if this is missing then we can assume
# this is not a distribution we support.
echo "Distribution not supported."
return ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE}
fi
fi
}
echon() {
echo -n "$@";
}
#
# ver_cmp() - compares two RPM-style version numbers and returns 255, 0, 1
# to indicate if the first verison is less than, equal to, or greater than
# the second. Version numbers can be specified with or without release
# suffixes. Alpha, beta, etc. suffixes should always specified be in the
# release portion.
#
# Examples:
# ver_cmp 1.0 1.0.1
# ver_cmp 1.0-a1 1.0-a12
# ver_cmp 1.0.1-b1 1.0-1
# ver_cmp 2.2.3.4-99 2.2.4
# ver_cmp 8.2-d120 8.2-0b129
# ver_cmp 8.2-0b129 8.2-0rc0
# ver_cmp 8.2-0rc0 8.2-1
ver_cmp() {
canonicalize_version() {
canonical_version=`echo "$1" |
sed -e 's,\([0-9]\)\([A-Za-z]\),\1.000.\2,g' \
-e 's,\([A-Za-z]\)\([0-9]\),\1.\2,g' \
-e 's,^\([A-Za-z]\),---.\1,' \
-e 's,\b\([0-9]\)\b,00\1,g' \
-e 's,\b\([0-9][0-9]\)\b,0\1,g'`
}
local arg1 arg2 ret_result first_vers second_vers result_vers
if [ "$1" = "$2" ]; then
return 0
fi
arg1=$(echo "$1" | sed 's,-.*$,,')
arg2=$(echo "$2" | sed 's,-.*$,,')
if [ "$1" != "$arg1" -o "$2" != "$arg2" ]; then
ver_cmp "$arg1" "$arg2"
ret_result=$?
if [ $ret_result -ne 0 ]; then
return $ret_result
fi
fi
canonicalize_version $(echo "$1" | sed 's,^.*-,,')
first_vers="$canonical_version"
canonicalize_version $(echo "$2" | sed 's,^.*-,,')
second_vers="$canonical_version"
result_vers=$((echo "$first_vers"; echo "$second_vers") | LC_ALL=C sort -t. | head -1)
if [ "$first_vers" = "$result_vers" ]; then
return 255
else
return 1
fi
}
check_selinux() {
if [ -q selinux-policy-targeted >/dev/null 2>&1 -a -x /usr/sbin/getenforce ]; then
ENFORCING=$(/usr/sbin/getenforce | grep -i enforc >/dev/null 2>&1)
if [ -n "$ENFORCING" ]; then
echo ""
echo "*** You appear to have SELinux enabled on your system in 'enforcing' mode."
echo "If you experience errors in LabVIEW loading projects, make sure you have the"
echo "latest selinux-policy-targeted RPM package update from your vendor"
echo "(or disable SELinux with /usr/sbin/setenforce permissive)."
echo ""
fi
fi
}
util_check() {
path=$(which "$1")
if [ $? -ne 0 ]; then
error_handler ${INSTALL_SCRIPT_ERROR_MISSING_UTIL} "$1"
fi
return ${INSTALL_SCRIPT_ERROR_SUCCESS}
}
find_acrobat_reader() {
if [ -x /usr/bin/evince ]; then
ACROREAD=/usr/bin/evince
elif [ -x /usr/bin/okular ]; then
ACROREAD=/usr/bin/okular
elif [ -x /usr/bin/xpdf ]; then
ACROREAD=/usr/bin/xpdf
elif [ -x /usr/bin/ggv ]; then
ACROREAD=/usr/bin/ggv
elif [ -x /usr/bin/kpdf ]; then
ACROREAD=/usr/bin/kpf
elif [ -x /usr/bin/gv ]; then
ACROREAD=/usr/bin/gv
elif [ -x /usr/bin/epdfview ]; then
ACROREAD=/usr/bin/epdfview
elif [ -x /usr/bin/acroread ]; then
ACROREAD=/usr/bin/acroread
elif [ -x /usr/local/bin/acroread ]; then
ACROREAD=/usr/local/bin/acroread
elif [ -x /usr/local/Acrobat5/bin/acroread ]; then
ACROREAD=/usr/local/Acrobat5/bin/acroread
fi
}
summary() {
case "${distro_id}" in
ubuntu|pop) apt show $1 2>/dev/null | grep ^Description | sed s/Description/$1/g;;
centos|rhel|opensuse-leap) rpm -qp --queryformat "%{name}: %{summary}\n" "${cd_path}/rpm/$1-*.rpm";;
*) return ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE};;
esac
}
info() {
case "${distro_id}" in
ubuntu|pop) apt show "$1";;
centos|rhel|opensuse-leap) rpm -qpi "${cd_path}/rpm/$1-*.rpm";;
*) return ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE};;
esac
}
prereq_check() {
if [ "`whoami`" != root ]; then
error_handler ${INSTALL_SCRIPT_ERROR_NOT_ROOT}
fi
get_bitness
if [ "${os_bitness}" -eq "32" ]; then
error_handler ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE}
fi
get_distro
case "${distro_id}" in
ubuntu|pop)
util_check "apt"
util_check "dpkg-query"
util_check "dpkg"
;;
centos|rhel)
util_check "yum"
util_check "rpm"
;;
opensuse-leap)
util_check "zypper"
util_check "rpm"
;;
*) error_handler ${INSTALL_SCRIPT_ERROR_INCOMPATIBLE};;
esac
return ${INSTALL_SCRIPT_ERROR_SUCCESS}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment