]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/initscripts/system/functions
initskripts: remove buggy remount at halt and reboot
[people/pmueller/ipfire-2.x.git] / src / initscripts / system / functions
CommitLineData
73d9a908 1#!/bin/sh
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
73d9a908
MT
21
22## Environmental setup
23# Setup default values for environment
24umask 022
25export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
26
27# Signal sent to running processes to refresh their configuration
28RELOADSIG="HUP"
29
30# Number of seconds between STOPSIG and FALLBACK when stopping processes
cb1fb691 31KILLDELAY="10"
73d9a908
MT
32
33## Screen Dimensions
34# Find current screen size
35if [ -z "${COLUMNS}" ]; then
324bb888 36 COLUMNS=$(stty size 2>/dev/null)
73d9a908
MT
37 COLUMNS=${COLUMNS##* }
38fi
39
40# When using remote connections, such as a serial port, stty size returns 0
41if [ "${COLUMNS}" = "0" ]; then
42 COLUMNS=80
43fi
44
45## Measurements for positioning result messages
46COL=$((${COLUMNS} - 8))
47WCOL=$((${COL} - 2))
48
49## Set Cursor Position Commands, used via echo -e
50SET_COL="\\033[${COL}G" # at the $COL char
51SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
52CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
53
54## Set color commands, used via echo -e
55# Please consult `man console_codes for more information
56# under the "ECMA-48 Set Graphics Rendition" section
57#
58# Warning: when switching from a 8bit to a 9bit font,
59# the linux console will reinterpret the bold (1;) to
60# the top 256 glyphs of the 9bit font. This does
61# not affect framebuffer consoles
62NORMAL="\\033[0;39m" # Standard console grey
63SUCCESS="\\033[1;32m" # Success is green
64WARNING="\\033[1;33m" # Warnings are yellow
65FAILURE="\\033[1;31m" # Failures are red
66INFO="\\033[1;36m" # Information is light cyan
67BRACKET="\\033[1;34m" # Brackets are blue
68
69STRING_LENGTH="0" # the length of the current message
70
71#*******************************************************************************
72# Function - boot_mesg()
73#
74# Purpose: Sending information from bootup scripts to the console
75#
76# Inputs: $1 is the message
77# $2 is the colorcode for the console
78#
79# Outputs: Standard Output
80#
81# Dependencies: - sed for parsing strings.
82# - grep for counting string length.
83#
84# Todo:
85#*******************************************************************************
86boot_mesg()
87{
88 local ECHOPARM=""
89
90 while true
91 do
92 case "${1}" in
93 -n)
94 ECHOPARM=" -n "
95 shift 1
96 ;;
97 -*)
98 echo "Unknown Option: ${1}"
99 return 1
100 ;;
101 *)
102 break
103 ;;
104 esac
105 done
106
107 ## Figure out the length of what is to be printed to be used
108 ## for warning messges.
109 STRING_LENGTH="`echo "${1}" | sed \
110 -e 's,.,.,g' -e 'l 1' | grep -c \$`"
111
112 # Print the message to the screen
113 echo ${ECHOPARM} -e "${2}${1}"
114
115}
116
117boot_mesg_flush()
118{
119 # Reset STRING_LENGTH for next message
120 STRING_LENGTH="0"
121}
122
123boot_log()
124{
125 # Left in for backwards compatibility
126 echo -n ""
127}
128
129echo_ok()
130{
131 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]"
132 echo -e "${NORMAL}"
133 boot_mesg_flush
134}
135
136echo_failure()
137{
138 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]"
139 echo -e "${NORMAL}"
140 boot_mesg_flush
141}
142
143echo_warning()
144{
145 echo -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]"
146 echo -e "${NORMAL}"
147 boot_mesg_flush
148}
149
150print_error_msg()
151{
152 echo_failure
153 # $i is inherited by the rc script
154 boot_mesg -n "FAILURE:\n\nYou should not be reading this error message.\n\n" ${FAILURE}
155 boot_mesg -n " It means that an unforeseen error took"
156 boot_mesg -n " place in ${i}, which exited with a return value of"
157 boot_mesg " ${error_value}.\n"
158 boot_mesg_flush
159 boot_mesg -n "If you're able to track this"
160 boot_mesg -n " error down to a bug in one of the files provided by"
4601019b 161 boot_mesg -n " ipfire, please be so kind to inform us at"
31a36bb9 162 boot_mesg " https://bugzilla.ipfire.org.\n"
73d9a908 163 boot_mesg_flush
e147d1e6 164 boot_mesg -n "Press Enter to continue or wait a minute..." ${INFO}
73d9a908 165 boot_mesg "" ${NORMAL}
e147d1e6 166 read -t 60 ENTER
73d9a908
MT
167}
168
169check_script_status()
170{
171 # $i is inherited by the rc script
172 if [ ! -f ${i} ]; then
173 boot_mesg "${i} is not a valid symlink." ${WARNING}
174 echo_warning
175 continue
176 fi
177
178 if [ ! -x ${i} ]; then
179 boot_mesg "${i} is not executable, skipping." ${WARNING}
180 echo_warning
181 continue
182 fi
183}
184
185evaluate_retval()
186{
187 error_value="${?}"
188
189 if [ ${error_value} = 0 ]; then
190 echo_ok
191 else
192 echo_failure
193 fi
194
195 # This prevents the 'An Unexpected Error Has Occurred' from trivial
196 # errors.
197 return 0
198}
199
200print_status()
201{
202 if [ "${#}" = "0" ]; then
203 echo "Usage: ${0} {success|warning|failure}"
204 return 1
205 fi
206
207 case "${1}" in
208
209 success)
210 echo_ok
211 ;;
212
213 warning)
214 # Leave this extra case in because old scripts
215 # may call it this way.
216 case "${2}" in
217 running)
218 echo -e -n "${CURS_UP}"
219 echo -e -n "\\033[${STRING_LENGTH}G "
220 boot_mesg "Already running." ${WARNING}
221 echo_warning
222 ;;
223 not_running)
224 echo -e -n "${CURS_UP}"
225 echo -e -n "\\033[${STRING_LENGTH}G "
226 boot_mesg "Not running." ${WARNING}
227 echo_warning
228 ;;
229 not_available)
230 echo -e -n "${CURS_UP}"
231 echo -e -n "\\033[${STRING_LENGTH}G "
232 boot_mesg "Not available." ${WARNING}
233 echo_warning
234 ;;
235 *)
236 # This is how it is supposed to
237 # be called
238 echo_warning
239 ;;
240 esac
241 ;;
242
243 failure)
244 echo_failure
245 ;;
246
247 esac
248
249}
250
251reloadproc()
252{
253 if [ "${#}" = "0" ]; then
254 echo "Usage: reloadproc [{program}]"
255 exit 1
256 fi
257
258 getpids "${1}"
259
260 if [ -n "${pidlist}" ]; then
261 failure="0"
262 for pid in ${pidlist}
263 do
264 kill -"${RELOADSIG}" "${pid}" || failure="1"
265 done
266
267 (exit ${failure})
268 evaluate_retval
269
270 else
271 boot_mesg "Process ${1} not running." ${WARNING}
272 echo_warning
273 fi
274}
275
276statusproc()
277{
278 if [ "${#}" = "0" ]
279 then
280 echo "Usage: statusproc {program}"
281 exit 1
282 fi
283
284 getpids "${1}"
285
286 if [ -n "${pidlist}" ]; then
287 echo -e "${INFO}${base} is running with Process"\
288 "ID(s) ${pidlist}.${NORMAL}"
289 else
290 if [ -n "${base}" -a -e "/var/run/${base}.pid" ]; then
291 echo -e "${WARNING}${1} is not running but"\
292 "/var/run/${base}.pid exists.${NORMAL}"
293 else
294 if [ -n "${PIDFILE}" -a -e "${PIDFILE}" ]; then
295 echo -e "${WARNING}${1} is not running"\
296 "but ${PIDFILE} exists.${NORMAL}"
297 else
298 echo -e "${INFO}${1} is not running.${NORMAL}"
299 fi
300 fi
301 fi
302}
303
304# The below functions are documented in the LSB-generic 2.1.0
305
306#*******************************************************************************
307# Function - pidofproc [-s] [-p pidfile] pathname
308#
309# Purpose: This function returns one or more pid(s) for a particular daemon
310#
311# Inputs: -p pidfile, use the specified pidfile instead of pidof
312# pathname, path to the specified program
313#
314# Outputs: return 0 - Success, pid's in stdout
315# return 1 - Program is dead, pidfile exists
316# return 2 - Invalid or excessive number of arguments,
317# warning in stdout
318# return 3 - Program is not running
319#
320# Dependencies: pidof, echo, head
321#
322# Todo: Remove dependency on head
323# This depreciates getpids
324# Test changes to pidof
325#
326#*******************************************************************************
327pidofproc()
328{
329 local pidfile=""
330 local lpids=""
331 local silent=""
332 pidlist=""
333 while true
334 do
335 case "${1}" in
336 -p)
337 pidfile="${2}"
338 shift 2
339 ;;
340
341 -s)
342 # Added for legacy opperation of getpids
343 # eliminates several '> /dev/null'
344 silent="1"
345 shift 1
346 ;;
347 -*)
348 log_failure_msg "Unknown Option: ${1}"
349 return 2
350 ;;
351 *)
352 break
353 ;;
354 esac
355 done
356
357 if [ "${#}" != "1" ]; then
358 shift 1
359 log_failure_msg "Usage: pidofproc [-s] [-p pidfile] pathname"
360 return 2
361 fi
362
363 if [ -n "${pidfile}" ]; then
364 if [ ! -r "${pidfile}" ]; then
365 return 3 # Program is not running
366 fi
367
368 lpids=`head -n 1 ${pidfile}`
369 for pid in ${lpids}
370 do
371 if [ "${pid}" -ne "$$" -a "${pid}" -ne "${PPID}" ]; then
372 kill -0 "${pid}" > /dev/null &&
373 pidlist="${pidlist} ${pid}"
374 fi
375
376 if [ "${silent}" -ne "1" ]; then
377 echo "${pidlist}"
378 fi
379
380 test -z "${pidlist}" &&
381 # Program is dead, pidfile exists
382 return 1
383 # else
384 return 0
385 done
386
387 else
388 pidlist=`pidof -o $$ -o $PPID -x "$1"`
389 if [ "x${silent}" != "x1" ]; then
390 echo "${pidlist}"
391 fi
392
393 # Get provide correct running status
394 if [ -n "${pidlist}" ]; then
395 return 0
396 else
397 return 3
398 fi
399
400 fi
401
402 if [ "$?" != "0" ]; then
403 return 3 # Program is not running
404 fi
405}
406
407# This will ensure compatibility with previous LFS Bootscripts
408getpids()
409{
410 if [ -z "${PIDFILE}" ]; then
411 pidofproc -s -p "${PIDFILE}" $@
412 else
413 pidofproc -s $@
414 fi
415 base="${1##*/}"
416}
417
418#*******************************************************************************
419# Function - loadproc [-f] [-n nicelevel] [-p pidfile] pathname [args]
420#
421# Purpose: This runs the specified program as a daemon
422#
423# Inputs: -f, run the program even if it is already running
424# -n nicelevel, specifies a nice level. See nice(1).
425# -p pidfile, uses the specified pidfile
426# pathname, pathname to the specified program
427# args, arguments to pass to specified program
428#
429# Outputs: return 0 - Success
430# return 2 - Invalid of excessive number of arguments,
431# warning in stdout
432# return 4 - Program or service status is unknown
433#
434# Dependencies: nice
435#
436# Todo: LSB says this should be called start_daemon
437# LSB does not say that it should call evaluate_retval
438# It checks for PIDFILE, which is deprecated.
439# Will be removed after BLFS 6.0
440# loadproc returns 0 if program is already running, not LSB compliant
441#
442#*******************************************************************************
443loadproc()
444{
0c7ba652 445 local background=""
73d9a908
MT
446 local pidfile=""
447 local forcestart=""
b64d57aa 448 local nicelevel=""
73d9a908
MT
449
450# This will ensure compatibility with previous LFS Bootscripts
451 if [ -n "${PIDFILE}" ]; then
452 pidfile="${PIDFILE}"
453 fi
454
455 while true
456 do
457 case "${1}" in
0c7ba652
MT
458 -b)
459 background="1"
460 shift 1
461 ;;
73d9a908
MT
462 -f)
463 forcestart="1"
464 shift 1
465 ;;
466 -n)
467 nicelevel="${2}"
468 shift 2
469 ;;
470 -p)
471 pidfile="${2}"
472 shift 2
473 ;;
474 -*)
475 log_failure_msg "Unknown Option: ${1}"
476 return 2 #invalid or excess argument(s)
477 ;;
478 *)
479 break
480 ;;
481 esac
482 done
483
484 if [ "${#}" = "0" ]; then
485 log_failure_msg "Usage: loadproc [-f] [-n nicelevel] [-p pidfile] pathname [args]"
486 return 2 #invalid or excess argument(s)
487 fi
488
489 if [ -z "${forcestart}" ]; then
490 if [ -z "${pidfile}" ]; then
491 pidofproc -s "${1}"
492 else
493 pidofproc -s -p "${pidfile}" "${1}"
494 fi
495
496 case "${?}" in
497 0)
498 log_warning_msg "Unable to continue: ${1} is running"
499 return 0 # 4
500 ;;
501 1)
502 log_warning_msg "Unable to continue: ${pidfile} exists"
503 return 0 # 4
504 ;;
505 3)
506 ;;
507 *)
508 log_failure_msg "Unknown error code from pidofproc: ${?}"
509 return 4
510 ;;
511 esac
512 fi
513
b64d57aa
MT
514 local cmd="${@}"
515
516 if [ -n "${nicelevel}" ]; then
517 cmd="nice -n "${nicelevel}" ${cmd}"
518 fi
519
0c7ba652
MT
520 if [ -n "${background}" ]; then
521 (
522 ${cmd} &>/dev/null
523 ) &
524 evaluate_retval
525 else
526 ${cmd}
527 evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
528 fi
529
73d9a908
MT
530 return 0
531}
532
533#*******************************************************************************
534# Function - killproc [-p pidfile] pathname [signal]
535#
536# Purpose:
537#
538# Inputs: -p pidfile, uses the specified pidfile
539# pathname, pathname to the specified program
540# signal, send this signal to pathname
541#
542# Outputs: return 0 - Success
543# return 2 - Invalid of excessive number of arguments,
544# warning in stdout
545# return 4 - Unknown Status
546#
547# Dependencies: kill
548#
549# Todo: LSB does not say that it should call evaluate_retval
550# It checks for PIDFILE, which is deprecated.
551# Will be removed after BLFS 6.0
552#
553#*******************************************************************************
554killproc()
555{
556 local pidfile=""
557 local killsig=""
558 pidlist=""
559
560# This will ensure compatibility with previous LFS Bootscripts
561 if [ -n "${PIDFILE}" ]; then
562 pidfile="${PIDFILE}"
563 fi
564
565 while true
566 do
567 case "${1}" in
568 -p)
569 pidfile="${2}"
570 shift 2
571 ;;
572 -*)
573 log_failure_msg "Unknown Option: ${1}"
574 return 2
575 ;;
576 *)
577 break
578 ;;
579 esac
580 done
581
582 if [ "${#}" = "2" ]; then
583 killsig="${2}"
584 elif [ "${#}" != "1" ]; then
585 shift 2
586 log_failure_msg "Usage: killproc [-p pidfile] pathname [signal]"
587 return 2
588 fi
589
590 if [ -z "${pidfile}" ]; then
591 pidofproc -s "${1}"
592 else
593 pidofproc -s -p "${pidfile}" "${1}"
594 fi
595
596 # Change....
597 if [ -n "${pidlist}" ]; then
598 for pid in ${pidlist}
599 do
600 kill -${killsig:-TERM} ${pid} 2>/dev/null
601 if [ -z "${killsig}" ]; then
602 # Wait up to 3 seconds, for ${pid} to terminate
603 local dtime=${KILLDELAY}
604 while [ "${dtime}" != "0" ]
605 do
606 kill -0 ${pid} 2>/dev/null || break
607 sleep 1
608 dtime=$(( ${dtime} - 1))
609 done
610 # If ${pid} is still running, kill it
611 kill -0 ${pid} 2>/dev/null && kill -KILL ${pid} 2>/dev/null
612 fi
613 done
614
615 if [ -z "${killsig}" ]; then
616 pidofproc -s "${1}"
617
618 # Program was terminated
619 if [ "$?" != "0" ]; then
620 # Pidfile Exists
621 if [ -f "${pidfile}" ]; then
622 rm -f "${pidfile}"
623 fi
624 echo_ok
625 return 0
626 else # Program is still running
627 echo_failure
628 return 4 # Unknown Status
629 fi
630 else
631 if [ -z "${pidfile}" ]; then
632 pidofproc -s "${1}"
633 else
634 pidofproc -s -p "${pidfile}" "${1}"
635 fi
636 fi
637
638 evaluate_retval # This is "Probably" not LSB compliant, but required to be compatible with older bootscripts
639
640 else
641 print_status warning not_running
642 fi
643}
644
645
646#*******************************************************************************
647# Function - log_success_msg "message"
648#
649# Purpose: Print a success message
650#
651# Inputs: $@ - Message
652#
653# Outputs: Text output to screen
654#
655# Dependencies: echo
656#
657# Todo: logging
658#
659#*******************************************************************************
660log_success_msg()
661{
662 echo -n -e "${BOOTMESG_PREFIX}${@}"
663 echo -e "${SET_COL}""${BRACKET}""[""${SUCCESS}"" OK ""${BRACKET}""]""${NORMAL}"
664 return 0
665}
666
667#*******************************************************************************
668# Function - log_failure_msg "message"
669#
670# Purpose: Print a failure message
671#
672# Inputs: $@ - Message
673#
674# Outputs: Text output to screen
675#
676# Dependencies: echo
677#
678# Todo: logging
679#
680#*******************************************************************************
681log_failure_msg() {
682 echo -n -e "${BOOTMESG_PREFIX}${@}"
683 echo -e "${SET_COL}""${BRACKET}""[""${FAILURE}"" FAIL ""${BRACKET}""]""${NORMAL}"
684 return 0
685}
686
687#*******************************************************************************
688# Function - log_warning_msg "message"
689#
690# Purpose: print a warning message
691#
692# Inputs: $@ - Message
693#
694# Outputs: Text output to screen
695#
696# Dependencies: echo
697#
698# Todo: logging
699#
700#*******************************************************************************
701log_warning_msg() {
702 echo -n -e "${BOOTMESG_PREFIX}${@}"
703 echo -e "${SET_COL}""${BRACKET}""[""${WARNING}"" WARN ""${BRACKET}""]""${NORMAL}"
704 return 0
705}
706
0e42072a 707run_subdir() {
905fbf3e
MT
708 DIR=$1
709 for i in $(ls -v ${DIR}* 2> /dev/null); do
0e42072a
MT
710 check_script_status
711 OUT=$(echo $(basename ${i}) | awk -F- '{ print $2 }')
712 case "$OUT" in
713 S) ${i} start ;;
714 K) ${i} stop ;;
715 RS) ${i} restart ;;
716 RL) ${i} reload ;;
ebca0d9a 717 U) ${i} up ;;
905fbf3e 718 D) ${i} down ;;
0e42072a
MT
719 *) ${i} ;;
720 esac
721 done
378cbbe0
MT
722}
723
c4a451ee
AM
724mem_amount() {
725 local pagesize="$(getconf PAGESIZE)"
726 local pages="$(getconf _PHYS_PAGES)"
727
728 echo "$(( ${pagesize} * ${pages} / 1024 / 1024 ))"
729}
730
ee3dec50
MT
731use_ramdisk() {
732 eval $(/usr/local/bin/readhash /etc/sysconfig/ramdisk)
733
734 case "${RAMDISK_MODE}" in
735 # Don't use ramdisk
736 0)
737 return 1
738 ;;
739
740 # Always use ramdisk
741 1)
742 return 0
743 ;;
744
745 # Automatic mode - use ramdisk if sufficient
746 # memory is available
747 2)
748 local mem_avail="$(mem_amount)"
749
c83d1614 750 if [ ${mem_avail} -ge 400 ]; then
ee3dec50
MT
751 return 0
752 else
753 return 1
754 fi
755 ;;
756
757 # Fail for everything else
758 *)
759 return 2
760 ;;
761 esac
762}
763
c4a451ee 764mount_ramdisk() {
6146d190
MT
765 local path="${1}"
766 local path_tmpfs="${path}.tmpfs"
c4a451ee 767
6146d190
MT
768 # Check if the ramdisk is already mounted
769 if mountpoint "${path}" &>/dev/null; then
770 return 0
c4a451ee 771 fi
c4a451ee 772
6146d190
MT
773 # Create ramdisk
774 mkdir -p "${path_tmpfs}"
775 mount -t tmpfs none "${path_tmpfs}"
776
777 # Restore ramdisk content
24f2144d 778 cp -pR ${path}/* "${path_tmpfs}"
5258a65d 779
6146d190
MT
780 # Move ramdisk to final destination
781 mount --move "${path_tmpfs}" "${path}"
b5e1360e 782 rm -rf "${path_tmpfs}"
c4a451ee
AM
783}
784
6146d190
MT
785umount_ramdisk() {
786 local path="${1}"
787 local path_tmpfs="${path}.tmpfs"
788
789 # Check if a ramdisk is actually mounted
790 if ! mountpoint "${path}" &>/dev/null; then
791 return 0
c4a451ee 792 fi
6146d190
MT
793
794 # Move the ramdisk
795 mkdir -p "${path_tmpfs}"
796 mount --move "${path}" "${path_tmpfs}"
797
798 # Backup ramdisk content
24f2144d 799 cp -pR ${path_tmpfs}/* "${path}"
6146d190
MT
800
801 # Destroy the ramdisk
802 umount "${path_tmpfs}"
b5e1360e 803 rm -rf "${path_tmpfs}"
c4a451ee 804}
5258a65d 805
0e457b13
MT
806# Returns true when this system running in a virtual environment
807running_on_hypervisor() {
808 grep -qE "^flags\s+:.*hypervisor" /proc/cpuinfo
809}
810
8bd0c4b1
MT
811# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
812running_on_ec2() {
813 local uuid
814
8bd0c4b1
MT
815 # Check if the DMI product UUID starts with EC2
816 if [ -r "/sys/devices/virtual/dmi/id/product_uuid" ]; then
817 uuid=$(</sys/devices/virtual/dmi/id/product_uuid)
818
80b1dc64
MT
819 # Convert the UUID as uppercase
820 uuid="${uuid^^}"
821
8bd0c4b1
MT
822 [ "${uuid:0:3}" = "EC2" ] && return 0
823 fi
824
825 # We are not running on AWS EC2
826 return 1
827}
828
829running_on_azure() {
830 # Check if the vendor is Microsoft
831 if [ -r "/sys/devices/virtual/dmi/id/sys_vendor" ] && \
832 [ "$(</sys/devices/virtual/dmi/id/sys_vendor)" = "Microsoft Corporation" ]; then
833 # Check if this product is a "Virtual Machine"
834 if [ -r "/sys/devices/virtual/dmi/id/product_name" ] && \
835 [ "$(</sys/devices/virtual/dmi/id/product_name)" = "Virtual Machine" ]; then
836 # Yes, we are running on Azure
837 return 0
838 fi
839 fi
840
841 # We are not running on Azure
842 return 1
843}
844
5ae3706d
MT
845running_on_exoscale() {
846 if [ -r "/sys/devices/virtual/dmi/id/sys_vendor" ]; then
847 local sys_vendor="$(</sys/devices/virtual/dmi/id/sys_vendor)"
848
849 [ "${sys_vendor}" = "Exoscale" ] && return 0
850 fi
851
852 # We are not running on Exoscale
853 return 1
854}
855
86c64598
MT
856running_on_gcp() {
857 # Check if the BIOS vendor is "Google"
858 if [ -r "/sys/devices/virtual/dmi/id/bios_vendor" ]; then
859 local bios_vendor="$(</sys/devices/virtual/dmi/id/bios_vendor)"
860
861 [ "${bios_vendor}" = "Google" ] && return 0
862 fi
863
864 # We are not running on GCP
865 return 1
866}
867
7c24a0d9
MT
868running_on_oci() {
869 if [ -r "/sys/devices/virtual/dmi/id/chassis_asset_tag" ]; then
870 local asset_tag="$(</sys/devices/virtual/dmi/id/chassis_asset_tag)"
871
872 [ "${asset_tag}" = "OracleCloud.com" ] && return 0
873 fi
874
875 # We are not running on OCI
876 return 1
877}