-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
core
142 lines (127 loc) · 5.03 KB
/
core
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/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.
REQUIRES=''
DESCRIPTION='Performs core system configuration. Most users would want this.'
CHROOTBIN='brightness croutonpowerd croutonversion host-dbus host-wayland'
. "${TARGETSDIR:="$PWD"}/common"
### Append to prepare.sh:
echo 'Preparing environment...' 1>&2
if [ "$VERSION" != '#VERSION#' ]; then
sed -e "s ^VERSION=.*\$ VERSION='$VERSION' ;" \
-e "s ^RELEASE=.*\$ RELEASE='$RELEASE' ;" \
-e "s ^ARCH=.*\$ ARCH='$ARCH' ;" \
-i '/usr/local/bin/croutonversion'
fi
# Create the new environment file
oldenv='/etc/environment'
newenv='/etc/environment.new'
{
echo '### begin crouton-generated environment variables'
if [ "$PROXY" = 'unspecified' -o "$PROXY" = '#PROXY#' ]; then
# Copy over previously generated content
awk '/^### end/ { exit }
x && tolower($0) ~ /^[a-z]*_proxy=/
/^### begin/ { x=1 }' "$oldenv" 2>/dev/null || true
elif [ -n "$PROXY" ]; then
for var in http_proxy HTTP_PROXY https_proxy HTTPS_PROXY \
ftp_proxy FTP_PROXY; do
echo "$var='$PROXY'"
done
for var in no_proxy NO_PROXY; do
echo "$var='localhost,127.0.0.1'"
done
fi
echo '### end crouton-generated environment variables'
} > "$newenv"
# Set proxy variables for this script
. "$newenv"
export http_proxy https_proxy ftp_proxy
# Copy in previous user-environment settings
if [ -r "$oldenv" ]; then
awk '/^### begin/{x=1}!x;/^### end/{x=0}' "$oldenv" >> "$newenv"
fi
mv -f "$newenv" "$oldenv"
if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
echo 'Preparing software sources...' 1>&2
if [ "$PROXY" != 'unspecified' -a "$PROXY" != '#PROXY#' ]; then
aptproxy='/etc/apt/apt.conf.d/80croutonproxy'
if [ -z "$PROXY" ]; then
rm -f "$aptproxy"
else
cat > "$aptproxy" <<EOF
Acquire::http::proxy "$PROXY";
Acquire::ftp::proxy "$PROXY";
Acquire::https::proxy "$PROXY";
EOF
fi
fi
# Only update sources.list if MIRROR is specified
if [ -n "$MIRROR" -a "$MIRROR" != 'unspecified' ]; then
if [ "$DISTRO" = 'ubuntu' ]; then
# Ubuntu has its own categories of packages
cat > /etc/apt/sources.list <<EOF
deb $MIRROR $RELEASE main restricted universe multiverse
deb-src $MIRROR $RELEASE main restricted universe multiverse
deb $MIRROR $RELEASE-updates main restricted universe multiverse
deb-src $MIRROR $RELEASE-updates main restricted universe multiverse
deb $MIRROR $RELEASE-security main restricted universe multiverse
deb-src $MIRROR $RELEASE-security main restricted universe multiverse
EOF
else
# Not all Debian distros have all sets of repos
cat > /etc/apt/sources.list <<EOF
deb $MIRROR $RELEASE main non-free contrib
deb-src $MIRROR $RELEASE main non-free contrib
EOF
# Only stable and testing have an updates channel
if release -lt sid; then
cat >> /etc/apt/sources.list <<EOF
deb $MIRROR $RELEASE-updates main non-free contrib
deb-src $MIRROR $RELEASE-updates main non-free contrib
EOF
fi
# Some derivatives also have security updates
if release -le buster -eq kali; then
cat >> /etc/apt/sources.list <<EOF
deb $MIRROR2 $RELEASE/updates main non-free contrib
deb-src $MIRROR2 $RELEASE/updates main non-free contrib
EOF
fi
fi
fi
# Update the package list.
# Ignore failures, as most are due to bad PPAs and are not critical.
apt-get -y update || true
echo 'Ensuring system is up-to-date...' 1>&2
apt-get -y dist-upgrade
fi
# On release upgrade, keyboard-configuration might be reconfigured.
fixkeyboardmode
# Install critical packages
install --minimal sudo wget ca-certificates apt-transport-https
# Generate and set default locale
if ! grep -q '^[^#]*LANG=' /etc/default/locale 2>/dev/null && hash locale-gen 2>/dev/null; then
echo 'LANG=en_US.UTF-8' > '/etc/default/locale'
locale-gen --lang en_US.UTF-8
if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
dpkg-reconfigure locales
fi
fi
# Link debian_chroot to the chroot name
if [ "${DISTROAKA:-"$DISTRO"}" = 'debian' ]; then
ln -sfT '/etc/crouton/name' '/etc/debian_chroot'
fi
echo 'Syncing timezone...' 1>&2
# Link the timezone to Chromium OS
# Remove /etc/timezone: this tells Ubuntu/Debian that we are managing the
# content of /etc/localtime manually, and that it should not erase the symbolic
# link upon update, unless "dpkg-reconfigure tzdata" is called explicitly.
rm -f /etc/timezone
# /var/host/timezone/localtime is itself a symbolic link, but as long as the
# zoneinfo packages in the chroot and Chromium OS are the same, it'll be fine
ln -sfT /var/host/timezone/localtime /etc/localtime
# Link /etc/mtab to /proc/mounts. It's not totally accurate, but close enough,
# as it at least has / and all the media-mounted devices.
ln -sfT /proc/mounts /etc/mtab