Advertisement
alexeyshmalko

Untitled

Feb 4th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. echo "This script sets up read permissions for the kernel's event devices
  2. in order for your user to be able to run WhatPulse. It will create a new
  3. group called 'input', add your username to that group, and make the event
  4. devices readable for the group. Press Ctrl+C now if you don't want this,
  5. or press Return to continue."
  6.  
  7. read temp
  8.  
  9. if [ "`whoami`" != "root" ] ; then
  10.     echo "This script must be run as root (e.g. using sudo). Will now exit."
  11.     exit
  12. fi
  13.  
  14. # set up persistent settings
  15.  
  16. if [ -r /etc/udev/rules.d/99-whatpulse-input.rules ] ; then
  17.     echo "/etc/udev/rules.d/99-whatpulse-input.rules already exists. Will not change it."
  18. else
  19.     echo "KERNEL==\"event*\",       NAME=\"input/%k\", MODE=\"640\", GROUP=\"input\"" >> /etc/udev/rules.d/99-whatpulse-input.rules
  20.     if [ $? != 0 ] ; then
  21.         echo "There was some error creating the udev rule file. Sorry. Quitting."
  22.         exit
  23.     fi
  24.     echo "UDEV rules file has been set up."
  25. fi
  26.  
  27. if [ -n "`cat /etc/group | grep -e ^input:`" ] ; then
  28.     echo "Group 'input' already exists!"
  29. else
  30.     groupadd input
  31.     echo "Created group 'input'."
  32. fi
  33.  
  34. echo "Please enter the username that should get added to the group:"
  35. read username
  36.  
  37. if [ -z "$username" ] ; then
  38.     echo "What do you mean by an empty username? Quitting."
  39.     exit
  40. fi
  41.  
  42. if [ -z "`cat /etc/passwd | grep -e ^$username:`" ] ; then
  43.     echo "This username doesn't exist. Quitting."
  44.     exit
  45. fi
  46.  
  47. gpasswd -a $username input &> /dev/null
  48. if [ $? != 0 ] ; then
  49.     # maybe this is openSUSE (or a similar system)
  50.     usermod -A input $username &> /dev/null
  51.     if [ $? != 0 ] ; then
  52.         echo "There was a problem adding your username to the group 'input'.
  53. Please add your user to the 'input' group yourself."
  54.     else
  55.         echo "Added user '$username' to group 'input', using the special openSUSE method."
  56.     fi
  57. else
  58.     echo "Added user '$username' to group 'input'."
  59. fi
  60. echo " "
  61. echo "Setup of persistent permission settings complete."
  62.  
  63. # apply non-persistent settings so that no reboot is necessary :-)
  64.  
  65. echo " "
  66. echo "Since the UDEV rules will only be applied when you restart your
  67. computer, this script will now apply temporary read permissions for all
  68. users to the device files to let you use WhatPulse immediately. You have
  69. the chance to cancel this by pressing Ctrl+C now (which you should do if
  70. you fear that other users on your computer might log your keyboard
  71. events!). Otherwise press Return to continue."
  72.  
  73. read temp
  74.  
  75. find /dev/input/ -iname 'event*' -exec chmod 644 {} \;
  76.  
  77. echo "All done, have fun using WhatPulse!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement