Annotation of freem/scripts/_fmd_common.bash, revision 1.1
1.1 ! snw 1: #
! 2: # $Id$
! 3: # fmd common functions
! 4: #
! 5: #
! 6: # Author: Serena Willis <snw@coherent-logic.com>
! 7: # Copyright (C) 2025 Coherent Logic Development LLC
! 8: #
! 9: #
! 10: # This file is part of FreeM.
! 11: #
! 12: # FreeM is free software: you can redistribute it and/or modify
! 13: # it under the terms of the GNU Affero Public License as published by
! 14: # the Free Software Foundation, either version 3 of the License, or
! 15: # (at your option) any later version.
! 16: #
! 17: # FreeM is distributed in the hope that it will be useful,
! 18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 20: # GNU Affero Public License for more details.
! 21: #
! 22: # You should have received a copy of the GNU Affero Public License
! 23: # along with FreeM. If not, see <https://www.gnu.org/licenses/>.
! 24: #
! 25: # $Log$
! 26: #
! 27: # SPDX-FileCopyrightText: (C) 2025 Coherent Logic Development LLC
! 28: # SPDX-License-Identifier: AGPL-3.0-or-later
! 29: #
! 30:
! 31: function _fmd_os_detect()
! 32: {
! 33: export _fmd_uname=$(uname -a)
! 34: export _fmd_kernel=$(uname | tr '[:upper:]' '[:lower:]')
! 35:
! 36: _fmd_can_package=0
! 37:
! 38: case $_fmd_kernel in
! 39:
! 40: sunos)
! 41: export _fmd_arch=$(isainfo | cut -d" " -f2)
! 42: export _fmd_subarch=$(isainfo | cut -d" " -f1)
! 43: export _fmd_osversion=$(echo "${_fmd_uname}" | cut -d" " -f3)
! 44:
! 45: local distname=$(cat /etc/release | head -1 | awk '{print $1}')
! 46: case $distname in
! 47: Solaris)
! 48: export _fmd_distribution="solaris"
! 49: ;;
! 50: Oracle)
! 51: export _fmd_distribution="solaris"
! 52: ;;
! 53: OpenIndiana)
! 54: export _fmd_distribution="openindiana"
! 55: export _fmd_distfamily="illumos"
! 56: ;;
! 57: *)
! 58: export _fmd_distribution="unknown"
! 59: ;;
! 60: esac
! 61:
! 62: ##
! 63: # account for systems like Oracle Solaris 11
! 64: # that do not have the traditional pkgadd infrastructure
! 65: #
! 66: which pkgtrans &> /dev/null
! 67: if [[ $? == 0 ]]
! 68: then
! 69: export _fmd_can_package=1
! 70: export _fmd_pkg_mechanism="pkgadd"
! 71: else
! 72: export _fmd_can_package=0
! 73: fi
! 74: ;;
! 75:
! 76: netbsd)
! 77: export _fmd_arch=$(echo "{_fmd_uname}" | awk '{ print $NF }')
! 78: export _fmd_subarch=${_fmd_arch}
! 79: export _fmd_osversion=$(echo $"{_fmd_uname}" | awk '{ print $3 }')
! 80: export _fmd_distribution="netbsd"
! 81: export _fmd_distfamily="bsd"
! 82: export _fmd_can_package=1
! 83: export _fmd_pkg_mechanism="pkgsrc"
! 84: ;;
! 85:
! 86: freebsd)
! 87: export _fmd_arch=$(echo "${_fmd_uname}" | awk '{ print $NF }')
! 88: export _fmd_subarch=${_fmd_arch}
! 89: export _fmd_osversion=$(echo "${_fmd_uname}" | awk '{ print $3 }')
! 90: export _fmd_distribution="freebsd"
! 91: export _fmd_distfamily="bsd"
! 92: export _fmd_can_package=0
! 93: ;;
! 94:
! 95: openbsd)
! 96: export _fmd_arch=$(echo "${_fmd_uname}" | awk '{ print $NF }')
! 97: export _fmd_subarch=${_fmd_arch}
! 98: export _fmd_osversion=$(echo "${_fmd_uname}" | awk '{ print $3 }')
! 99: export _fmd_distribution="openbsd"
! 100: export _fmd_distfamily="bsd"
! 101: export _fmd_can_package=0
! 102: ;;
! 103:
! 104: osf1)
! 105: export _fmd_arch="alpha"
! 106: export _fmd_subarch="alpha"
! 107: export _fmd_osversion=$(echo "${_fmd_uname}" | awk '{ print $3 }')
! 108: export _fmd_distribution="tru64"
! 109: export _fmd_distfamily="osf1"
! 110: export _fmd_can_package=0
! 111: ;;
! 112:
! 113: sco_sv)
! 114: export _fmd_arch="i386"
! 115: export _fmd_subarch="i386"
! 116: export _fmd_osversion=$(echo "${_fmd_uname}" | awk '{ print $4 }')
! 117: export _fmd_distribution="sco"
! 118: ;;
! 119:
! 120: linux)
! 121: export _fmd_subarch=$(echo "${_fmd_uname}" | awk '{ print $(NF - 1) }')
! 122: export _fmd_arch="${_fmd_subarch}"
! 123:
! 124: which lsb_release &> /dev/null;
! 125: if [[ $? == 0 ]]
! 126: then
! 127: local distname=$(lsb_release -i | awk '{print $3}' | tr '[:upper:]' '[:lower:]')
! 128: export _fmd_osversion=$(lsb_release -r | awk '{print $2}' | tr '[:upper:]' '[:lower:]')
! 129: else
! 130: local distfound=0
! 131:
! 132: if [[ -f /etc/redhat-release ]]
! 133: then
! 134: distfound=1
! 135: export _fmd_osversion=$(cat /etc/redhat-release | cut -d'(' -f1 | awk '{ print $NF }')
! 136: local distname=$(cat /etc/redhat-release | awk '{ print $1 }' | tr '[:upper]' '[:lower:]')
! 137: fi
! 138:
! 139: if [[ -f /etc/debian_version ]]
! 140: then
! 141: ##
! 142: # note that /etc/debian_version exists on Ubuntu
! 143: # as well, but Ubuntu always has `lsb_release` AFAIK,
! 144: # so Ubuntu systems should never reach this block
! 145: #
! 146: distfound=1
! 147: export _fmd_osversion=$(cat /etc/debian_version)
! 148: local distname="debian"
! 149: fi
! 150:
! 151: if [[ -f /etc/slackware-version ]]
! 152: then
! 153: distfound=1
! 154: local distname="slackware"
! 155: fi
! 156:
! 157: if [[ $distfound == 0 ]]
! 158: then
! 159: local distname="unknown"
! 160: fi
! 161: fi
! 162:
! 163: case $distname in
! 164: arch)
! 165: export _fmd_distribution="arch"
! 166: export _fmd_distfamily="arch"
! 167: export _fmd_can_package=0
! 168: export _fmd_pkg_mechanism="pacman"
! 169: ;;
! 170:
! 171: debian)
! 172: export _fmd_distribution="debian"
! 173: export _fmd_distfamily="debian"
! 174: export _fmd_can_package=1
! 175: export _fmd_pkg_mechanism="dpkg"
! 176: ;;
! 177:
! 178: ubuntu)
! 179: export _fmd_distribution="ubuntu"
! 180: export _fmd_distfamily="debian"
! 181: export _fmd_can_package=1
! 182: export _fmd_pkg_mechanism="dpkg"
! 183: ;;
! 184:
! 185: linuxmint)
! 186: export _fmd_distribution="mint"
! 187: export _fmd_distfamily="debian"
! 188: export _fmd_can_package=1
! 189: export _fmd_pkg_mechanism="dpkg"
! 190: ;;
! 191:
! 192: slackware)
! 193: export _fmd_distribution="slackware"
! 194: export _fmd_distfamily="slackware"
! 195: export _fmd_can_package=0
! 196: export _fmd_pkg_mechanism="txz"
! 197: ;;
! 198:
! 199: opensuse)
! 200: export _fmd_distribution="opensuse"
! 201: export _fmd_distfamily="suse"
! 202: export _fmd_can_package=0
! 203: export _fmd_pkg_mechanism="rpm+zypper"
! 204: ;;
! 205:
! 206: rocky)
! 207: export _fmd_distribution="rocky"
! 208: export _fmd_distfamily="redhat"
! 209: export _fmd_can_package=1
! 210: export _fmd_pkg_mechanism="rpm+yum"
! 211: ;;
! 212:
! 213: fedora)
! 214: export _fmd_distribution="fedora"
! 215: export _fmd_distfamily="redhat"
! 216: export _fmd_can_package=1
! 217: export _fmd_pkg_mechanism="rpm+dnf"
! 218: ;;
! 219:
! 220: unknown)
! 221: export _fmd_distribution="unknown"
! 222: export _fmd_distfamily="unknown"
! 223: export _fmd_can_package=0
! 224: ;;
! 225:
! 226: esac
! 227: ;;
! 228: esac
! 229:
! 230: }
! 231:
! 232: function _fmd_repo_detect()
! 233: {
! 234: if [[ ! -f sem.ver ]]
! 235: then
! 236: echo "fmd: $(pwd) is not a FreeM repository"
! 237: exit 1
! 238: fi
! 239:
! 240: export _fmd_freem_version=$(cat sem.ver)
! 241: }
! 242:
! 243: function _fmd_loadconfig()
! 244: {
! 245: export _fmd_cvsuser=$(cat "${_fmd_rc}" | grep "user=" | cut -d= -f2)
! 246: export _fmd_email=$(cat "${_fmd_rc}" | grep "email=" | cut -d= -f2)
! 247: export _fmd_fullname=$(cat "${_fmd_rc}" | grep "fullname=" | cut -d= -f2)
! 248: }
! 249:
! 250: function _fmd_reconfig()
! 251: {
! 252: echo
! 253: echo
! 254: echo -n "What is your username on cvs.coherent-logic.com? "
! 255: read _fmd_cvsuser
! 256: echo -n "What e-mail address do you want to use for FreeM contributions? "
! 257: read _fmd_email
! 258: echo -n "What is your full name? "
! 259: read _fmd_fullname
! 260: echo "user=${_fmd_cvsuser}" > "${_fmd_rc}"
! 261: echo "email=${_fmd_email}" >> "${_fmd_rc}"
! 262: echo "fullname=${_fmd_fullname}" >> "${_fmd_rc}"
! 263: echo
! 264: echo "fmd: wrote ${_fmd_rc}"
! 265: }
! 266:
! 267: function _fmd_chkconfig()
! 268: {
! 269: export _fmd_rc="${HOME}/.fmdrc"
! 270:
! 271: if [[ ! -f "${_fmd_rc}" ]]
! 272: then
! 273: echo "fmd: not configured"
! 274: _fmd_reconfig
! 275: fi
! 276:
! 277: _fmd_loadconfig
! 278: }
! 279:
! 280: function _fmd_commands()
! 281: {
! 282: ls -1 ${_fmd_script_dir}/fmd-* | cut -d'-' -f2 | grep -v "~"
! 283: }
! 284:
! 285: SCRIPT_DIR=$(dirname "$0")
! 286: export _fmd_script_dir="${SCRIPT_DIR}"
! 287:
! 288: _fmd_chkconfig
! 289: _fmd_repo_detect
! 290: _fmd_os_detect
! 291:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>