| #!/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" |
| # Global variables. |
| BINHOST="" |
| |
| # Check if we are root. |
| if [ $(/usr/bin/id -u) -ne 0 ]; then |
| echo "ERROR: Can not run script." |
| echo "You are not root or you did not use sudo." |
| exit 1 |
| fi |
| |
| # 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 "ERROR: Can not run script." |
| echo "Chrome OS is not in developer mode." |
| exit 1 |
| fi |
| |
| # Process flags. |
| . /usr/lib/shflags |
| DEFINE_string binhost "" \ |
| "URL of the binhost that emerge will use." |
| DEFINE_string binhost_version "" \ |
| "Version number to use instead of the one in /etc/lsb-release." |
| DEFINE_boolean uninstall "${FLAGS_FALSE}" \ |
| "Remove all installed packages." |
| DEFINE_boolean reinstall "${FLAGS_FALSE}" \ |
| "Remove all installed packages and re-bootstrap emerge." |
| |
| FLAGS "$@" || exit 1 |
| |
| set -e |
| |
| # Here we simply wipe /usr/local/* since that it's the only directory in which |
| # packages are installed to. |
| remove_installed_packages() { |
| read -p "Remove all installed packages now (y/n)?" reply |
| if [ "${reply}" = "y" ]; then |
| rm -rf --one-file-system /usr/local/* |
| echo "Removed all installed packages." |
| else |
| echo "Operation cancelled." |
| exit 0 |
| fi |
| } |
| |
| if [ ${FLAGS_uninstall} -eq ${FLAGS_TRUE} \ |
| -o ${FLAGS_reinstall} -eq ${FLAGS_TRUE} ]; then |
| remove_installed_packages |
| if [ ${FLAGS_uninstall} -eq ${FLAGS_TRUE} ]; then |
| exit 0 |
| else |
| echo "Reinstalling emerge." |
| fi |
| fi |
| |
| # Check if packages are already installed. |
| if [ -d /usr/local/etc/portage ]; then |
| echo "ERROR: Directory /urs/local/etc/portage exists." |
| echo "Did you mean dev_install --reinstall?" |
| exit 1 |
| fi |
| |
| # Get the portage configuration variables. |
| . /etc/portage/make.profile/make.defaults |
| |
| # 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 |
| |
| if [ ! -d /usr/local/local ]; then |
| ln -s /usr/local /usr/local/local |
| fi |
| |
| get_binhost() { |
| if [ -n "${FLAGS_binhost}" ]; then |
| BINHOST="${FLAGS_binhost}" |
| else |
| local release_number |
| # Get prefix for binhost. |
| . /etc/portage/repository.conf |
| |
| if [ -n "${FLAGS_binhost_version}" ]; then |
| release_number="${FLAGS_binhost_version}" |
| else |
| # Get the release number. |
| release_number=`grep "CHROMEOS_RELEASE_VERSION" /etc/lsb-release | |
| grep -Eo "[0-9]\.[0-9]+\.[0-9]+"` |
| fi |
| BINHOST="${PREFIX_BINHOST}full-${release_number}.0/packages" |
| fi |
| } |
| |
| # Get the static Python binary and portage (emerge script and python modules). |
| download_bootstrap_packages() { |
| # 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}/$line.tbz2" |
| directory=`echo "${line}" | cut -d"/" -f1` |
| package_file="${PKGDIR}/$line.tbz2" |
| mkdir -p -m 0755 "${PKGDIR}/${directory}" |
| echo "Downloading ${package_url}" |
| curl -o "${package_file}" "${package_url}" |
| cur_exit_code=$? |
| if [ ${curl_exit_code} -ne 0 ]; then |
| echo "ERROR: Could not download package." |
| echo "Command wget -nv -N -nd -P ${PKGDIR}/" \ |
| "${directory} ${package_url} failed." |
| exit 1 |
| fi |
| echo "Extracting ${package_file}" |
| # 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 "ERROR: Could not extract package." |
| echo "Command tar -C /usr/local -xjf ${package_file} failed." |
| exit 1 |
| fi |
| done < "${EMERGE_PACKAGES}" |
| } |
| |
| # Configure emerge in /usr/local. |
| configure_emerge() { |
| # 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 |
| |
| # 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}" |
| |
| echo "PORTAGE_BINHOST=${BINHOST}" >> /usr/local/etc/portage/make.conf |
| |
| # 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 |
| # TODO(arkaitzr): remove emergeing perf once the packages dependencies are |
| # correct. Now chromeos-dev does not install because of missing |
| # virtual/perf although dev-util/perf is available. |
| emerge dev-util/perf |
| emerge chromeos-dev |
| else |
| echo "You can install chromeos-dev later by typing the command:" |
| echo "emerge chromeos-dev" |
| fi |
| } |
| |
| echo "Starting installation of developer packages." |
| echo "First, we download the necessary files." |
| get_binhost |
| download_bootstrap_packages |
| |
| echo "Files downloaded, configuring emerge." |
| configure_emerge |
| |
| echo "Emerge installation complete. Installing additional optional packages." |
| install_optional_packages |
| |
| echo "dev_install done. Enjoy!" |
| |