pm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. #
  3. # A password manager for quickpass. Merged from alimiracle
  4. #
  5. # Copyright (c) 2016 ali abdul ghani <alimiracle@riseup.net>
  6. # Copyright (c) 2016 kzimmermann <kzimmermann@vivaldi.net>
  7. #
  8. # This file is part of quickpass, a Password Generator and Manager
  9. # quickpass is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, either version 3 of the License, or
  12. # (at your option) any later version.
  13. # quickpass is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with quickpass. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # I dislike the idea of running this as root. No need to include a potential
  21. # security hole in a relatively simple script.
  22. #if [[ $UID -ne 0 ]]; then
  23. # echo "This script must be run as root"
  24. # exit 1
  25. #fi
  26. user_name="$USER" # env variables are built-in and better to use.
  27. encrypt() {
  28. if test $# = 0
  29. then
  30. echo E:Missing Website name
  31. exit
  32. fi
  33. if test $# = 1
  34. then
  35. echo E:Missing password
  36. exit
  37. fi
  38. if test $# = 2
  39. then
  40. echo E:Missing gpg key
  41. exit
  42. fi
  43. echo $2 | gpg --encrypt --armor -r $3 > /$user_name/.pm/$1
  44. }
  45. decrypt() {
  46. file=`ls /$user_name/.pm`
  47. if echo "$file" | grep -q $1; then
  48. cat /$user_name/.pm/$1 | gpg --decrypt -r $2
  49. else
  50. echo I cant find the web site name
  51. exit
  52. fi
  53. if test $# = 1
  54. then
  55. echo E:Missing gpg key
  56. exit
  57. fi
  58. }
  59. remove() {
  60. file=`ls /$user_name/.pm`
  61. if echo "$file" | grep -q $1; then
  62. rm /$user_name/.pm/$1
  63. else
  64. echo I cant find the web site name
  65. exit
  66. fi
  67. }
  68. tistdir=`ls -a /$user_name`
  69. if echo "$tistdir" | grep -q ".pm"; then
  70. echo
  71. else
  72. mkdir /$user_name/.pm
  73. fi
  74. if test $# = 0
  75. then
  76. echo E:Missing Website name
  77. exit
  78. elif test "$1" = "--new"
  79. then
  80. encrypt $2 $3 $4
  81. exit
  82. elif test "$1" = "--list"
  83. then
  84. ls /$user_name/.pm
  85. exit
  86. elif test "$1" = "--remove"
  87. then
  88. remove $2
  89. exit
  90. fi
  91. decrypt $1 $2