configure-suspend-encryption.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. #
  3. # configuration script for encrypted suspend
  4. #
  5. # (C) 2008 Stefan Seyfried <seife@suse.de> SUSE Linux Products GmbH
  6. # released under the GPL V2
  7. CONF=/etc/suspend.conf
  8. if [ $UID != 0 ]; then
  9. echo "Sorry, this configuration script needs root privileges."
  10. echo "Exiting now..."
  11. echo
  12. exit 1
  13. fi
  14. cat <<EOF
  15. We are going to create the key for encrypted suspend now. There are some
  16. questions we need to ask for:
  17. - Key size.
  18. The longer the key, the harder it will be to break the encryption.
  19. On the other hand, the longer the key, the more computational power is
  20. needed, which means that the suspend and resume will be slightly slower.
  21. Nowadays, 1024 bits of key length might be too insecure for some users,
  22. the default of 2048 bits should be fine.
  23. - Your passphrase. This passphrase protects the generated key. It should
  24. be sufficiently long and not easy to guess.
  25. This is the password you need to enter to resume from encrypted suspend.
  26. To make sure that you did not mistype the passphrase, you need to confirm
  27. it by entering it a second time.
  28. The program will create the key and copy it to /etc/suspend.key, then it
  29. will modify /etc/suspend.conf that from now on your suspend to disk image
  30. will be encrypted. Note that creating the key might take some time,
  31. depending on your machine. You can probably speed it up by using the mouse
  32. and generating I/O, e.g. by starting other programs.
  33. If you do not want to continue, press CTRL-C now.
  34. EOF
  35. # -q suppresses asking for the key file and makes it default
  36. # to /etc/suspend.key
  37. suspend-keygen -q
  38. if [ $? != 0 ]; then
  39. echo
  40. echo "Something went wrong. Please check above for error messages."
  41. echo "/etc/suspend.conf is not modified."
  42. echo
  43. exit 1
  44. fi
  45. echo "We successfully generated /etc/suspend.key. Modifying suspend.conf now."
  46. # backup...
  47. cp -a $CONF ${CONF}.backup
  48. # remove the encrypt and keyfile entries from the config file.
  49. # the key file will default to /etc/suspend.key anyway
  50. sed -i '/^encrypt /d;/^RSA key file /d;' $CONF
  51. echo "encrypt = y" >> $CONF
  52. # if we have more than one CPU / core, enabling threads will speed up
  53. # suspend.
  54. NUMCPU=$(grep -c ^processor /proc/cpuinfo)
  55. if [ $NUMCPU -gt 1 ]; then
  56. # remove the threads setting...
  57. sed -i '/^threads /d; ' $CONF
  58. # ..and add it back.
  59. echo "threads = y" >> $CONF
  60. fi
  61. echo
  62. echo "/etc/suspend.conf written, you can find the original file as /etc/suspend.conf.backup"
  63. echo