From e29f031bec1857f5a3b1bbeb3333d7695fc8587b Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Wed, 13 Sep 2017 16:57:12 -0500 Subject: [PATCH] Update Gentoo element for element changes There have been a few changes over the past few months, here we make the following changes. * change from backtrack=99 to complete-graph as a more correct flag * make python version selection more in line with what gentoo supports * set up python before stuff gets pip installed * ensure we have the proper pip so we can install pip packages as root * ensure we have the proper use flags for the disk formatting changes * set DIB_RELEASE like other distros * fix openssh-server element for gentoo Change-Id: I17202de3016616ce34c8cbead7d0fb047a64e96b --- diskimage_builder/elements/gentoo/README.rst | 10 +++ diskimage_builder/elements/gentoo/bin/fix_shm | 45 +++++++++++ .../elements/gentoo/bin/install-packages | 44 +---------- .../elements/gentoo/bin/unfix_shm | 34 ++++++++ .../environment.d/00-gentoo-envars.bash | 3 + .../elements/gentoo/finalise.d/99-cleanup | 21 ++--- .../gentoo/pre-install.d/03-gentoo-flags | 19 +++++ .../pre-install.d/10-install-desired-python | 78 +++++++++++++++++++ .../post-install.d/80-enable-sshd-service | 3 +- 9 files changed, 204 insertions(+), 53 deletions(-) create mode 100755 diskimage_builder/elements/gentoo/bin/fix_shm create mode 100755 diskimage_builder/elements/gentoo/bin/unfix_shm create mode 100755 diskimage_builder/elements/gentoo/pre-install.d/03-gentoo-flags create mode 100755 diskimage_builder/elements/gentoo/pre-install.d/10-install-desired-python diff --git a/diskimage_builder/elements/gentoo/README.rst b/diskimage_builder/elements/gentoo/README.rst index 14b97b10d..7ebb23b0f 100644 --- a/diskimage_builder/elements/gentoo/README.rst +++ b/diskimage_builder/elements/gentoo/README.rst @@ -34,3 +34,13 @@ Notes: * You can set the GENTOO_PORTAGE_CLEANUP environment variable to true (or anything other than False) to clean up portage from the system and get the image size smaller. + +* Gentoo supports many diferent versions of python, in order to select one + you may use the `GENTOO_PYTHON_TARGETS` environment variable to select + the versions of python you want on your image. The format of this variable + is a string as follows `"python2_7 python3_5"`. + +* In addition you can select the primary python version you wish to use (that + which will be called by running the `python` command. The + `GENTOO_PYTHON_ACTIVE_VERSION` is used to set that mapping. The variable + contents can be something like `python3.5`. diff --git a/diskimage_builder/elements/gentoo/bin/fix_shm b/diskimage_builder/elements/gentoo/bin/fix_shm new file mode 100755 index 000000000..e85e7c245 --- /dev/null +++ b/diskimage_builder/elements/gentoo/bin/fix_shm @@ -0,0 +1,45 @@ +#!/bin/bash + +# Copyright 2017 Matthew Thode +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +if [[ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]]; then + set -x +fi +set -eu +set -o pipefail + +# make /dev/shm dir if it doesn't exist +# mount tmpfs and chown it +# existing programs could be using /dev/shm +# This means it cannot be moved or backed +# up as a copy easily. The only remaining +# option is to move the link if it exists +# as a link. Existing programs will still +# hold the file handle of the original +# location open and new programs can use +# the fixed /dev/shm. +[[ -e /run/lock/shm_fixed ]] && exit 0 # shm has already been fixed +if [[ ! -d /dev/shm ]]; then + if [[ ! -e /dev/shm ]]; then + if [[ -L /dev/shm ]]; then + mv /dev/shm /dev/shm.orig + fi + mkdir /dev/shm + fi +fi +mount -t tmpfs none /dev/shm +chmod 1777 /dev/shm +mkdir -p /run/lock +touch /run/lock/shm_fixed diff --git a/diskimage_builder/elements/gentoo/bin/install-packages b/diskimage_builder/elements/gentoo/bin/install-packages index 04c4cff8e..b98ec16a5 100755 --- a/diskimage_builder/elements/gentoo/bin/install-packages +++ b/diskimage_builder/elements/gentoo/bin/install-packages @@ -32,49 +32,9 @@ function show_options { exit 0 } -function fix_shm { - # make /dev/shm dir if it doesn't exist - # mount tmpfs and chown it - # existing programs could be using /dev/shm - # This means it cannot be moved or backed - # up as a copy easily. The only remaining - # option is to move the link if it exists - # as a link. Existing programs will still - # hold the file handle of the original - # location open and new programs can use - # the fixed /dev/shm. - if [[ "${RUN_ONCE_SHM}" == '1' ]]; then - if [[ ! -d /dev/shm ]]; then - if [[ ! -e /dev/shm ]]; then - if [[ -L /dev/shm ]]; then - mv /dev/shm /dev/shm.orig - fi - mkdir /dev/shm - fi - fi - mount -t tmpfs none /dev/shm - chmod 1777 /dev/shm - RUN_ONCE_SHM='0' - fi -} - -function unfix_shm { - # unmount tmpfs - # care about anything still using it - if [[ "${RUN_ONCE_SHM}" == '0' ]]; then - umount /dev/shm - if fuser /dev/shm; then - rmdir /dev/shm - fi - if [[ -e /dev/shm.orig ]]; then - mv /dev/shm.orig /dev/shm - fi - fi -} - function install_gentoo_packages { RUN_ONCE_SHM='1' - if grep -q /dev/shm /proc/mounts; then + if mountpoint -q /dev/shm; then emerge $@ elif [[ -k /dev/shm ]]; then emerge $@ @@ -98,7 +58,7 @@ while true; do if [[ ! -f /usr/portage/profiles ]]; then emerge-webrsync -q fi - install_gentoo_packages -uDNv --with-bdeps=y --backtrack=99 --jobs=2 @world + install_gentoo_packages -uDNv --with-bdeps=y --complete-graph=y --jobs=2 @world install_gentoo_packages --verbose=n --depclean install_gentoo_packages -v --usepkg=n @preserved-rebuild etc-update --automode -5 diff --git a/diskimage_builder/elements/gentoo/bin/unfix_shm b/diskimage_builder/elements/gentoo/bin/unfix_shm new file mode 100755 index 000000000..1f302782a --- /dev/null +++ b/diskimage_builder/elements/gentoo/bin/unfix_shm @@ -0,0 +1,34 @@ +#!/bin/bash + +# Copyright 2017 Matthew Thode +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +if [[ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]]; then + set -x +fi +set -eu +set -o pipefail + + +# unmount tmpfs +# care about anything still using it +[[ ! -e /run/lock/shm_fixed ]] && exit 0 # shm hasn't been modified +umount /dev/shm +if fuser /dev/shm; then + rmdir /dev/shm +fi +if [[ -e /dev/shm.orig ]]; then + mv /dev/shm.orig /dev/shm +fi +rm /run/lock/shm_fixed diff --git a/diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash b/diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash index 65cf93d25..fad06d68f 100644 --- a/diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash +++ b/diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash @@ -1,3 +1,6 @@ +export DIB_RELEASE=gentoo export DISTRO_NAME=gentoo export GENTOO_PROFILE=${GENTOO_PROFILE:-'default/linux/amd64/13.0'} export GENTOO_PORTAGE_CLEANUP=${GENTOO_PORTAGE_CLEANUP:-'False'} +export GENTOO_PYTHON_TARGETS=${GENTOO_PYTHON_TARGETS:-'python2_7 python3_4'} +export GENTOO_PYTHON_ACTIVE_VERSION=${GENTOO_PYTHON_ACTIVE_VERSION:-'python3.4'} diff --git a/diskimage_builder/elements/gentoo/finalise.d/99-cleanup b/diskimage_builder/elements/gentoo/finalise.d/99-cleanup index e6bd96d1e..86c098b7c 100755 --- a/diskimage_builder/elements/gentoo/finalise.d/99-cleanup +++ b/diskimage_builder/elements/gentoo/finalise.d/99-cleanup @@ -6,15 +6,16 @@ fi set -eu set -o pipefail -# make sure system is in a consistent state -echo 'PYTHON_TARGETS="python3_4"' >> /etc/portage/make.conf -eselect python set python3.4 -# allow these uninstalls to fail as they may not be installed -set +e -emerge -C -q dev-lang/python:2.7 -emerge -C -q dev-vcs/git -set -e -USE="-build" emerge -q --backtrack=99 --jobs=2 --update --newuse --deep --with-bdeps=y @world +if mountpoint -q /dev/shm; then + echo "/dev/shm found in /proc/self/mountinfo" +elif [[ -k /dev/shm ]]; then + echo "/dev/shm exists and is stickied" +else + fix_shm +fi + +# make world consistant +USE="-build" emerge -q --complete-graph=y --jobs=2 --update --newuse --deep --with-bdeps=y @world # rebuild packages that might need it USE="-build" emerge -q --jobs=2 --usepkg=n @preserved-rebuild # remove unneeded packages @@ -45,3 +46,5 @@ if [[ -a /usr/sbin/grub2-install ]]; then mkdir -p /tmp/grub touch /tmp/grub/install fi + +unfix_shm diff --git a/diskimage_builder/elements/gentoo/pre-install.d/03-gentoo-flags b/diskimage_builder/elements/gentoo/pre-install.d/03-gentoo-flags new file mode 100755 index 000000000..3270e26db --- /dev/null +++ b/diskimage_builder/elements/gentoo/pre-install.d/03-gentoo-flags @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi +set -eu +set -o pipefail + +mkdir -p /etc/portage/package.use +mkdir -p /etc/portage/package.keywords + +# needed in order to install pip packages as root +echo 'dev-python/pip vanilla' >> /etc/portage/package.use/pip +# needed to create disk images +echo 'sys-fs/lvm2 -thin' >> /etc/portage/package.use/grub +echo 'sys-boot/grub device-mapper' >> /etc/portage/package.use/grub + +# needed in order to install pip packages as root +echo '=dev-python/pip-9.0.1-r2 ~amd64' >> /etc/portage/package.keywords/pip diff --git a/diskimage_builder/elements/gentoo/pre-install.d/10-install-desired-python b/diskimage_builder/elements/gentoo/pre-install.d/10-install-desired-python new file mode 100755 index 000000000..e4df3b2d5 --- /dev/null +++ b/diskimage_builder/elements/gentoo/pre-install.d/10-install-desired-python @@ -0,0 +1,78 @@ +#!/bin/bash + +if [[ ${DIB_DEBUG_TRACE:-0} -gt 0 ]]; then + set -x +fi +set -eu +set -o pipefail + +if mountpoint -q /dev/shm; then + echo "/dev/shm found in /proc/self/mountinfo" +elif [[ -k /dev/shm ]]; then + echo "/dev/shm exists and is stickied" +else + fix_shm +fi + +if [[ ! -f /usr/portage/profiles ]]; then + emerge-webrsync -q +fi + +# get the directories in order +mkdir -p /etc/portage/profile +mkdir -p /etc/portage/package.keywords +mkdir -p /etc/portage/package.use + +# python-3.6 and python-3.5 are masked and considered unstable for some reason +echo "PYTHON_TARGETS=\"${GENTOO_PYTHON_TARGETS}\"" >> /etc/portage/make.conf +if [[ "${GENTOO_PYTHON_TARGETS}" == *"python3_6"* ]]; then + echo -e "-python_targets_python3_6\n-python_single_target_python3_6" >> /etc/portage/profile/use.stable.mask + echo 'dev-lang/python:3.6 ~amd64' >> /etc/portage/package.keywords/python + echo '~dev-python/setuptools-36.0.1 ~amd64' >> /etc/portage/package.keywords/python + echo '~dev-python/pyxattr-0.6.0 ~amd64' >> /etc/portage/package.keywords/python + echo '~sys-apps/kmod-24 ~amd64' >> /etc/portage/package.keywords/python + [[ ! -e /usr/lib64/libpython3.6m.so ]] && USE="-build" emerge -1q --jobs=2 dev-lang/python:3.6 +fi +if [[ "${GENTOO_PYTHON_TARGETS}" == *"python3_5"* ]]; then + echo -e "-python_targets_python3_5\n-python_single_target_python3_5" >> /etc/portage/profile/use.stable.mask + echo 'dev-lang/python:3.5 ~amd64' >> /etc/portage/package.keywords/python + echo '~dev-python/setuptools-36.0.1 ~amd64' >> /etc/portage/package.keywords/python + [[ ! -e /usr/lib64/libpython3.5m.so ]] && USE="-build" emerge -1q --jobs=2 dev-lang/python:3.5 +fi +[[ "${GENTOO_PYTHON_TARGETS}" == *"python3_4"* ]] && [[ ! -e /usr/lib64/libpython3.4m.so ]] && USE="-build" emerge -1q --jobs=2 dev-lang/python:3.4 +[[ "${GENTOO_PYTHON_TARGETS}" == *"python2_7"* ]] && [[ ! -e /usr/lib64/libpython2.7.so ]] && USE="-build" emerge -1q --jobs=2 dev-lang/python:2.7 +# disable python in git if we have to, it only supports python-2.7 +if [[ "${GENTOO_PYTHON_TARGETS}" != *"python2_7"* ]]; then + echo 'dev-vcs/git -python' >> /etc/portage/package.use/git +fi +# make sure we have the new python for portage bevore we possibly remove python 2.7 +USE="-build" emerge -q --oneshot --jobs=2 --with-bdeps=y --update --newuse --deep sys-apps/portage dev-python/pyxattr +# set the active python version +eselect python set ${GENTOO_PYTHON_ACTIVE_VERSION} +# allow these uninstalls to fail as they may not be installed to begin with +set +e +if [[ "${GENTOO_PYTHON_TARGETS}" != *"python2_7"* ]]; then + emerge -C -q dev-lang/python:2.7 +fi +if [[ "${GENTOO_PYTHON_TARGETS}" != *"python3_4"* ]]; then + emerge -C -q dev-lang/python:3.4 +fi +if [[ "${GENTOO_PYTHON_TARGETS}" != *"python3_5"* ]]; then + emerge -C -q dev-lang/python:3.5 +fi +if [[ "${GENTOO_PYTHON_TARGETS}" != *"python3_6"* ]]; then + emerge -C -q dev-lang/python:3.6 +fi +set -e + +# make world consistant +USE="-build" emerge -q --complete-graph=y --jobs=2 --update --newuse --deep --with-bdeps=y @world +# rebuild packages that might need it +USE="-build" emerge -q --jobs=2 --usepkg=n @preserved-rebuild +# remove unneeded packages +USE="-build" emerge --verbose=n --depclean +# rebuild packages that might have somehow depended on the unneeded packages +USE="-build" emerge -q --jobs=2 --usepkg=n @preserved-rebuild + + +unfix_shm diff --git a/diskimage_builder/elements/openssh-server/post-install.d/80-enable-sshd-service b/diskimage_builder/elements/openssh-server/post-install.d/80-enable-sshd-service index ee59b3a41..29500faa1 100755 --- a/diskimage_builder/elements/openssh-server/post-install.d/80-enable-sshd-service +++ b/diskimage_builder/elements/openssh-server/post-install.d/80-enable-sshd-service @@ -19,8 +19,7 @@ case "$DIB_INIT_SYSTEM" in fi ;; openrc) - # let dib-init-system's postinstall handle enabling init scripts - exit 0 + rc-update add sshd default ;; sysv) # ssh is enabled by default, nothing to do