File:  [Coherent Logic Development] / freem / scripts / _fmd_common.bash
Revision 1.7: download - view: text, annotated - select for diffs
Mon Apr 14 14:34:07 2025 UTC (3 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Fix _fmd_common.bash syntax error

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

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