qubes-hcl-report 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/bin/bash
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2013 Laszlo Zrubecz <mail@zrubi.hu>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. VERSION=2.5
  20. COPY2VM="dom0"
  21. SUPPORT_FILES=0
  22. while [ $# -gt 0 ]; do
  23. case "$1" in
  24. -s |--support)
  25. SUPPORT_FILES=1
  26. ;;
  27. -* | -h | --help)
  28. echo -e "qubes-hcl-report v$VERSION"
  29. echo ""
  30. echo "This tool is used to gather basic hardware information for the Qubes HCL (Hardware Compatibility List)"
  31. echo "and copy the results to the given AppVM for the easy contribution."
  32. echo ""
  33. echo -e "Usage:\tqubes-hcl-report [OPTIONS] [<AppVM Name>]"
  34. echo -e "Options are:"
  35. echo -e "\t-h, --help\tDisplay this help text and exit."
  36. echo -e "\t-s, --support\tGenerate more detailed HCL Support Files"
  37. echo -e "\t\t\tWARNING: The HCL Support Files may contain numerous hardware details, including serial numbers."
  38. echo -e "\t\t\tIf, for privacy or security reasons, you do not wish to make this information public, "
  39. echo -e "\t\t\tplease do not send the .cpio.gz file to the public mailing list."
  40. echo ""
  41. echo -e "\t<AppVM Name>\tCopy the results to the given AppVM. The default is to keep it in dom0"
  42. echo ""
  43. exit
  44. ;;
  45. *)
  46. /usr/bin/qvm-check -q $1
  47. if [[ $? -eq 0 ]]
  48. then
  49. COPY2VM="$1"
  50. else
  51. echo -e "ERROR:\tAppVM with the name '$1' does not exist in the system!"
  52. exit 1
  53. fi
  54. ;;
  55. esac
  56. shift
  57. done
  58. DATE=`date +%Y%m%d-%H%M%S`
  59. TEMP_DIR=`mktemp --tmpdir -d HCL.XXXXXXXXXX`
  60. cat /etc/qubes-release > $TEMP_DIR/qubes-release
  61. cat /proc/cpuinfo > $TEMP_DIR/cpuinfo
  62. lspci -nnvk > $TEMP_DIR/lspci
  63. cat /proc/scsi/scsi > $TEMP_DIR/scsi
  64. sudo dmidecode > $TEMP_DIR/dmidecode
  65. xl info > $TEMP_DIR/xl-info
  66. xl dmesg > $TEMP_DIR/xl-dmesg
  67. BRAND=`cat $TEMP_DIR/dmidecode |grep -A9 "System Information" |grep "Manufacturer:" |cut -d ' ' -f2-`
  68. PRODUCT=`cat $TEMP_DIR/dmidecode |grep -A9 "System Information" |grep "Product Name:" |cut -d ' ' -f3-`
  69. TYPE=`cat $TEMP_DIR/dmidecode |grep -A9 "Chassis Information" |grep Type |cut -d ' ' -f2- |tr '[:upper:]' '[:lower:]'`
  70. if [[ $BRAND =~ "O.E.M" ]]
  71. then
  72. BRAND=`cat $TEMP_DIR/dmidecode |grep -A9 "Base Board Information" |grep "Manufacturer:" |cut -d ' ' -f2-`
  73. PRODUCT=`cat $TEMP_DIR/dmidecode |grep -A9 "Base Board Information" |grep "Product Name:" |cut -d ' ' -f3-`
  74. fi
  75. KERNEL=`uname -r |cut -d '.' -f-3`
  76. CPU=`cat $TEMP_DIR/cpuinfo |grep "model name" |sort -u |cut -d ' ' -f3- |sed -e "s/[[:space:]]*/\ /"`
  77. CHIPSET=`cat $TEMP_DIR/lspci |grep "00:00.0.*Host bridge" |cut -d ':' -f3- |sed -e "s/[[:space:]]*/\ /"`
  78. VGA=`cat $TEMP_DIR/lspci |grep "VGA\|Display" |cut -d ':' -f3- |sed -e "s/^[[:space:]]*/\ /"`
  79. NET=`cat $TEMP_DIR/lspci |lspci |grep "Network\|Ethernet" |cut -d ':' -f3- |sed -e "s/^[[:space:]]*/\ /"`
  80. SCSI=`cat $TEMP_DIR/scsi |grep Model |cut -d ':' -f3-|sed -e "s/^[[:space:]]*/\ /"`
  81. RAM=`cat $TEMP_DIR/xl-info |grep total_memory |cut -d ':' -f2 |tr -d ' '`
  82. BIOS=`cat $TEMP_DIR/dmidecode |grep -A9 "BIOS Information" |grep "Version" |cut -d ' ' -f2-`
  83. XEN_MAJOR=`cat $TEMP_DIR/xl-info |grep xen_major |cut -d: -f2 |tr -d ' '`
  84. XEN_MINOR=`cat $TEMP_DIR/xl-info |grep xen_minor |cut -d: -f2 |tr -d ' '`
  85. XEN_EXTRA=`cat $TEMP_DIR/xl-info |grep xen_extra |cut -d: -f2 |tr -d ' '`
  86. QUBES=`cat $TEMP_DIR/qubes-release |cut -d '(' -f2 |cut -d ')' -f1`
  87. XL_VTX=`cat $TEMP_DIR/xl-info |grep xen_caps | grep hvm`
  88. XL_VTD=`cat $TEMP_DIR/xl-info |grep virt_caps |grep hvm_directio`
  89. PCRS=`find /sys/devices/ -name pcrs`
  90. FILENAME="Qubes-HCL-${BRAND//[^[:alnum:]]/_}-${PRODUCT//[^[:alnum:]]/_}-$DATE"
  91. if [[ $XL_VTX ]]
  92. then
  93. VTX="Active"
  94. HVM="yes"
  95. else
  96. VTX="Not active"
  97. HVM="no"
  98. fi
  99. if [[ $XL_VTD ]]
  100. then
  101. VTD="Active"
  102. IOMMU="yes"
  103. else
  104. VTD="Not active"
  105. IOMMU="no"
  106. fi
  107. if [[ $PCRS ]]
  108. then
  109. # try tu run tcsd and: grep the logs, try get version info.
  110. TPM="Device present"
  111. else
  112. TPM="Device not found"
  113. TPM_s="unknown"
  114. fi
  115. cat /etc/qubes-release
  116. echo
  117. echo -e "Brand:\t\t$BRAND"
  118. echo -e "Model:\t\t$PRODUCT"
  119. echo -e "BIOS:\t\t$BIOS\n"
  120. echo -e "Xen:\t\t$XEN_MAJOR.$XEN_MINOR$XEN_EXTRA"
  121. echo -e "Kernel:\t\t$KERNEL\n"
  122. echo -e "RAM:\t\t$RAM Mb\n"
  123. echo -e "CPU:\n$CPU"
  124. echo -e "Chipset:\n$CHIPSET"
  125. echo -e "VGA:\n${VGA}\n"
  126. echo -e "Net:\n$NET\n"
  127. echo -e "SCSI:\n$SCSI\n"
  128. echo -e "HVM:\t\t$VTX"
  129. echo -e "I/O MMU:\t$VTD"
  130. echo -e "TPM:\t\t$TPM"
  131. echo
  132. echo -e "---
  133. layout:
  134. 'hcl'
  135. type:
  136. '$TYPE'
  137. hvm:
  138. '$HVM'
  139. iommu:
  140. '$IOMMU'
  141. tpm:
  142. '$TPM_s'
  143. brand: |
  144. $BRAND
  145. model: |
  146. $PRODUCT
  147. bios: |
  148. $BIOS
  149. cpu: |
  150. $CPU
  151. cpu-short: |
  152. FIXME
  153. chipset: |
  154. $CHIPSET
  155. chipset-short: |
  156. FIXME
  157. gpu: |
  158. $VGA
  159. gpu-short: |
  160. FIXME
  161. network: |
  162. $NET
  163. memory: |
  164. $RAM
  165. scsi: |
  166. $SCSI
  167. versions:
  168. - works:
  169. 'FIXME:yes|no|partial'
  170. qubes: |
  171. $QUBES
  172. xen: |
  173. $XEN_MAJOR.$XEN_MINOR$XEN_EXTRA
  174. kernel: |
  175. $KERNEL
  176. remark: |
  177. FIXME
  178. credit: |
  179. FIXAUTHOR
  180. link: |
  181. FIXLINK
  182. ---
  183. " >> "$HOME/$FILENAME.yml"
  184. if [[ "$SUPPORT_FILES" == 1 ]]
  185. then
  186. # cpio
  187. cd $TEMP_DIR
  188. find -print0 | cpio --quiet -o -H crc --null | gzip > "$HOME/$FILENAME.cpio.gz"
  189. cd
  190. fi
  191. # Destination VM check
  192. if [[ "$COPY2VM" != "dom0" ]]
  193. then
  194. # Copy to VM
  195. qvm-start -q $COPY2VM 2> /dev/null
  196. if [[ -f "$HOME/$FILENAME.cpio.gz" ]]
  197. then
  198. cat "$HOME/$FILENAME.cpio.gz" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.cpio.gz\""
  199. fi
  200. if [[ -f "$HOME/$FILENAME.yml" ]]
  201. then
  202. cat "$HOME/$FILENAME.yml" | qvm-run -a -q --pass-io $COPY2VM "cat > \"/home/user/$FILENAME.yml\""
  203. fi
  204. fi
  205. echo -e "Qubes HCL Files are copied to: '$COPY2VM'"
  206. echo -e "\t$FILENAME.yml\t\t- HCL Info"
  207. if [[ "$SUPPORT_FILES" == 1 ]]
  208. then
  209. echo -e "\t$FILENAME.cpio.gz\t- HCL Support Files"
  210. fi
  211. echo
  212. # cleanup
  213. if [[ -d $TEMP_DIR ]]
  214. then
  215. rm -rf $TEMP_DIR
  216. fi