From 8bef8020a022c52a8d1d4bb373b5c8cdc256284f Mon Sep 17 00:00:00 2001 From: James Meyer Date: Wed, 3 Sep 2014 18:10:16 -0500 Subject: Convert dev chroot to a container. This was needed to play nice with systemd and the way it mounts /dev/pts inside the chroot as public (breaking the default kernel policy). When public after /dev/pts inside the chroot is unmounted it also unmounts /dev/pts for the host. Same general steps as before. - Create new container with ./setup_env_container.sh - Enter container using ./enter_dev_container.$ARCH.$TS --- setup_env_container.sh | 208 +++++++++++++++++++++++++++++ templates/container-getty@.service | 26 ++++ templates/developers/jams/custom_chroot.sh | 14 +- templates/developers/jams/loginrun.sh | 4 +- templates/enter_dev_container.sh | 95 +++++++++++++ templates/etc/.bashrc | 3 +- 6 files changed, 341 insertions(+), 9 deletions(-) create mode 100755 setup_env_container.sh create mode 100644 templates/container-getty@.service create mode 100755 templates/enter_dev_container.sh diff --git a/setup_env_container.sh b/setup_env_container.sh new file mode 100755 index 0000000..3c293e5 --- /dev/null +++ b/setup_env_container.sh @@ -0,0 +1,208 @@ +#!/bin/bash +# Script to setup the LinHES development enviroment +# ./setup_env.sh ( i686|x86_64 ) devID +# This script assumes that /tmp is usable. +START_DIR=`pwd` +TS=`date +%Y%h%d_%H%M%S` + +function arg_check { + case $1 in + i686) ARCH=$1 ;; + x86_64) ARCH=$1 ;; + *) + echo "invalid arch specified" + echo "valid options include i686 and x86_64" + echo "EX: ./setup_env.sh i686 " + echo "EX: ./setup_env.sh x86_64 " + exit 1 + ;; + esac + + + case $2 in + release) BENV="release" ;; + testing) BENV="testing" ;; + + *) + echo "invalid env specified" + echo "valid options include release, testing" + echo "EX: ./setup_env.sh i686 testing" + echo "EX: ./setup_env.sh x86_64 testing" + exit 1 + ;; + esac + + + if [ ! x$3 = x ] + then + USER=$3 + #check if developer template is present + fi + +} + + +function pacman_check { + for i in pacman pacstrap + do + which $i + status=$? + if [ ! $status = 0 ] + then + echo "Can not find $i in the path." + exit 1 + fi + done + + +} + + +function checkout_repo { + mkdir -p $BENV/$ARCH + cd $BENV/$ARCH + + git clone git@linhes.org:linhes_dev + git clone git@linhes.org:linhes_pkgbuild + + # git clone $USER@knoppmyth.net:linhes_pkgbuild + # git clone $USER@knoppmyth.net:linhes_dev + + + if [ $BENV == "testing" ] + then + echo "=====================================" + echo "switching linhes_pkgbuild to testing" + + cd linhes_pkgbuild + git checkout -b testing origin/testing + cd - + + echo "=====================================" + fi + + if [ $BENV == "testing" ] + then + echo "=====================================" + echo "switching linhes_dev to testing" + + cd linhes_dev + git checkout -b testing origin/testing + cd - + + echo "=====================================" + fi + +} + +create_pkg_mirror_dir(){ + #create the local pkg dir's for mirror and creating pkg's + + [ -e $MIRROR_DIR ] || mkdir -p $MIRROR_DIR + + for i in i686 x86_64 + do + [ -e $MIRROR_DIR/$i ] || mkdir -p $MIRROR_DIR/$i + for y in core extra core-testing extra-testing + do + [ -e $MIRROR_DIR/$i/$y ] || mkdir -p $MIRROR_DIR/$i/$y + [ -e $MIRROR_DIR/src_packages/$y ] || mkdir -p $MIRROR_DIR/src_packages/$y + done + done + + [ -e $MIRROR_DIR/sources ] || mkdir -p $MIRROR_DIR/sources + [ -e $MIRROR_DIR/packages ] || mkdir -p $MIRROR_DIR/packages + +} + +create_container(){ + #correct pacman.conf to use the correct ARCH to build the chroot + cd $START_DIR/$BENV/$ARCH/linhes_dev + sed -e "s/REPLACEME/$ARCH/g" templates/pacman.conf.chroot > /tmp/pacman.conf.chroot + + #create the container + cd $START_DIR + #mkdir -p $START_DIR/$BENV/$ARCH/linhes_container_root.$ARCH + mkdir -p $CONTAINER_DIR + pacstrap -i -c -d -C /tmp/pacman.conf.chroot $CONTAINER_DIR base base-devel openssh unison + status=$? + + if [ ! $status = 0 ] + then + printf "\n" + printf "%s\n" "********************************************************" + printf "*** %-48s ***\n" " An error occured creating the container" + printf "%s\n" "********************************************************" + exit 1 + fi +} + + +copy_custom_developer_file(){ + cd $START_DIR/$BENV/$ARCH/linhes_dev + if [ -d templates/developers/$USER ] + then + #check for login run + if [ -f templates/developers/$USER/loginrun.sh ] + then + echo "copy loginrun.sh for $USER" + cp -f templates/developers/$USER/loginrun.sh $CONTAINER_DIR/root/loginrun.sh + fi + + if [ -f templates/developers/$USER/custom_chroot.sh ] + then + echo "running custom_chroot.sh for $USER" + cd templates/developers/$USER + BROOT=$CONTAINER_DIR ./custom_chroot.sh $ARCH + cd - + fi + + fi +} + +create_entry_files() { + + #create custom enter_dev_chroot.sh script + cp templates/enter_dev_container.sh ../enter_dev_container.$ARCH.$TS + sed -i "s/REPLACE_ARCH/$ARCH/" ../enter_dev_container.$ARCH.$TS + sed -i "s/REPLACE_TS/$TS/" ../enter_dev_container.$ARCH.$TS + + chmod 755 ../enter_dev_container.$ARCH.$TS + + printf "%s\n" "********************************************************" + printf "** %-50s **\n" " To enter the container (linhes_container_root.$ARCH.$TS) run:" + printf "** %-50s **\n" " cd $BENV/$ARCH" + printf "** %-50s **\n" " ./enter_dev_container.$ARCH.$TS" + printf "%s\n" "********************************************************" + + #copy makepkg.conf into the chroot + sed -e "s/REPLACEME/$ARCH/g" templates/makepkg.conf > ../linhes_container_root.$ARCH.$TS/etc/makepkg.conf + + #copy pacman.conf into the chroot + sed -e "s/REPLACEME/$ARCH/g" templates/pacman.conf.chroot > ../linhes_container_root.$ARCH.$TS/etc/pacman.conf +} + + + + +#----------------------------------------------- + +arg_check $1 $2 $3 +#checkout_repo +pacman_check + +MIRROR_DIR=$START_DIR/$BENV/pkg_repo +create_pkg_mirror_dir + +CONTAINER_DIR=$START_DIR/$BENV/$ARCH/linhes_container_root.$ARCH.$TS +create_container +copy_custom_developer_file +create_entry_files + + + + + + + + diff --git a/templates/container-getty@.service b/templates/container-getty@.service new file mode 100644 index 0000000..3f6d643 --- /dev/null +++ b/templates/container-getty@.service @@ -0,0 +1,26 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +[Unit] +Description=Container Getty on /dev/pts/%I +Documentation=man:agetty(8) man:machinectl(1) +After=systemd-user-sessions.service plymouth-quit-wait.service +Before=getty.target +IgnoreOnIsolate=yes + +[Service] +ExecStart=-/sbin/agetty --noclear --keep-baud pts/%I 115200,38400,9600 $TERM +Type=idle +Restart=always +RestartSec=0 +UtmpIdentifier=%I +TTYPath=/dev/%I +TTYReset=yes +TTYVHangup=yes +KillMode=process +IgnoreSIGPIPE=no +SendSIGHUP=yes diff --git a/templates/developers/jams/custom_chroot.sh b/templates/developers/jams/custom_chroot.sh index 75fe866..f8e6bce 100755 --- a/templates/developers/jams/custom_chroot.sh +++ b/templates/developers/jams/custom_chroot.sh @@ -1,11 +1,13 @@ #!/bin/bash -set -x -build_root="../../../../build_root" + +build_root=$BROOT + #copy in the ssh keys -cp -rp /home/jams/.ssh $build_root.${1}/root -chown root.root $build_root.${1}/root/.ssh +cp -rp /home/jams/.ssh $build_root/root +chown -R root.root $build_root/root/.ssh #copy in display -cp display.sh $build_root.${1}/etc/profile.d +cp display.sh $build_root/etc/profile.d + #copy in .gtkrc -cp .gtkrc-2.0 $build_root.${1}/root \ No newline at end of file +#cp .gtkrc-2.0 $build_root/root diff --git a/templates/developers/jams/loginrun.sh b/templates/developers/jams/loginrun.sh index dbd5d5c..ebe3c94 100755 --- a/templates/developers/jams/loginrun.sh +++ b/templates/developers/jams/loginrun.sh @@ -1,4 +1,4 @@ #!/bin/bash -thunar & -terminal & +#thunar & +#terminal & diff --git a/templates/enter_dev_container.sh b/templates/enter_dev_container.sh new file mode 100755 index 0000000..cd098a6 --- /dev/null +++ b/templates/enter_dev_container.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# A LinHES development script to start container +#--------- +#container_name='linhes_build_root_x86_64' +container_name='linhes_container_root.REPLACE_ARCH.REPLACE_TS' +container_dir=$(pwd) + +dev_tools='linhes_dev' +package_build_dir='linhes_pkgbuild' +repo_base_dir='pkg_repo' +repo_base_dir_source='../pkg_repo' + +templates="$dev_tools/templates" + +#-------- + + + +copy_files(){ + +if [ ! -f $container_name/etc/profile.d/kmdev.sh ] + then + echo " Missing kmdev.sh, copy in setup files" + cp -f $templates/etc/.bashrc $container_name/root/.bashrc + cp -f $templates/etc/.bash_profile $container_name/root/ + + cp -f $templates/etc/bashrc $container_name/etc/bashrc_linhes + cp -f $templates/etc/kmdev.sh $container_name/etc/profile.d/ + + chmod 0755 $container_name/etc/profile.d/kmdev.sh + cp -f $templates/container-getty\@.service $container_name/etc/systemd/system/ + + grep -q pts $container_name/etc/securetty + rc=$? + if [ ! $rc -eq 0 ] + then + for i in `seq 5` + do + echo pts\/$i >> $container_name/etc/securetty + + done + + fi + + + + fi + +} + +pre_checks(){ + # must be root: + if [ $EUID -ne 0 ] + then + echo -e "Must be run as the root user" 1>&2 + exit 1 + fi + + # must have the chroot subdirectory: + if [ ! -d $BROOT ] + then + echo $BROOT directory not found + fi + +} + + +main(){ + pre_checks + + #copy in linhes files + copy_files + + + #Start container + #check for to see if start it with nspawn or machinectl login + + machinectl list | grep -q $container_name + rc=$? + +if [ $rc -eq 0 ] +then + echo "Trying machinectl" + machinectl login $container_name +else + systemd-nspawn -bD $container_name\ + --bind=$container_dir/$package_build_dir:/data/$package_build_dir \ + --bind=$container_dir/$dev_tools/build_tools:/build_tools \ + --bind=$container_dir/$repo_base_dir_source:/data/$repo_base_dir +fi + + +} + +main \ No newline at end of file diff --git a/templates/etc/.bashrc b/templates/etc/.bashrc index 9abf8d0..2874bab 100755 --- a/templates/etc/.bashrc +++ b/templates/etc/.bashrc @@ -1,3 +1,4 @@ #!/bin/bash . /etc/profile -. /etc/bashrc +. /etc/bash.bashrc +. /etc/bashrc_linhes -- cgit v0.12