Annotation of freem/scripts/_fmd_common.bash, revision 1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>