chg: [installer] One step closer to "sane" aka. generic os-detection

pull/4826/head
Steve Clement 2019-07-01 15:46:14 +09:00
parent 4d590160da
commit fe16c017ce
No known key found for this signature in database
GPG Key ID: 69A20F509BE4AEE9
8 changed files with 187 additions and 17 deletions

View File

@ -232,9 +232,14 @@ setOpt () {
done
}
# check if command_exists
command_exists() {
command -v "$@" > /dev/null 2>&1
}
# TODO: fix os detection mess
# Try to detect what we are running on
checkCoreOS () {
# lsb_release can exist on any platform. RedHat package: redhat-lsb
LSB_RELEASE=$(which lsb_release > /dev/null ; echo $?)
APT=$(which apt > /dev/null 2>&1; echo -n $?)
@ -256,12 +261,63 @@ checkCoreOS () {
# Extract debian flavour
checkFlavour () {
if [ -z $(which lsb_release) ]; then
checkAptLock
sudo apt install lsb-release dialog -y
lsb_dist=""
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
FLAVOUR="$(. /etc/os-release && echo "$ID"| tr '[:upper:]' '[:lower:]')"
fi
FLAVOUR=$(lsb_release -s -i |tr '[:upper:]' '[:lower:]')
case "$FLAVOUR" in
ubuntu)
if command_exists lsb_release; then
dist_version="$(lsb_release --codename | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
fi
;;
debian|raspbian)
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
10)
dist_version="buster"
;;
9)
dist_version="stretch"
;;
esac
;;
centos)
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
echo "$lsb_dist not supported at the moment"
exit 1
;;
rhel|ol|sles)
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
echo "$lsb_dist not supported at the moment"
exit 1
;;
*)
if command_exists lsb_release; then
dist_version="$(lsb_release --release | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
;;
esac
# FIXME: The below want to be refactored
if [ FLAVOUR == "ubuntu" ]; then
RELEASE=$(lsb_release -s -r)
debug "We detected the following Linux flavour: ${YELLOW}$(tr '[:lower:]' '[:upper:]' <<< ${FLAVOUR:0:1})${FLAVOUR:1} ${RELEASE}${NC}"
@ -2359,6 +2415,35 @@ fi
[[ -n $NUKE ]] && nuke && exit
# TODO: Move support map to top
SUPPORT_MAP="
x86_64-centos-8
x86_64-rhel-7
x86_64-rhel-8
x86_64-fedora-30
x86_64-debian-stretch
x86_64-debian-buster
x86_64-ubuntu-bionic
armv6l-raspbian-stretch
armv7l-raspbian-stretch
armv7l-debian-jessie
armv7l-debian-stretch
armv7l-debian-buster
armv7l-ubuntu-bionic
"
# Check if we actually support this configuration
if ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; then
cat >&2 <<-'EOF'
Either your platform is not easily detectable or is not supported by this
installer script.
Please visit the following URL for more detailed installation instructions:
https://misp.github.io/MISP/
EOF
exit 1
fi
# If Ubuntu is detected, figure out which release it is and run the according scripts
if [ "${FLAVOUR}" == "ubuntu" ]; then
RELEASE=$(lsb_release -s -r| tr '[:upper:]' '[:lower:]')

View File

@ -1,5 +1,5 @@
; Generated by RHash v1.3.8 on 2019-06-27 at 21:03.22
; Generated by RHash v1.3.8 on 2019-07-01 at 15:45.16
; Written by Kravchenko Aleksey (Akademgorodok) - http://rhash.sf.net/
;
; 95577 21:03.22 2019-06-27 INSTALL.sh
INSTALL.sh 5519CED9CB797C6C285215E4865337E876BDB37D 42BE710D6484F3533D5690175C293E4E87CB8F1810C3506B0B1783E16EF44C6A D47422C0756C89A47FC682F7E1B0F2661B88A132189F716AA335C6CB5EB71750AB975AE97054B2BFE3DC8EC6FC933D1D E650E66B36D85DA19243B15AFD91B754B51E52A5746556848B60B8953C1B76DF5A7A2489BA5F688C2D6C5B34EB27C34142DAD22E2FD2385568141C2566937314
; 97737 15:45.16 2019-07-01 INSTALL.sh
INSTALL.sh CC5E83EEE4B6A3DA6B9E819F632EE36FEA8E6E2D 7D19B435AB944E1E0B9109BD77C9934C21C697A3275F8F87758093391D790495 59CB8E2ECB63930C0F41DE60E6506B19087C8AD71431FE6E940ED131F703F84BF24B1F5830E55CE9A042F0933BD7CF1C 20693377790107BB58EE1075446594822E037E3C37C0F31F68E55477418F177C614D9AC791F96BF57BFD8E257DAF61B55F89D4887EF58D8CC139174563B0EBD3

View File

@ -1 +1 @@
5519ced9cb797c6c285215e4865337e876bdb37d INSTALL.sh
cc5e83eee4b6a3da6b9e819f632ee36fea8e6e2d INSTALL.sh

View File

@ -1 +1 @@
42be710d6484f3533d5690175c293e4e87cb8f1810c3506b0b1783e16ef44c6a INSTALL.sh
7d19b435ab944e1e0b9109bd77c9934c21c697a3275f8f87758093391d790495 INSTALL.sh

View File

@ -1 +1 @@
d47422c0756c89a47fc682f7e1b0f2661b88a132189f716aa335c6cb5eb71750ab975ae97054b2bfe3dc8ec6fc933d1d INSTALL.sh
59cb8e2ecb63930c0f41de60e6506b19087c8ad71431fe6e940ed131f703f84bf24b1f5830e55ce9a042f0933bd7cf1c INSTALL.sh

View File

@ -1 +1 @@
e650e66b36d85da19243b15afd91b754b51e52a5746556848b60b8953c1b76df5a7a2489ba5f688c2d6c5b34eb27c34142dad22e2fd2385568141c2566937314 INSTALL.sh
20693377790107bb58ee1075446594822e037e3c37c0f31f68e55477418f177c614d9ac791f96bf57bfd8e257daf61b55f89d4887ef58d8cc139174563b0ebd3 INSTALL.sh

View File

@ -667,6 +667,35 @@ fi
[[ -n $NUKE ]] && nuke && exit
# TODO: Move support map to top
SUPPORT_MAP="
x86_64-centos-8
x86_64-rhel-7
x86_64-rhel-8
x86_64-fedora-30
x86_64-debian-stretch
x86_64-debian-buster
x86_64-ubuntu-bionic
armv6l-raspbian-stretch
armv7l-raspbian-stretch
armv7l-debian-jessie
armv7l-debian-stretch
armv7l-debian-buster
armv7l-ubuntu-bionic
"
# Check if we actually support this configuration
if ! echo "$SUPPORT_MAP" | grep "$(uname -m)-$lsb_dist-$dist_version" >/dev/null; then
cat >&2 <<-'EOF'
Either your platform is not easily detectable or is not supported by this
installer script.
Please visit the following URL for more detailed installation instructions:
https://misp.github.io/MISP/
EOF
exit 1
fi
# If Ubuntu is detected, figure out which release it is and run the according scripts
if [ "${FLAVOUR}" == "ubuntu" ]; then
RELEASE=$(lsb_release -s -r| tr '[:upper:]' '[:lower:]')

View File

@ -78,9 +78,14 @@ setOpt () {
done
}
# check if command_exists
command_exists() {
command -v "$@" > /dev/null 2>&1
}
# TODO: fix os detection mess
# Try to detect what we are running on
checkCoreOS () {
# lsb_release can exist on any platform. RedHat package: redhat-lsb
LSB_RELEASE=$(which lsb_release > /dev/null ; echo $?)
APT=$(which apt > /dev/null 2>&1; echo -n $?)
@ -102,12 +107,63 @@ checkCoreOS () {
# Extract debian flavour
checkFlavour () {
if [ -z $(which lsb_release) ]; then
checkAptLock
sudo apt install lsb-release dialog -y
lsb_dist=""
# Every system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
FLAVOUR="$(. /etc/os-release && echo "$ID"| tr '[:upper:]' '[:lower:]')"
fi
FLAVOUR=$(lsb_release -s -i |tr '[:upper:]' '[:lower:]')
case "$FLAVOUR" in
ubuntu)
if command_exists lsb_release; then
dist_version="$(lsb_release --codename | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
fi
;;
debian|raspbian)
dist_version="$(sed 's/\/.*//' /etc/debian_version | sed 's/\..*//')"
case "$dist_version" in
10)
dist_version="buster"
;;
9)
dist_version="stretch"
;;
esac
;;
centos)
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
echo "$lsb_dist not supported at the moment"
exit 1
;;
rhel|ol|sles)
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
echo "$lsb_dist not supported at the moment"
exit 1
;;
*)
if command_exists lsb_release; then
dist_version="$(lsb_release --release | cut -f2)"
fi
if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
fi
;;
esac
# FIXME: The below want to be refactored
if [ FLAVOUR == "ubuntu" ]; then
RELEASE=$(lsb_release -s -r)
debug "We detected the following Linux flavour: ${YELLOW}$(tr '[:lower:]' '[:upper:]' <<< ${FLAVOUR:0:1})${FLAVOUR:1} ${RELEASE}${NC}"