mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 06:31:18 +02:00
Add scripts to modify a rootfs.image for testability.
Review URL: http://chromereview.prom.corp.google.com/1177024 git-svn-id: svn://chrome-svn/chromeos/trunk@91 06c00378-0e64-4dae-be16-12b19f9950a1
This commit is contained in:
parent
2b93e5faf1
commit
66c440d687
14
mod_for_test_scripts/300changePassword
Executable file
14
mod_for_test_scripts/300changePassword
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/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.
|
||||||
|
|
||||||
|
# reset password for root and shared user account.
|
||||||
|
|
||||||
|
LOCAL_ACCOUNT="chronos"
|
||||||
|
echo "Reset password for root."
|
||||||
|
passwd root < test_account.passwd 2> /dev/null
|
||||||
|
echo "Reset password for ${LOCAL_ACCOUNT}."
|
||||||
|
passwd ${LOCAL_ACCOUNT} < test_account.passwd 2> /dev/null
|
||||||
|
|
12
mod_for_test_scripts/600autoStartSshd
Normal file
12
mod_for_test_scripts/600autoStartSshd
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/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.
|
||||||
|
|
||||||
|
# start sshd at os init time.
|
||||||
|
|
||||||
|
cp -pf sshd.conf /etc/init/sshd.conf
|
||||||
|
chmod 644 /etc/init/sshd.conf
|
||||||
|
chown 0:0 /etc/init/sshd.conf
|
||||||
|
|
0
mod_for_test_scripts/chronos.password
Normal file
0
mod_for_test_scripts/chronos.password
Normal file
0
mod_for_test_scripts/common.sh
Executable file
0
mod_for_test_scripts/common.sh
Executable file
8
mod_for_test_scripts/sshd.conf
Normal file
8
mod_for_test_scripts/sshd.conf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
start on login-prompt-ready
|
||||||
|
|
||||||
|
exec /etc/init.d/ssh start
|
||||||
|
|
3
mod_for_test_scripts/test_account.passwd
Normal file
3
mod_for_test_scripts/test_account.passwd
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
test0000
|
||||||
|
test0000
|
||||||
|
|
12
mod_for_test_scripts/test_setup.sh
Executable file
12
mod_for_test_scripts/test_setup.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/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.
|
||||||
|
|
||||||
|
cd `dirname $0`
|
||||||
|
for SCRIPT in [0-9][0-9][0-9]*[!$~]
|
||||||
|
do
|
||||||
|
./${SCRIPT}
|
||||||
|
done
|
||||||
|
|
76
mod_image_for_test.sh
Executable file
76
mod_image_for_test.sh
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
#!/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 modify a keyfob-based chromeos system image for testability.
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
DEFINE_string image "rootfs.image" \
|
||||||
|
"Location of the rootfs raw image file"
|
||||||
|
|
||||||
|
# Parse command line
|
||||||
|
FLAGS "$@" || exit 1
|
||||||
|
eval set -- "${FLAGS_ARGV}"
|
||||||
|
|
||||||
|
# Make sure anything mounted in the rootfs is cleaned up ok on exit.
|
||||||
|
cleanup_rootfs_mounts() {
|
||||||
|
# Occasionally there are some daemons left hanging around that have our
|
||||||
|
# root image file system open. We do a best effort attempt to kill them.
|
||||||
|
PIDS=`sudo lsof -t "${ROOT_FS_DIR}" | sort | uniq`
|
||||||
|
for pid in ${PIDS}
|
||||||
|
do
|
||||||
|
local cmdline=`cat /proc/$pid/cmdline`
|
||||||
|
echo "Killing process that has open file on our rootfs: $cmdline"
|
||||||
|
! sudo kill $pid # Preceded by ! to disable ERR trap.
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup_rootfs_loop() {
|
||||||
|
sudo umount "${LOOP_DEV}"
|
||||||
|
sleep 1 # in case $LOOP_DEV is in use
|
||||||
|
sudo losetup -d "${LOOP_DEV}"
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
# Disable die on error.
|
||||||
|
set +e
|
||||||
|
|
||||||
|
cleanup_rootfs_mounts
|
||||||
|
if [ -n "${LOOP_DEV}" ]
|
||||||
|
then
|
||||||
|
cleanup_rootfs_loop
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Turn die on error back on.
|
||||||
|
set -e
|
||||||
|
}
|
||||||
|
|
||||||
|
# main process begins here.
|
||||||
|
set -e
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
ROOT_FS_DIR="`dirname ${FLAGS_image}`/rootfs"
|
||||||
|
mkdir -p "${ROOT_FS_DIR}"
|
||||||
|
|
||||||
|
LOOP_DEV=`sudo losetup -f`
|
||||||
|
sudo losetup "${LOOP_DEV}" "${FLAGS_image}"
|
||||||
|
sudo mount "${LOOP_DEV}" "${ROOT_FS_DIR}"
|
||||||
|
|
||||||
|
MOD_SCRIPTS_ROOT="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts"
|
||||||
|
sudo mkdir -p "${ROOT_FS_DIR}/modify_scripts"
|
||||||
|
sudo mount --bind "${MOD_SCRIPTS_ROOT}" "${ROOT_FS_DIR}/modify_scripts"
|
||||||
|
|
||||||
|
# Run test setup script inside chroot jail to modify the image
|
||||||
|
sudo chroot "${ROOT_FS_DIR}" "/modify_scripts/test_setup.sh"
|
||||||
|
|
||||||
|
sudo umount "${ROOT_FS_DIR}/modify_scripts"
|
||||||
|
sudo rmdir "${ROOT_FS_DIR}/modify_scripts"
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
trap - EXIT
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user