VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use