add check_osdb.py
This commit is contained in:
49
check_osdb.py
Executable file
49
check_osdb.py
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/python3
|
||||
#coding=utf-8
|
||||
import subprocess
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
recognized = [ "debian", "arch" ]
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--verbose", "-v", action="store_true")
|
||||
parser.add_argument("--expect")
|
||||
args = parser.parse_args()
|
||||
|
||||
quiet = not args.verbose
|
||||
|
||||
try:
|
||||
with open("/etc/os-release") as f:
|
||||
lines = f.read().splitlines()
|
||||
except Exception as e:
|
||||
print(f"UNKNOWN - {e}")
|
||||
sys.exit(3)
|
||||
|
||||
detected_os = None
|
||||
like_os = None
|
||||
|
||||
for line in lines:
|
||||
if line.startswith("ID_LIKE="):
|
||||
for os in recognized:
|
||||
if os in line:
|
||||
like_os = os
|
||||
if line.startswith("ID="):
|
||||
for os in recognized:
|
||||
if os in line:
|
||||
detected_os = os
|
||||
|
||||
if not detected_os:
|
||||
if like_os:
|
||||
detected_os = like_os
|
||||
else:
|
||||
detected_os = "unknown"
|
||||
|
||||
if detected_os == args.expect:
|
||||
print("OK - OS matches")
|
||||
sys.exit(0)
|
||||
|
||||
if args.expect != detected_os:
|
||||
print(f"CRITICAL - MISSMATCH DETECTED {detected_os} != {args.expect}")
|
||||
sys.exit(2)
|
||||
Reference in New Issue
Block a user