root2user 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/sh
  2. #Barry Kauler, April 2011, GPL3 (/usr/share/doc/legal)
  3. #intended to be called by rc.shutdown on 1st boot, create a non-root saved session.
  4. #note, /usr/sbin/loginmanager is able to revert fido back to root.
  5. #110918 run with or without X.
  6. #111003 change from Xdialog to pupdialog.
  7. #120317 L18L: set group/permissions for /dev/console
  8. #120409 if using minit instead of busybox init.
  9. #130528 change /root/.Diricon. No, revert.
  10. . /etc/rc.d/PUPSTATE
  11. #ask for a username? i don't think that is required.
  12. NEWUSER='fido'
  13. if [ $DISPLAY ];then
  14. export XDIALOG_HIGH_DIALOG_COMPAT=true #for Xdialog.
  15. DIALOGEXE="pupdialog"
  16. DIALOGEXE2="Xdialog"
  17. BACKGROUNDYELLOW='--background \#FFFF80' #110924 change to pale-yellow. yellow' #only works pupdialog.
  18. BACKGROUNDPINK='--background pink' #ditto.
  19. BACKGROUNDORANGE='--background \#FFDC32' #110924 change to pale-orange. orange' #ditto.
  20. TITLEPARAM='--backtitle'
  21. else
  22. DIALOGEXE="dialog"
  23. DIALOGEXE2="dialog"
  24. TITLEPARAM='--title'
  25. BACKGROUNDYELLOW=''
  26. BACKGROUNDPINK=''
  27. BACKGROUNDORANGE=''
  28. fi
  29. # -h means affect symlinks instead of target, -R means recursive...
  30. busybox chown -h -R ${NEWUSER}:users /root
  31. busybox chmod g+s /root
  32. busybox chown -h -R spot:spot /root/spot
  33. case $PUPMODE in
  34. 2)
  35. echo
  36. ;;
  37. *)
  38. echo
  39. ;;
  40. esac
  41. #modify /etc/inittab to autologin as fido...
  42. userEXPR='s%autologin root %autologin fido %'
  43. sed -i -e "$userEXPR" /etc/inittab
  44. #120409 if using minit instead of busybox init...
  45. if [ -f /etc/minit/getty/1/params ];then #see my minit pet pkg.
  46. EXPR2='s%^root$%fido%'
  47. sed -i -e "$EXPR2" /etc/minit/getty/1/params
  48. fi
  49. #stuff from pizzasgood, http://www.murga-linux.com/puppy/viewtopic.php?t=47410
  50. #i don't know why setting these /dev permissions reverts to that in rootfs-skeleton
  51. #on next boot, so have changed them in rootfs-skeleton also...
  52. # ...oh, i think snapmergepuppy (when boot from usb) does not save /dev.
  53. busybox chmod 770 /dev/zero
  54. busybox chmod 770 /dev/ptmx
  55. #set the setuid bit...
  56. busybox chmod u+s `which ddcprobe`
  57. [ "`which Xvesa`" ] && busybox chmod u+s `which Xvesa`
  58. [ "`which Xorg`" ] && busybox chmod u+s `which Xorg`
  59. #120317 L18L: ref http://murga-linux.com/puppy/viewtopic.php?t=71358&start=60
  60. chgrp users /dev/console
  61. chmod g+w /dev/console
  62. #busybox has to be configured with CONFIG_FEATURE_SUID_CONFIG (ex: busybox-1.17.2-1-w5.pet)
  63. busybox chmod u+s `which busybox`
  64. #see docs on busybox.conf at: http://www.softforge.de/bb/suid.html
  65. #also: http://www.slitaz.org/en/doc/scratchbook/base-system.html
  66. echo '[SUID]
  67. reboot = ssx root.0 # reboot can be run by anyone and runs with euid=0/egid=0
  68. poweroff = ssx root.0
  69. halt = ssx root.0
  70. su = ssx root.root
  71. # passwd = ssx root.root
  72. loadkmap = ssx root.root
  73. mount = ssx root.root
  74. umount = ssx root.root
  75. ps = ssx root.0
  76. kill = ssx root.0
  77. ' > /etc/busybox.conf
  78. #i made /dev/pts 777 (was 707) in rootfs-skeleton in Woof.
  79. #optional, change root password, and require password to 'su root'...
  80. ROOTPASSWORD="`${DIALOGEXE} ${BACKGROUNDYELLOW} ${TITLEPARAM} "First shutdown: ask admin password" --stdout --nocancel --inputbox "Please enter a password for the administrator (root), minimum six characters.\n\nLogin as fido does not require a password, so at bootup you will go directly to the desktop. This is also the case if you had chosen to run as administrator. However, having chosen the restricted fido user, you will be required to enter a password whenever you want to perform an operation that requires admin priviledges.\n\nPLEASE REMEMBER THIS PASSWORD" 0 0 ""`"
  81. echo "root:${ROOTPASSWORD}" | busybox chpasswd #--md5
  82. #sudo asks for user password, not root, simple solution give same password to both...
  83. #(that is the default, but i have specified runaspw in /etc/sudoers to ask for root pw)
  84. echo "fido:${ROOTPASSWORD}" | busybox chpasswd #--md5
  85. #note, /usr/sbin/loginmanager enables to change back to root afterward.
  86. ###END###