VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/installer/module-autologon.sh@ 70836

Last change on this file since 70836 was 69500, checked in by vboxsync, 7 years ago

*: scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
1# Oracle VM VirtualBox
2# $Id: module-autologon.sh 69500 2017-10-28 15:14:05Z vboxsync $
3## @file
4# VirtualBox Linux Guest Additions installer - autologon module
5#
6
7#
8# Copyright (C) 2012-2017 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19# @todo Document functions and their usage!
20
21MOD_AUTOLOGON_DEFAULT_LIGHTDM_CONFIG="/etc/lightdm/lightdm.conf"
22MOD_AUTOLOGON_DEFAULT_LIGHTDM_GREETER_DIR="/usr/share/xgreeters"
23
24mod_autologon_init()
25{
26 echo "Initializing auto-logon support ..."
27 return 0
28}
29
30mod_autologon_install_ex()
31{
32 info "Installing auto-logon support ..."
33
34 ## Parameters:
35 # Greeter directory. Defaults to /usr/share/xgreeters.
36 greeter_dir="$1"
37 # LightDM config. Defaults to /etc/lightdm/lightdm.conf.
38 lightdm_config="$2"
39 # Whether to force installation if non-compatible distribution
40 # is detected.
41 force="$3"
42
43 # Check for Ubuntu and derivates. @todo Debian?
44 distros="Ubuntu UbuntuStudio Edubuntu Kubuntu Lubuntu Mythbuntu Xubuntu"
45 ## @todo Map Linux Mint versions to Ubuntu ones.
46
47 ## @todo Move the distro check to a routine / globals as soon as
48 ## we have other distribution-dependent stuff.
49 which lsb_release &>/dev/null
50 if test "$?" -ne "0"; then
51 info "Error: lsb_release not found (path set?), skipping auto-logon installation"
52 return 1
53 fi
54 distro_name=$(lsb_release -si)
55 distro_ver=$(lsb_release -sr)
56
57 for distro_cur in ${distros}; do
58 if test "$distro_name" = "$distro_cur"; then
59 distro_found="true"
60 break
61 fi
62 done
63
64 if test -z "$distro_found"; then
65 if ! test "$force" = "force"; then
66 info "Error: Unsupported distribution \"$distro_name\" found, skipping auto-logon installation"
67 return 1
68 fi
69 info "Warning: Unsupported distribution \"$distro_name\" found"
70 else
71 # Do we have Ubuntu 11.10 or greater?
72 # Use AWK for comparison since we run on plan sh.
73 echo | awk 'END { exit ( !('"$distro_ver >= 11.10"') ); }'
74 if test "$?" -ne "0"; then
75 if ! test "$force" = "force"; then
76 info "Error: Version $distro_ver of \"$distro_name\" not supported, skipping auto-logon installation"
77 return 1
78 fi
79 info "Warning: Unsupported \"$distro_name\" version $distro_ver found"
80 fi
81 fi
82
83 # Install dependencies (lightdm and FLTK 1.3+) using apt-get.
84 which apt-get &>/dev/null
85 if test "$?" -ne "0"; then
86 info "Error: apt-get not found (path set?), skipping auto-logon installation"
87 return 1
88 fi
89 info "Checking and installing necessary dependencies ..."
90 apt-get -qqq -y install libfltk1.3 libfltk-images1.3 || return 1
91 apt-get -qqq -y install lightdm || return 1
92
93 # Check for LightDM config.
94 if ! test -f "$lightdm_config"; then
95 info "Error: LightDM config \"$lightdm_config\" not found (LightDM installed?), skipping auto-logon installation"
96 return 1
97 fi
98
99 # Check for /usr/share/xgreeters.
100 if ! test -d "$greeter_dir"; then
101 if ! test "$force" = "force"; then
102 info "Error: Directory \"$greeter_dir\" does not exist, skipping auto-logon installation"
103 return 1
104 fi
105 info "Warning: Directory \"$greeter_dir\" does not exist, creating it"
106 mkdir -p -m 755 "$greeter_dir" || return 1
107 fi
108
109 # Link to required greeter files into $greeter_dir.
110 add_symlink "$INSTALLATION_DIR/other/vbox-greeter.desktop" "$greeter_dir/vbox-greeter.desktop"
111
112 # Backup and activate greeter config.
113 if ! test -f "$lightdm_config.vbox-backup"; then
114 info "Backing up LightDM configuration file ..."
115 cp "$lightdm_config" "$lightdm_config.vbox-backup" || return 1
116 chmod 644 "$lightdm_config.vbox-backup" || return 1
117 fi
118 sed -i -e 's/^\s*greeter-session\s*=.*/greeter-session=vbox-greeter/g' "$lightdm_config" || return 1
119 chmod 644 "$lightdm_config" || return 1
120
121 info "Auto-logon installation successful"
122 return 0
123}
124
125mod_autologon_install()
126{
127 if [ -z "$MOD_AUTOLOGON_LIGHTDM_GREETER_DIR" ]; then
128 MOD_AUTOLOGON_LIGHTDM_GREETER_DIR=$MOD_AUTOLOGON_DEFAULT_LIGHTDM_GREETER_DIR
129 fi
130 if [ -z "$MOD_AUTOLOGON_LIGHTDM_CONFIG" ]; then
131 MOD_AUTOLOGON_LIGHTDM_CONFIG=$MOD_AUTOLOGON_DEFAULT_LIGHTDM_CONFIG
132 fi
133
134 mod_autologon_install_ex "$MOD_AUTOLOGON_LIGHTDM_GREETER_DIR" "$MOD_AUTOLOGON_LIGHTDM_CONFIG" "$MOD_AUTOLOGON_FORCE"
135 return $?
136}
137
138mod_autologon_pre_uninstall()
139{
140 echo "Preparing to uninstall auto-logon support ..."
141 return 0
142}
143
144mod_autologon_uninstall()
145{
146 if test -z "$MOD_AUTOLOGON_LIGHTDM_CONFIG"; then
147 return 0
148 fi
149 info "Un-installing auto-logon support ..."
150
151 # Switch back to original greeter.
152 if test -f "$MOD_AUTOLOGON_LIGHTDM_CONFIG.vbox-backup"; then
153 mv "$MOD_AUTOLOGON_LIGHTDM_CONFIG.vbox-backup" "$MOD_AUTOLOGON_LIGHTDM_CONFIG"
154 if test "$?" -ne "0"; then
155 info "Warning: Could not restore original LightDM config \"$MOD_AUTOLOGON_LIGHTDM_CONFIG\""
156 fi
157 fi
158
159 # Remove greeter directory (if not empty).
160 rm "$MOD_AUTOLOGON_LIGHTDM_GREETER_DIR" 2>/dev/null
161
162 info "Auto-logon uninstallation successful"
163 return 0
164}
165
166mod_autologon_config_save()
167{
168 echo "
169MOD_AUTOLOGON_LIGHTDM_CONFIG='$MOD_AUTOLOGON_LIGHTDM_CONFIG'
170MOD_AUTOLOGON_LIGHTDM_GREETER_DIR='$MOD_AUTOLOGON_LIGHTDM_GREETER_DIR'"
171}
172
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette