#!/usr/bin/env bash{l_pkgoutput=""l_output=""l_output2=""# Check if GNOME Desktop Manager is installed. If package isn't installed, recommendation is Not Applicable\n# determine system's package managerifcommand-vdpkg-query>/dev/null2>&1;thenl_pq="dpkg-query -W"elifcommand-vrpm>/dev/null2>&1;thenl_pq="rpm -q"fi# Check if GDM is installedl_pcl="gdm gdm3"# Space separated list of packages to checkforl_pnin$l_pcl;do$l_pq"$l_pn">/dev/null2>&1&&l_pkgoutput="$l_pkgoutput\n - Package: \"$l_pn\" exists on the system\n - checking configuration"echo-e"$l_pkgoutput"done# Check configuration (If applicable)if[-n"$l_pkgoutput"];thenecho-e"$l_pkgoutput"# Look for existing settings and set variables if they existl_kfile="$(grep-Prils--'^\h*autorun-never\b'/etc/dconf/db/*.d)"# Set profile name based on dconf db directory ({PROFILE_NAME}.d)if[-f"$l_kfile"];thenl_gpname="$(awk-F\/'{split($(NF-1),a,".");print a[1]}'<<<"$l_kfile")"fi# If the profile name exist, continue checksif[-n"$l_gpname"];thenl_gpdir="/etc/dconf/db/$l_gpname.d"# Check if profile file existsifgrep-Pq--"^\h*system-db:$l_gpname\b"/etc/dconf/profile/*;thenl_output="$l_output\n - dconf database profile file \"$(grep-Pl--"^\h*system-db:$l_gpname\b"/etc/dconf/profile/*)\" exists"elsel_output2="$l_output2\n - dconf database profile isn't set"fi# Check if the dconf database file existsif[-f"/etc/dconf/db/$l_gpname"];thenl_output="$l_output\n - The dconf database \"$l_gpname\" exists"elsel_output2="$l_output2\n - The dconf database \"$l_gpname\" doesn't exist"fi# check if the dconf database directory existsif[-d"$l_gpdir"];thenl_output="$l_output\n - The dconf directory \"$l_gpdir\" exitst"elsel_output2="$l_output2\n - The dconf directory \"$l_gpdir\" doesn't exist"fi# check autorun-never settingifgrep-Pqrs--'^\h*autorun-never\h*=\h*true\b'"$l_kfile";thenl_output="$l_output\n - \"autorun-never\" is set to true in: \"$l_kfile\""elsel_output2="$l_output2\n - \"autorun-never\" is not set correctly"fielse# Settings don't exist. Nothing further to checkl_output2="$l_output2\n - \"autorun-never\" is not set"fielsel_output="$l_output\n - GNOME Desktop Manager package is not installed on the system\n - Recommendation is not applicable"fi# Report results. If no failures output in l_output2, we passif[-z"$l_output2"];thenecho-e"\n- Audit Result:\n ** PASS **\n$l_output\n"elseecho-e"\n- Audit Result:\n ** FAIL **\n - Reason(s) for audit failure:\n$l_output2\n"[-n"$l_output"]&&echo-e"\n- Correctly set:\n$l_output\n"fi}
#!/usr/bin/env bash{l_pkgoutput=""l_output=""l_output2=""l_gpname="local"# Set to desired dconf profile name (default is local)# Check if GNOME Desktop Manager is installed. If package isn't installed, recommendation is Not Applicable\n# determine system's package managerifcommand-vdpkg-query>/dev/null2>&1;thenl_pq="dpkg-query -W"elifcommand-vrpm>/dev/null2>&1;thenl_pq="rpm -q"fi# Check if GDM is installedl_pcl="gdm gdm3"# Space separated list of packages to checkforl_pnin$l_pcl;do$l_pq"$l_pn">/dev/null2>&1&&l_pkgoutput="$l_pkgoutput\n - Package: \"$l_pn\" exists on the system\n - checking configuration"doneecho-e"$l_pkgoutput"# Check configuration (If applicable)if[-n"$l_pkgoutput"];thenecho-e"$l_pkgoutput"# Look for existing settings and set variables if they existl_kfile="$(grep-Prils--'^\h*autorun-never\b'/etc/dconf/db/*.d)"# Set profile name based on dconf db directory ({PROFILE_NAME}.d)if[-f"$l_kfile"];thenl_gpname="$(awk-F\/'{split($(NF-1),a,".");print a[1]}'<<<"$l_kfile")"echo" - updating dconf profile name to \"$l_gpname\""fi[!-f"$l_kfile"]&&l_kfile="/etc/dconf/db/$l_gpname.d/00-mediaautorun"# Check if profile file existsifgrep-Pq--"^\h*system-db:$l_gpname\b"/etc/dconf/profile/*;thenecho-e"\n - dconf database profile exists in: \"$(grep-Pl--"^\h*system-db:$l_gpname\b"/etc/dconf/profile/*)\""else[!-f"/etc/dconf/profile/user"]&&l_gpfile="/etc/dconf/profile/user"||l_gpfile="/etc/dconf/profile/user2"echo-e" - creating dconf database profile"{echo-e"\nuser-db:user"echo"system-db:$l_gpname"}>>"$l_gpfile"fi# create dconf directory if it doesn't existsl_gpdir="/etc/dconf/db/$l_gpname.d"if[-d"$l_gpdir"];thenecho" - The dconf database directory \"$l_gpdir\" exists"elseecho" - creating dconf database directory \"$l_gpdir\""mkdir"$l_gpdir"fi# check autorun-never settingifgrep-Pqs--'^\h*autorun-never\h*=\h*true\b'"$l_kfile";thenecho" - \"autorun-never\" is set to true in: \"$l_kfile\""elseecho" - creating or updating \"autorun-never\" entry in \"$l_kfile\""ifgrep-Psq--'^\h*autorun-never'"$l_kfile";thensed-ri's/(^\s*autorun-never\s*=\s*)(\S+)(\s*.*)$/\1true \3/'"$l_kfile"else!grep-Psq--'\^\h*\[org\/gnome\/desktop\/media-handling\]\b'"$l_kfile"&&echo'[org/gnome/desktop/media-handling]'>>"$l_kfile"sed-ri'/^\s*\[org\/gnome\/desktop\/media-handling\]/a \\nautorun-never=true'"$l_kfile"fifielseecho-e"\n - GNOME Desktop Manager package is not installed on the system\n - Recommendation is not applicable"fi# update dconf databasedconfupdate
}