grub-deluser.in 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh -e
  2. #
  3. # BURG - Brand-new Universal loadeR from GRUB
  4. # Copyright 2010 Bean Lee - All Rights Reserved
  5. #
  6. # BURG is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # BURG 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 BURG. If not, see <http://www.gnu.org/licenses/>.
  18. # Initialize some variables.
  19. transform="@program_transform_name@"
  20. prefix=@prefix@
  21. sysconfdir=@sysconfdir@
  22. pass_file=${sysconfdir}/default/burg-passwd
  23. # Usage: usage
  24. # Print the usage.
  25. usage () {
  26. cat <<EOF
  27. Usage: $0 [OPTION] username
  28. Delete a burg user
  29. -h, --help print this message and exit
  30. -v, --version print the version information and exit
  31. Report bugs to <bean123ch@gmail.com>.
  32. EOF
  33. }
  34. # Check the arguments.
  35. for option in "$@"; do
  36. case "$option" in
  37. -h | --help)
  38. usage
  39. exit 0 ;;
  40. -v | --version)
  41. echo "$0 (${PACKAGE_NAME} ${package_version})"
  42. exit 0 ;;
  43. -*)
  44. echo "Unrecognized option \`$option'" 1>&2
  45. usage
  46. exit 1
  47. ;;
  48. esac
  49. done
  50. if [ "x$1" = "x" ] ; then
  51. echo "$0: No username is specified" >&2
  52. exit 1
  53. fi
  54. username=`echo $1 | sed 's,[^a-zA-Z0-9],,'`
  55. if [ "x$1" != "x$username" ] ; then
  56. echo "$0: Only digits and letters are allowed in username" >&2
  57. exit 1
  58. fi
  59. if [ "x$EUID" = "x" ] ; then
  60. EUID=`id -u`
  61. fi
  62. if [ "$EUID" != 0 ] ; then
  63. root=f
  64. case "`uname 2>/dev/null`" in
  65. CYGWIN*)
  66. # Cygwin: Assume root if member of admin group
  67. for g in `id -G 2>/dev/null` ; do
  68. case $g in
  69. 0|544) root=t ;;
  70. esac
  71. done ;;
  72. esac
  73. if [ $root != t ] ; then
  74. echo "$0: You must run this as root" >&2
  75. exit 1
  76. fi
  77. fi
  78. touch $pass_file
  79. chmod 600 $pass_file
  80. temp_file=${pass_file}.tmp
  81. touch $temp_file
  82. chmod 600 $temp_file
  83. grep -v "^$username:" $pass_file > $temp_file || { rm $temp_file; exit 1; }
  84. mv $temp_file $pass_file
  85. exit 0