summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-03-27 10:42:13 +0200
committerKarel Kočí <cynerd@email.cz>2018-03-27 10:42:13 +0200
commit0dd840d496676f7ac0549db8bc25d3ba7ed121d5 (patch)
treeee32541db39f13d711517d83b72830d1640aad75
parent29984afc35fe81afd94ec92feb718aef5d0fa16c (diff)
downloadgentoo-personal-overlay-0dd840d496676f7ac0549db8bc25d3ba7ed121d5.tar.gz
gentoo-personal-overlay-0dd840d496676f7ac0549db8bc25d3ba7ed121d5.tar.bz2
gentoo-personal-overlay-0dd840d496676f7ac0549db8bc25d3ba7ed121d5.zip
Add gentoo-mount to personal-utils
-rwxr-xr-xsys-apps/personal-utils/files/gentoo-mount125
-rw-r--r--sys-apps/personal-utils/personal-utils-1.5-r1.ebuild (renamed from sys-apps/personal-utils/personal-utils-1.4-r1.ebuild)1
2 files changed, 126 insertions, 0 deletions
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.5-r1.ebuild
index 6c98922..0f40c22 100644
--- a/sys-apps/personal-utils/personal-utils-1.4-r1.ebuild
+++ b/sys-apps/personal-utils/personal-utils-1.5-r1.ebuild
@@ -11,4 +11,5 @@ KEYWORDS="amd64 x86"
src_install() {
exeinto /usr/sbin
doexe "${FILESDIR}/emergefix"
+ doexe "${FILESDIR}/gentoo-mount"
}