qubes-hcl-report 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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.3
  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-`
  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// /_}-${PRODUCT// /_}-$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. ---
  134. layout: 'hcl'
  135. brand: '$BRAND'
  136. model: '$PRODUCT'
  137. type: '$TYPE'
  138. bios: '$BIOS'
  139. ram: '$RAM'
  140. hvm: '$HVM'
  141. iommu: '$IOMMU'
  142. tpm: '$TPM_s'
  143. cpu-short: 'FIXME'
  144. cpu: |
  145. $CPU
  146. chipset-sort: 'FIXME'
  147. chipset: |
  148. $CHIPSET
  149. gpu-short: 'FIXME'
  150. gpu: |
  151. $VGA
  152. network: |
  153. $NET
  154. scsi: |
  155. $SCSI
  156. versions:
  157. - qubes: '$QUBES'
  158. xen: '$XEN_MAJOR.$XEN_MINOR$XEN_EXTRA'
  159. kernel: '$KERNEL'
  160. works: 'FIXME'
  161. remark: |
  162. FIXME
  163. credit: |
  164. FIXME
  165. ---
  166. # vim: ts=2 sw=2 et nowrap
  167. " >> $HOME/$FILENAME.yml
  168. if [[ "$SUPPORT_FILES" == 1 ]]
  169. then
  170. # cpio
  171. cd $TEMP_DIR
  172. find -print0 |cpio --quiet -o -H crc --null |gzip >$HOME/$FILENAME.cpio.gz
  173. cd
  174. fi
  175. # Destination VM check
  176. if [[ "$COPY2VM" != "dom0" ]]
  177. then
  178. # Copy to VM
  179. qvm-start -q $COPY2VM 2>/dev/null
  180. if [[ -f "$HOME/$FILENAME.cpio.gz" ]]
  181. then
  182. cat $HOME/$FILENAME.cpio.gz | qvm-run -a -q --pass-io $COPY2VM "cat >/home/user/$FILENAME.cpio.gz"
  183. fi
  184. if [[ -f "$HOME/$FILENAME.yml" ]]
  185. then
  186. cat $HOME/$FILENAME.yml | qvm-run -a -q --pass-io $COPY2VM "cat >/home/user/$FILENAME.yml"
  187. fi
  188. fi
  189. echo -e "Qubes HCL Files are copied to: '$COPY2VM'"
  190. echo -e "\t$FILENAME.yml\t\t- HCL Info"
  191. if [[ "$SUPPORT_FILES" == 1 ]]
  192. then
  193. echo -e "\t$FILENAME.cpio.gz\t- HCL Support Files"
  194. fi
  195. echo
  196. # cleanup
  197. if [[ -d $TEMP_DIR ]]
  198. then
  199. rm -rf $TEMP_DIR
  200. fi