Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # mer-sdk-chroot
- # TODO
- #
- # Support a Mer clean setup (ie no .oscrc)
- # Support multiple shells (ie split setup/entry)
- usage()
- {
- cat <<EOF
- usage: $0 [-u <user>] [-m <all|none|root|home>] [-r <SDK root path>] [<command> <args> ..]
- $0 -h
- This is the Mer chroot SDK.
- For information see http://wiki.merproject.org/wiki/Platform_SDK
- If command is not present,
- used to enter the SDK and begin working. The SDK bash shell is a
- login shell. See below for .profile handling
- If command is present,
- used to execute an arbitrary command from within the SDK chroot
- environment. The environment variable MERSDK is set to allow
- SDK detection.
- Options:
- -u System user to link into SDK (not needed if using sudo)
- -m Devices to bind mount from host: none, all (default)
- root, home
- -r The root of the SDK to use - normally derived from the
- pathname of $0
- -h Show this help
- Profile
- Entering the SDK runs the user's normal .profile and any (SDK)
- system profile entries. It will not execute the host's system
- profile entries.
- The environment variable MERSDK is set to allow .profile to
- detect the SDK.
- If the user has a ~/.mersdk.profile then it is sourced after the
- normal .profile handling (this allows the common use case of
- setting a profile to be handled).
- Hooks
- If the user specified has a .mersdkrc in their $HOME, it will be
- sourced to allow hook functions to be defined. Hooks are run as
- root. No commands should be executed immediately.
- These hooks are usually used to define symbolic links from any
- /parentroot/data type filesystems into the SDK root to setup
- system specific shared caches or filesystem layouts etc
- EOF
- return 0
- }
- MY_SSH_AUTH_SOCK=${SSH_AUTH_SOCK#/parentroot}
- [[ $MY_SSH_AUTH_SOCK ]] && MY_SSH_AUTH_SOCK="/parentroot$MY_SSH_AUTH_SOCK"
- if [[ $EUID -ne 0 ]]; then
- exec sudo SSH_AGENT_PID=${SSH_AGENT_PID:-} SSH_AUTH_SOCK=${MY_SSH_AUTH_SOCK} $0 "$@"
- echo "$0 must be run as root and sudo failed; exiting"
- exit 1
- fi
- if cmp -s /proc/$PPID/mountinfo /proc/self/mountinfo; then
- exec unshare -m -- "$0" "$@"
- echo "$0 must be run in private namespace and unshare failed; exiting"
- exit 1
- fi
- # Make sure that mountpoints in the new namespace are really unshared from the
- # parental namespace. See unshare(1).
- # This prevents mounts in the sdk from appearing in the parent fs.
- mount --make-rslave /
- # Use the SUDO value if present
- user=$SUDO_USER || true;
- bind_mount_root="yes";
- bind_mount_home="yes";
- while getopts "u:m:r:" opt; do
- case $opt in
- u ) user=$OPTARG;;
- m )
- case $OPTARG in
- all) ;;
- home)
- bind_mount_root="no";;
- root)
- bind_mount_home="no";;
- none)
- bind_mount_root="no";
- bind_mount_home="no";;
- *) echo "Only 'none', 'all' or 'home' are permitted for -m"
- usage
- exit 1;;
- esac ;;
- r ) sdkroot=$OPTARG;;
- h|\? ) usage
- exit 1;;
- : ) echo "Option -$OPTARG requires an argument." >&2
- usage
- exit 1;;
- * ) usage
- exit 1;;
- esac
- done
- shift $(($OPTIND - 1))
- if [[ -z "${sdkroot}" ]] ; then
- sdkroot=$(dirname $(readlink -f $0))
- else
- sdkroot=$(readlink -f $sdkroot)
- fi
- if [[ ! -f ${sdkroot}/etc/MerSDK ]] ; then
- echo "${sdkroot} does not look like a Mer SDK rootfs"
- echo "if you are sure it is, you may mark it by running"
- echo "echo 'MerSDK' | sudo tee ${sdkroot}/etc/MerSDK"
- exit 1
- fi
- if ! [[ $(basename $(dirname $sdkroot)) == "sdks" ]]; then
- echo "Non-standard SDK installation layout - cannot determine location for "
- echo "SDK targets and toolings. Expected layout is:"
- echo ""
- echo " <path/to/SDKs...>/"
- echo " ├── sdks/"
- echo " │ ├── <sdk_1>/"
- echo " │ ├── <sdk_2>/"
- echo " │ └── .../"
- echo " ├── targets/"
- echo " │ ├── <targets_1>/"
- echo " │ ├── <targets_2>/"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement