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