]> gitweb.morketsmerke.org Git - immudex-lhe.git/commitdiff
immudex_hostname - BT #87
authorxf0r3m <jakubstasinski@protonmail.com>
Sat, 22 Jul 2023 19:42:52 +0000 (21:42 +0200)
committerxf0r3m <jakubstasinski@protonmail.com>
Sat, 22 Jul 2023 19:42:52 +0000 (21:42 +0200)
tools/000/immudex_hostname

index a1ff456912627fbc66ad57dbafa16a4de081b852..d2dff9f136ca42ea8b17c38fc8c1c13de302f5fd 100755 (executable)
@@ -1,49 +1,12 @@
 #!/bin/bash
 
-vendor=$(hostnamectl | grep 'Vendor' | awk '{printf $3}')
-modelLine=$(hostnamectl | grep 'Model' | awk '{printf $3}')
-model=$(hostnamectl | grep 'Model' | awk '{printf $4}')
-
-if [ "$vendor" ] && [ "$modelLine" ] && [ "$model" ]; then
-
-  case $vendor in
-    "Lenovo") vendorShort="l";;
-    "Dell") vendorShort="d";;
-    "Acer") vendorShort="a";;
-    "ASUSTeK") vendorShort="as";;
-    "GOOGLE") vendorShort="go";;
-    "QEMU") vendorShort="kvm";;
-    *) hName="immudex";;
-  esac
-
-  case $modelLine in
-    "ThinkPad") mLShort="TP";;
-    "Latitude") mLShort="Lat";;
-    "AOD260") mLShort="ao";
-              model="D260";;
-    "Candy") vendorShort="d";
-              mLShort="chrbook";
-              model="3120";;
-    "Inspiron") mLShort="Ins";;
-    "Standard") if [ $vendorShort = "kvm" ]; then
-                  mLShort=$(hostnamectl | grep 'Machine ID' | awk '{print $3}' | cut -c 26-33);
-                  model="";
-                else
-                  mlShort="Std";
-                fi;;
-    *) hName="immudex";;
-  esac
+bootID=$(sed 's/-//g' /proc/sys/kernel/random/boot_id | cut -c 26-33);
+if hostnamectl > /dev/null 2>&1; then
+       hName="$(hostnamectl | grep 'Chassis' | cut -d ":" -f 2 | sed 's/\ //g')-${bootID}";
 else
-  if hostnamectl | grep -q 'kvm'; then
-    vendorShort="kvm";
-    mLShort=$(hostnamectl | grep 'Machine ID' | awk '{print $3}' | cut -c 26-33);
-    model="";
-  fi
-fi
-if [ ! "$hName" ]; then
-  hName="${vendorShort}-${mLShort}-$model"
-  sudo hostnamectl set-hostname $hName;
-  sudo sed -i "s/immudex/${hName}/" /etc/hosts;
-  echo $hName | sudo tee /etc/hostname > /dev/null;
+       hName="$(sudo dmidecode -s chassis-type | head -1 | tr [A-Z] [a-z])-${bootID}";
 fi
 
+sudo hostnamectl set-hostname $hName;
+sudo sed -i "s/immudex/${hName}" /etc/hosts;
+echo $hName | sudo tee /etc/hostname > /dev/null;