#!/bin/bash # Copyright (c) 2009 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. # Script to customize the root file system after packages have been installed. # # NOTE: This script should be called by build_image.sh. Do not run this # on your own unless you know what you are doing. # Load common constants. This should be the first executable line. # The path to common.sh should be relative to your script's location. . "$(dirname "$0")/common.sh" # Script must be run inside the chroot assert_inside_chroot # Flags DEFINE_string target "x86" \ "The target architecture to build for. One of { x86, arm }." DEFINE_string root "" \ "The root file system to customize." # Parse command line FLAGS "$@" || exit 1 eval set -- "${FLAGS_ARGV}" # Die on any errors. set -e ROOT_FS_DIR="$FLAGS_root" if [[ -z "$ROOT_FS_DIR" ]]; then echo "Error: --root is required." exit 1 fi if [[ ! -d "$ROOT_FS_DIR" ]]; then echo "Error: Root FS does not exist? ($ROOT_FS_DIR)" exit 1 fi # Determine default user full username. if [ ${CHROMEOS_OFFICIAL:-0} = 1 ]; then FULLNAME="Google Chrome OS User" else FULLNAME="Chromium OS User" fi # Determine what password to use for the default user. CRYPTED_PASSWD_FILE="${SCRIPTS_DIR}/shared_user_passwd.txt" if [ -f $CRYPTED_PASSWD_FILE ]; then echo "Using password from $CRYPTED_PASSWD_FILE" CRYPTED_PASSWD=$(cat $CRYPTED_PASSWD_FILE) else # Use a random password. unix_md5_crypt will generate a random salt. echo "Using random password." PASSWORD="$(base64 /dev/urandom | head -1)" CRYPTED_PASSWD="$(echo "$PASSWORD" | openssl passwd -1 -stdin)" PASSWORD="gone now" fi # Set up a default user and add to sudo and the required groups. ADD_USER="chronos" ADD_GROUPS="audio video" SHELL="/bin/sh" if [[ -x "${ROOT_FS_DIR}/bin/bash" ]] ; then SHELL="/bin/bash" fi echo "${ADD_USER}:x:1000:1000:${FULLNAME}:/home/${ADD_USER}/:${SHELL}" | \ sudo dd of="${ROOT_FS_DIR}/etc/passwd" conv=notrunc oflag=append echo "${ADD_USER}:${CRYPTED_PASSWD}:14500:0:99999::::" | \ sudo dd of="${ROOT_FS_DIR}/etc/shadow" conv=notrunc oflag=append echo "${ADD_USER}:x:1000:" | \ sudo dd of="${ROOT_FS_DIR}/etc/group" conv=notrunc oflag=append for i in $ADD_GROUPS; do sudo sed -i "s/^\($i:x:[0-9]*:.*\)/\1,${ADD_USER}/g" \ "${ROOT_FS_DIR}"/etc/group done sudo mkdir -p "${ROOT_FS_DIR}/home/${ADD_USER}" sudo chown 1000.1000 "${ROOT_FS_DIR}/home/${ADD_USER}" cat <