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

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

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