pm 1.9 KB

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