From 0dd840d496676f7ac0549db8bc25d3ba7ed121d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 27 Mar 2018 10:42:13 +0200 Subject: Add gentoo-mount to personal-utils --- sys-apps/personal-utils/files/gentoo-mount | 125 +++++++++++++++++++++ .../personal-utils/personal-utils-1.4-r1.ebuild | 14 --- .../personal-utils/personal-utils-1.5-r1.ebuild | 15 +++ 3 files changed, 140 insertions(+), 14 deletions(-) create mode 100755 sys-apps/personal-utils/files/gentoo-mount delete mode 100644 sys-apps/personal-utils/personal-utils-1.4-r1.ebuild create mode 100644 sys-apps/personal-utils/personal-utils-1.5-r1.ebuild (limited to 'sys-apps') diff --git a/sys-apps/personal-utils/files/gentoo-mount b/sys-apps/personal-utils/files/gentoo-mount new file mode 100755 index 0000000..f3cd674 --- /dev/null +++ b/sys-apps/personal-utils/files/gentoo-mount @@ -0,0 +1,125 @@ +#!/bin/sh +set -e + +DIR= +DEV_ROOT= + +while [ $# -gt 0 ]; do + case "$1" in + -h|--help) + echo "Usage: gentoo-mount [OPTION]... DIR" + echo "Simple script for mounting chrootable gentoo system to given" + echo "directory." + echo + echo "Options:" + echo " -h, --help" + echo " Print this help text." + echo " -s, --sys-only" + echo " Mount only system paths to already given prepared" + echo " directory." + exit 0 + ;; + *) + if [ -z "$DIR" ]; then + DIR="$1" + else + echo "Unknown argument: $1" >&2 + exit 1 + fi + ;; + esac + shift +done + +if [ $(id -u) != 0 ]; then + echo "This script has to be run only as root." >&2 + exit 1 +fi + + +# Interactive mount +# Usage: imount DEVICE PATH OPTIONS NAME +# DEVICE: device to mount. If not provided (empty) then ask user. +# PATH: path where mount will be mounted. +# OPTIONS: mount options (mount -o) +# NAME: optional name to be used for mapper +imount() { + if [ -n "$1" ]; then + return mount -o "$3" "$1" "$2" + fi + + echo "\e[1;32mPlease choose device\e[0m" + lsblk -o NAME,LABEL,SIZE,FSTYPE,MOUNTPOINT + while true; do + echo -n "Device: /dev/" + read DEVICE + if [ ! -b "/dev/$DEVICE" ]; then + echo "No such device: /dev/$DEVICE" >&2 + else + break + fi + done + + # Check if it's Luks partition and open it if it's + if cryptsetup isLuks "/dev/$DEVICE"; then + local CSNAME="$4" + while [ -e "/dev/mapper/$CSNAME" ]; do + CSNAME="${CSNAME}2" + done + echo "\e[1;32mOpening encrypted filesystem\e[0m" + cryptsetup open "/dev/$DEVICE" "$CSNAME" + DEVICE="mapper/$CSNAME" + fi + + local OPTIONS="$3" + # Specially handle btrfs + if [ -n "$(blkid -t TYPE=btrfs "/dev/$DEVICE")" ]; then + if [ -n "$OPTIONS" ]; then + OPTIONS="$OPTIONS,compress=lzo" + else + OPTIONS="compress=lzo" + fi + + local TMP="$(mktemp -d)" + mount "/dev/$DEVICE" "$TMP" + while true; do + echo "\e[1;32mPlease choose subvolume\e[0m" + btrfs subvolume list -t "$TMP" + # TODO default value? Probably same as name? + echo -n "Subvolume: " + read SUBVOL + if btrfs subvolume list "$TMP" | grep -q "$SUBVOL"; then + OPTIONS="$OPTIONS,subvol=$SUBVOL" + break + fi + done + umount "$TMP" + rmdir "$TMP" + fi + + # And at last mount + mount -o "$OPTIONS" "/dev/$DEVICE" "$2" +} + +# Mount root filesystem ########################################################## +echo "\e[1;34mMount root filesystem\e[0m" +imount "$DEV_ROOT" "$DIR" "" root + + +# Mount system paths ############################################################# +echo "\e[1;34mMount system paths\e[0m" +mount -t proc /proc "$DIR/proc" +mount --rbind /dev "$DIR/dev" +mount --rbind /sys "$DIR/sys" + +# Copy current resolv.conf ####################################################### +echo "\e[1;34mCopy system resolv.conf\e[0m" +cp /etc/resolv.conf "$DIR/etc/resolv.conf" + +# Mount boot partition ########################################################### +echo "\e[1;34mMount boot partition\e[0m" +imount "$DEV_BOOT" "$DIR/boot" + +# Mount home partition ########################################################### +echo "\e[1;34mMount home partition\e[0m" +imount "$DEV_HOME" "$DIR/home" diff --git a/sys-apps/personal-utils/personal-utils-1.4-r1.ebuild b/sys-apps/personal-utils/personal-utils-1.4-r1.ebuild deleted file mode 100644 index 6c98922..0000000 --- a/sys-apps/personal-utils/personal-utils-1.4-r1.ebuild +++ /dev/null @@ -1,14 +0,0 @@ -EAPI=6 - -DESCRIPTION="My simple personal system utilities" -HOMEPAGE="http://git.cynerd.cz/gentoo-personal-overlay/" -S="${WORKDIR}" - -LICENSE="GPL-3.0+" -SLOT="0" -KEYWORDS="amd64 x86" - -src_install() { - exeinto /usr/sbin - doexe "${FILESDIR}/emergefix" -} diff --git a/sys-apps/personal-utils/personal-utils-1.5-r1.ebuild b/sys-apps/personal-utils/personal-utils-1.5-r1.ebuild new file mode 100644 index 0000000..0f40c22 --- /dev/null +++ b/sys-apps/personal-utils/personal-utils-1.5-r1.ebuild @@ -0,0 +1,15 @@ +EAPI=6 + +DESCRIPTION="My simple personal system utilities" +HOMEPAGE="http://git.cynerd.cz/gentoo-personal-overlay/" +S="${WORKDIR}" + +LICENSE="GPL-3.0+" +SLOT="0" +KEYWORDS="amd64 x86" + +src_install() { + exeinto /usr/sbin + doexe "${FILESDIR}/emergefix" + doexe "${FILESDIR}/gentoo-mount" +} -- cgit v1.2.3