Guest User

Untitled

a guest
Sep 11th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # This script is run as root by GDM after user's login.
  4. # It must return exit code 0, otherwise it totally breaks the logon process.
  5.  
  6. # Input
  7. # =====
  8. #
  9. # * /etc/live/config.d/username.conf : amnesia
  10. # * /var/lib/gdm3/tails.locale : $TAILS_LOCALE_NAME, $TAILS_XKBMODEL,
  11. # * /var/lib/gdm3/tails.password : $TAILS_USER_PASSWORD
  12. # * /var/lib/gdm3/tails.physical_security : $TAILS_MACSPOOF_ENABLED
  13.  
  14. # For whatever reason, /usr/sbin (needed by at least chpasswd)
  15. # is not in our PATH
  16. export PATH="/usr/sbin:${PATH}"
  17.  
  18. LIVE_USERNAME=amnesia
  19. LIVE_PASSWORD=live
  20.  
  21. TAILS_USER_PASSWORD=
  22.  
  23. TAILS_LOCALE_NAME=pt_BR
  24. TAILS_FORMATS=pt_BR
  25. TAILS_XKBMODEL=pc105
  26. TAILS_XKBLAYOUT=br
  27. TAILS_XKBVARIANT=
  28.  
  29. TAILS_NETCONF=direct
  30. TAILS_MACSPOOF_ENABLED=true
  31.  
  32. POLKIT=/etc/polkit-1/localauthority.conf.d/52-tails-greeter.conf
  33. #[Configuration]
  34. #AdminIdentities=unix-user:amnesia
  35.  
  36.  
  37. SUDOERS=/etc/sudoers.d/tails-greeter
  38. #amnesia ALL = (ALL) ALL
  39.  
  40. NO_PASSWORD_LECTURE=/etc/sudoers.d/tails-greeter-no-password-lecture
  41. KBDSET=/etc/default/keyboard
  42. #XKBMODEL=pc105
  43. #XKBLAYOUT=br
  44. #BACKSPACE=guess
  45.  
  46. CONSET=/etc/default/console-setup
  47. #ACTIVE_CONSOLES="/dev/tty[1-6]"
  48. #CHARMAP="UTF-8"
  49. #CODESET="Uni1"
  50. #FONTFACE="Fixed"
  51. #FONTSIZE="8x16"
  52. #VIDEOMODE=
  53.  
  54. LOCALE_CFG=/etc/default/locale
  55. #LANG=pt_BR.UTF-8
  56.  
  57. CODSET="Uni1" # universal codeset to properly display glyphs in localized console
  58.  
  59. log() {
  60. echo "$1" >&2
  61. }
  62.  
  63. log_n_exit() {
  64. log "$1"
  65. log "Leaving PostLogin"
  66. exit 0
  67. }
  68.  
  69. # enforce value $3 for variable $1 in file $2
  70. force_set() {
  71. sed -i -e "s|^$1=.*$|$1=\"$3\"|" "$2"
  72. }
  73.  
  74. # check if variable $1 is in file $2, if not - add with value $3 to file $2
  75. # $4 enforce adding $3 only (without $1= prefix)
  76. grep_n_set() {
  77. FCHK=yes
  78. grep -qs "$1" "$2" || FCHK=no
  79. if [ -n "$4" ] ; then
  80. if [ "$FCHK" = "no" ] ; then
  81. echo "$3" >> "$2"
  82. fi
  83. else
  84. if [ "$FCHK" = "no" ] ; then
  85. echo "$1=$3" >> "$2"
  86. else
  87. force_set "$1" "$2" "$3"
  88. fi
  89. fi
  90. }
  91.  
  92. ### Let's go
  93.  
  94. log "Entering PostLogin"
  95.  
  96. ### Gather general configuration
  97.  
  98. # Import the name of the live user
  99. . /etc/live/config.d/username.conf || log_n_exit "Username file not found."
  100. if [ -z "${LIVE_USERNAME}" ] ; then
  101. log_n_exit "Username variable not found."
  102. fi
  103.  
  104. ### Physical security
  105. log "Running /usr/local/lib/tails-unblock-network..."
  106. /usr/local/lib/tails-unblock-network &
  107.  
  108. ### Localization
  109.  
  110. # Import locale name
  111. . /var/lib/gdm3/tails.locale || log_n_exit "Locale file not found."
  112. if [ -z "${TAILS_LOCALE_NAME}" ] ; then
  113. log_n_exit "Locale variable not found."
  114. fi
  115.  
  116. # Set the keyboard mapping for X11 and the console
  117. localectl set-x11-keymap "$TAILS_XKBLAYOUT" "$TAILS_XKBMODEL" "$TAILS_XKBVARIANT" "$TAILS_XKBOPTIONS"
  118.  
  119. # Set the system locale and formats
  120. localectl set-locale \
  121. "LANG=${TAILS_LOCALE_NAME}.UTF-8" \
  122. "LC_TIME=${TAILS_FORMATS}.UTF-8" \
  123. "LC_NUMERIC=${TAILS_FORMATS}.UTF-8" \
  124. "LC_MONETARY=${TAILS_FORMATS}.UTF-8" \
  125. "LC_MEASUREMENT=${TAILS_FORMATS}.UTF-8" \
  126. "LC_PAPER=${TAILS_FORMATS}.UTF-8" \
  127.  
  128. # Save keyboard settings so that tails-configure-keyboard can set it
  129. # in the GNOME session.
  130. cat > /var/lib/tails-user-session/keyboard <<EOF
  131. XKBMODEL="$TAILS_XKBMODEL"
  132. XKBLAYOUT="$TAILS_XKBLAYOUT"
  133. XKBVARIANT="$TAILS_XKBVARIANT"
  134. XKBOPTIONS="$TAILS_XKBOPTIONS"
  135. EOF
  136.  
  137. ### Password
  138.  
  139. # Import password for superuser access
  140. if [ -e /var/lib/gdm3/tails.password ] ; then
  141. . /var/lib/gdm3/tails.password
  142. fi
  143.  
  144. # Remove password file
  145. rm --interactive=never -f /var/lib/gdm3/tails.password
  146.  
  147. # Check if password is actually set
  148. if [ -z "${TAILS_USER_PASSWORD}" ] ; then
  149. rm -f "${POLKIT}" "${SUDOERS}"
  150. deluser "${LIVE_USERNAME}" sudo
  151. passwd -d "${LIVE_USERNAME}"
  152. install -o root -g root -m 0440 /dev/null "${NO_PASSWORD_LECTURE}"
  153. echo "Defaults:amnesia lecture=always" > "${NO_PASSWORD_LECTURE}"
  154. echo "Defaults:amnesia lecture_file=/usr/share/tails-greeter/no-password-lecture.txt" >> "${NO_PASSWORD_LECTURE}"
  155. echo "Defaults:amnesia badpass_message=\"The administration password is disabled.\"" >> "${NO_PASSWORD_LECTURE}"
  156. log_n_exit "Password variable not found."
  157. fi
  158.  
  159. # Sets the password
  160. echo "${LIVE_USERNAME}:${TAILS_USER_PASSWORD}" | chpasswd
  161.  
  162. # Add sudoers entry
  163. echo "${LIVE_USERNAME} ALL = (ALL) ALL" >> "${SUDOERS}"
  164. chmod 0440 "${SUDOERS}"
  165.  
  166. # Add PolKit config
  167. echo "[Configuration]" > "${POLKIT}"
  168. echo "AdminIdentities=unix-user:${LIVE_USERNAME}" >> "${POLKIT}"
  169.  
  170. # Configure su-to-root to use sudo
  171. sudo -u "${LIVE_USERNAME}" sh -c "echo 'SU_TO_ROOT_SU=sudo' >> /home/${LIVE_USERNAME}/.su-to-rootrc"
  172.  
  173. log "Leaving PostLogin"
Add Comment
Please, Sign In to add comment