blob: d05e595cd1edd4ddbca3ded37f5b03644c7cb451 [file] [log] [blame]
#!/bin/sh
# Copyright (c) 2011 The Chromium OS 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 script downloads and installs the basic packages that the user needs
# in developer mode. It also takes care of some configuration details
# that arise from not havin write access to the root filesystem.
# Constant definitions.
EMERGE_PACKAGES="/etc/portage/bootstrap.packages"
# TODO(arkaitzr): Fix the color output if time allows.
# Color the script output a little.
ERROR_S_COLOR="\033[47m\033[44m\033[1m"
ERROR_E_COLOR="\033[0m"
S_COLOR="\033[40m\033[32m\033[1m"
E_COLOR="\033[0m"
# This script should only run in developer mode or for developer images.
/usr/bin/crossystem cros_debug?0
CROS_DEBUG=$?
if [ ${CROS_DEBUG} -ne 1 ]; then
echo -e "${ERROR_S_COLOR}ERROR: Can not run script."
echo -e "Chrome OS is not in developer mode.${ERROR_E_COLOR}"
exit 1
fi
# Check if we are root.
if [ $(/usr/bin/id -u) -ne 0 ]; then
echo -e "${ERROR_S_COLOR}ERROR: Can not run script."
echo -e "You are not root or you did not use sudo.${ERROR_E_COLOR}"
exit 1
fi
# Create work directory.
WORKDIR="$(mktemp -d /tmp/dev-installer.XXXX)"
# Copy emerge configuration to /usr/local.
mkdir -p -m 0755 /usr/local/etc/portage
cp /etc/portage/make.profile/make.conf /usr/local/etc/portage
ln -s /etc/portage/make.profile /usr/local/etc/portage/make.profile
# Get the portage configuration variables.
. /etc/portage/make.profile/make.defaults
# Create the directories defined in the portage config files. Permissions are
# consistent with the other directories in /usr/local, which is a bind mount
# for /mnt/stateful_partition/dev_image.
mkdir -p -m 0755 "${PORTDIR}"
mkdir -p -m 0755 "${PKGDIR}"
mkdir -p -m 0755 "${DISTDIR}"
mkdir -p -m 0755 "${RPMDIR}"
mkdir -p -m 0755 "${PORTAGE_TMPDIR}"
mkdir -p -m 0755 "${BUILD_PREFIX}"
# Create this loop so uncompressed files in /usr/local/usr/* will be reachable
# through /usr/local*.
if [ ! -d /usr/local/usr ]; then
ln -s /usr/local /usr/local/usr
fi
# Get the static Python binary and portage (emerge script and python modules).
download_bootstrap_packages() {
# Obtain the BOOTSTRAP and BINHOST variables.
. /etc/portage/repository.conf
# Download packages that python/emerge require into /usr/local/bootsrap.
while read line; do
local package_url
local directory
local package_file
package_url="${BINHOST}packages/$line.tbz2"
directory=`echo "${line}" | cut -d"/" -f1`
package_file="${PKGDIR}/$line.tbz2"
mkdir -p -m 0755 "/usr/local/portage/packages/${directory}"
wget -nv -N -nd -P "/usr/local/portage/packages/${directory}" \
"${package_url}"
wget_exit_code=$?
if [ ${wget_exit_code} -ne 0 ]; then
echo -e "${ERROR_S_COLOR}ERROR: Could not download package."
echo -e "Command wget -nv -N -nd -P /usr/local/portage/packages/" \
"${directory} ${package_url} failed.${ERROR_E_COLOR}"
exit 1
fi
# Ignore std error output about trailing garbage after EOF.
tar -C "/usr/local/" -xjf "${package_file}" 2>/dev/null
tar_exit_code=$?
if [ ${tar_exit_code} -ne 0 ]; then
echo -e "${ERROR_S_COLOR}ERROR: Could not extract package."
echo -e "Command tar -C /usr/local -xjf ${package_file} " \
"failed.${ERROR_E_COLOR}"
exit 1
fi
done < "${EMERGE_PACKAGES}"
}
# Configure emerge in /usr/local.
configure_emerge() {
# Add LD_LIBRARY_PATH within ebuild.sh.
# TODO(arkaitzr): find out a cleaner way to do this.
sed -i '3 a\export LD_LIBRARY_PATH=/usr/local/lib' \
/usr/local/lib/portage/bin/ebuild.sh
}
install_optional_packages() {
local reply
read -p "Install chromeos-dev package now (y/n)?" reply
if [ "${reply}" = "y" ]; then
emerge chromeos-dev
else
echo "You can install chromeos-dev later by typing the command:"
echo "emerge chromeos-dev"
fi
}
cleanup_directories() {
rm -r "${WORKDIR}"
}
echo "Starting installation of developer packages."
echo "First, we download the necessary files."
download_bootstrap_packages
echo "Files downloaded, configuring emerge."
configure_emerge
echo "Emerge installation complete. Installing additional optional packages."
install_optional_packages
echo "Cleaning temporary directories."
cleanup_directories
echo "dev_install done. Enjoy!"