149 lines
3.9 KiB
Bash
Executable File
149 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
#Setting up color codes
|
|
SCRIPT_NAME=$0
|
|
Black='\033[0;30m'
|
|
Red='\033[0;31m'
|
|
Green='\033[0;32m'
|
|
Orange='\033[0;33m'
|
|
Blue='\033[0;34m'
|
|
Purple='\033[0;35m'
|
|
Cyan='\033[0;36m'
|
|
Light_Gray='\033[0;37m'
|
|
Dark_Gray='\033[1;30m'
|
|
Light_Red='\033[1;31m'
|
|
Light_Green='\033[1;32m'
|
|
Yellow='\033[1;33m'
|
|
Light_Blue='\033[1;34m'
|
|
Light_Purple='\033[1;35m'
|
|
Light_Cyan='\033[1;36m'
|
|
White='\033[1;37m'
|
|
NC='\033[0m'
|
|
edebug () {
|
|
einfo $@
|
|
}
|
|
einfo () {
|
|
echo -e " ${Green}*${NC} ${@:1}${NC}"
|
|
}
|
|
ewarn () {
|
|
echo -e " ${Yellow}*${NC} ${@:1}${NC}"
|
|
}
|
|
eerror () {
|
|
echo -e " ${Red}*${Light_Red} ${@:1}${NC}"
|
|
}
|
|
die () {
|
|
echo
|
|
eerror die called, ending.
|
|
exit 1
|
|
}
|
|
end () {
|
|
exit 0
|
|
}
|
|
show_help () {
|
|
echo -e "USAGE : ${Light_Green}${SCRIPT_NAME}${NC} ${Yellow}[options]${NC} ${Light_Red}</path/to/target>${NC} "
|
|
echo -e
|
|
echo -e "${Yellow}OPTIONS :${NC}"
|
|
echo -e " -h --help Show this help."
|
|
echo -e " -u --userland,--no-root Allow the script to run in userland."
|
|
echo -e " -p --profile Use the specified profile."
|
|
echo -e " This value will be used in a eselect profile set command."
|
|
echo -e "${Light_Red}TARGET :${NC}"
|
|
echo -e " </path/to/target> Path to the future chroot installation,"
|
|
echo -e " can be . to install in the current directory"
|
|
}
|
|
|
|
getopt --test
|
|
if [ $? != 4 ]; then
|
|
eerror "Your installation doesn't support enhanced getopt."
|
|
die
|
|
fi
|
|
|
|
#Setting up the getopt parser
|
|
echo -e ${Light_Blue} -- Welcome to Gentoo Chroot Helper -- ${NC}
|
|
echo
|
|
|
|
SHORT="hup:"
|
|
LONG="help,userland,no-root,profile:"
|
|
|
|
OPTS=$(getopt --options $SHORT --long $LONG --name "$0" -- "$@")
|
|
if [ $? != 0 ]
|
|
then eerror Failed to parse options
|
|
die
|
|
fi
|
|
eval set -- "$OPTS"
|
|
#Setting default values
|
|
NO_ROOT=false
|
|
TARGET=false
|
|
PROFILE="12"
|
|
#Extracting arguments
|
|
while true
|
|
do case "$1" in
|
|
-h | --help )
|
|
show_help
|
|
end
|
|
shift
|
|
;;
|
|
-u | --userland | --no-root )
|
|
NO_ROOT=true
|
|
shift
|
|
;;
|
|
-p | --profile )
|
|
PROFILE="$2"
|
|
shift 2
|
|
;;
|
|
-- )
|
|
shift
|
|
;;
|
|
*)
|
|
TARGET=$1
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
if [ -z ${TARGET} ]
|
|
then eerror Please specify a target.
|
|
ewarn Run ${SCRIPT_NAME} --help for more info.
|
|
die
|
|
fi
|
|
if [ ${NO_ROOT} != true ]
|
|
then
|
|
if [ "$EUID" -ne 0 ]
|
|
then eerror This script should be ran as root.
|
|
ewarn If you want to run the script anyway use the --no-root argument.
|
|
ewarn Warning : Userland chroot generation has not been tested yet.
|
|
die
|
|
fi
|
|
fi
|
|
if [ ${NO_ROOT} == true ]
|
|
then ewarn Warning : NO_ROOT is experimental.
|
|
fi
|
|
|
|
PROFILE_CHECK=$(eselect profile list |grep ${PROFILE})
|
|
if [ -z "${PROFILE_CHECK}" ]
|
|
then eerror Invalid profile specified : ${PROFILE}
|
|
die
|
|
fi
|
|
|
|
PORTAGE_RSYNC_OPTS=$(emerge --info|grep PORTAGE_RSYNC_OPTS)
|
|
PORTAGE_RSYNC_OPTS=${PORTAGE_RSYNC_OPTS:20}
|
|
PORTAGE_RSYNC_OPTS=${PORTAGE_RSYNC_OPTS%\"*}
|
|
|
|
einfo Installing @system in ${Red}${TARGET}${NC}
|
|
einfo Profile selected : ${Light_Green}${PROFILE_CHECK}${NC}
|
|
echo
|
|
|
|
mkdir -p ${TARGET}/etc/portage || (eerror Could not create the directory; die)
|
|
cd ${TARGET} || die
|
|
TARGET=$(pwd)
|
|
edebug Entered ${Light_Blue}${TARGET}${NC}
|
|
|
|
mkdir -p ${TARGET}/usr/portage/
|
|
|
|
export ROOT=${TARGET}
|
|
export PORTAGE_CONFIGROOT=${TARGET}
|
|
export PORTDIR=${TARGET}/usr/portage
|
|
einfo Syncing /usr/portage and ${TARGET} Gentoo Repositories.
|
|
rsync ${PORTAGE_RSYNC_OPTS} /usr/portage/ ${PORTDIR} || (eerror Could not rsync .; die)
|
|
ln -s ../../usr/portage/profiles/default/linux/amd64/17.0 ${TARGET}/etc/portage/make.profile
|
|
eselect profile set ${PROFILE} || (eerror Could not set profile.; die)
|
|
FEATURES="buildpkg" emerge -k -j8 @system || (eerror Could not emerge @system ; die)
|