forked from dnschneid/crouton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-common
76 lines (67 loc) · 2.21 KB
/
post-common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh -e
# Copyright (c) 2016 The crouton Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This is a target, but it's not selectable by the user. These are the commands
# that get executed at the very end of the generated prepare.sh.
# These commands are not optional and are automatically added to targets.
REQUIRES=''
DESCRIPTION=''
HOSTBIN='enter-chroot delete-chroot edit-chroot mount-chroot unmount-chroot'
HOSTBIN="$HOSTBIN crash_reporter_wrapper"
. "${TARGETSDIR:="$PWD"}/common"
### Append to prepare.sh:
# Set the default coredump handler
if [ ! -f '/etc/crouton/core_pattern' ]; then
core_pattern=''
if [ "$DISTRO" = 'ubuntu' ]; then
core_pattern='|/usr/share/apport/apport %p %s %c'
fi
echo "\
# The first non-comment line is the core_pattern that applies to this chroot.
# See man 5 core for details.
$core_pattern" > '/etc/crouton/core_pattern'
fi
echo 'Cleaning up...' 1>&2
if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
apt-get -y --purge autoremove
apt-get clean
fi
# Add the primary user
groups='audio,input,video,wayland,sudo,plugdev,crouton'
if ! grep -q ':1000:' /etc/passwd; then
while ! echo "$username" | grep -q '^[a-z][-a-z0-9_]*$'; do
if [ -n "$username" ]; then
echo_tty 'Username must be lowercase letters, numbers, or dashes.'
fi
echo_tty -n "$(echo_color "b" "Please specify a username for the primary user: ")"
if [ -n "$USERNAME" ]; then
username="$USERNAME"
echo "$username" 1>&2
else
read -r username junk
fi
done
useradd -u 1000 -G "$groups" -s '/bin/bash' -m "$username"
if [ -t 0 ]; then
tries=0
else
tries=3
fi
while [ "$tries" -lt 3 ] && ! passwd "$username"; do
tries="$((tries+1))"
done
if [ "$tries" = 3 ]; then
echo \
"Password left unset. To set a password, inside the chroot run: passwd $username" 1>&2
fi
else
username="`awk -F: '$3==1000{print $1; exit}' '/etc/passwd'`"
usermod -a -G "$groups" "$username"
fi
if [ -n "$TIPS" ]; then
echo "
$(echo_color "b" "Here's some tips:")
$TIPS" 1>&2
fi
rm -f "$0"