Created
August 12, 2014 19:35
-
-
Save MorbosVermin/5773745abfa17269c945 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[[ -e $HOME/colors.conf ]] && . $HOME/colors.conf | |
CWD=`pwd` | |
NAME=$1 | |
#DIALOG="${DIALOG=dialog} --clear" | |
tempfile=/tmp/sel-$$ | |
[[ -z "${NAME}" ]] && echo "Syntax: $0 <name> [<path to stage3 tarball>] [<path to portage tarball>]" && exit 1; | |
sudo ls > /dev/null | |
if [ ! -d "${NAME}" ]; then | |
echo -e ">> ${boldwhite}Setting up${clear} environment for '${NAME}'" | |
sudo mkdir -p ${NAME}/dev | |
sudo mkdir -p ${NAME}/proc | |
sudo mkdir -p ${NAME}/tmp | |
sudo mkdir -p ${NAME}/sys | |
fi | |
echo -en ">> ${boldwhite}Ensuring${clear} proper directory perms..." | |
sudo chmod 1777 ${NAME}/tmp | |
sudo chown root:root ${NAME}/dev ${NAME}/proc ${NAME}/tmp ${NAME}/sys | |
echo "done." | |
STAGE3_TARBALL= | |
PORTAGE_TARBALL= | |
for arg in $2 $3 $4 $5 $6 $7 $8 $9; do | |
if [ -z "${STAGE3_TARBALL}" ]; then | |
STAGE3_TARBALL="${arg}" | |
elif [ -z "${PORTAGE_TARBALL}" ]; then | |
PORTAGE_TARBALL="${arg}" | |
fi | |
done | |
if [ -z "${STAGE3_TARBALL}" ]; then | |
ARCH="x86" | |
echo -en "Architecture? [${boldwhite}x86${clear}, amd64] " | |
read -e A | |
[[ ! -z "${A}" ]] && ARCH="${A}" | |
PROFILE="default" | |
echo -en "Profile? [${boldwhite}default${clear}, hardened] " | |
read -e P | |
[[ ! -z "${P}" ]] && PROFILE="${P}" | |
FILE="latest-stage3.txt" | |
[[ "${PROFILE}" == "hardened" ]] && FILE="latest-stage3-i686-hardened.txt" | |
FILE_URL="`wget -q -O - ${STAGE3_URL}/${FILE} | tail -1`" | |
FILENAME="`basename ${FILE_URL}`" | |
STAGE3_URL="http://distfiles.gentoo.org/releases/${ARCH}/autobuilds" | |
echo -e ">> ${boldwhite}Downloading${clear} latest stage3 tarball; please wait..." | |
wget --progress=bar:force -O /tmp/${FILENAME} "${STAGE3_URL}/${FILE_URL}" | |
if [ $? -eq 0 ]; then | |
STAGE3_TARBALL=/tmp/${FILENAME} | |
else | |
exit 1; | |
fi | |
fi | |
echo -e ">> ${boldwhite}Extracting${clear} stage3 to image; please wait..." | |
cd ${NAME} && pv "${STAGE3_TARBALL}" | sudo tar jpxf - && cd ../ | |
if [ -z "${PORTAGE_TARBALL}" ]; then | |
PORTAGE_URL="http://distfiles.gentoo.org/releases/snapshots/current/portage-latest.tar.bz2" | |
echo -e ">> ${boldwhite}Downloading${clear} latest portage snapshot; please wait..." | |
wget --progress=bar:force -O /tmp/portage-latest.tar.bz2 "${PORTAGE_URL}" | |
if [ $? -eq 0 ]; then | |
PORTAGE_TARBALL=/tmp/portage-latest.tar.bz2 | |
else | |
exit 1; | |
fi | |
fi | |
echo -e ">> ${boldwhite}Extracting${clear} portage-latest to image; please wait..." | |
cd ${NAME}/usr && pv "${PORTAGE_TARBALL}" | sudo tar jpxf - && \ | |
cd ../../ && rm -f /tmp/portage-latest* | |
echo -e ">> ${boldwhite}Fixing${clear} localtime for image; please wait..." | |
cd ${NAME}/etc | |
sudo ln -sf ../usr/share/zoneinfo/America/New_York localtime | |
cd ${CWD} | |
echo -e ">> ${boldwhite}Creating banner${clear} for ${NAME}..." | |
echo > ${NAME}.banner | |
figlet "${NAME}" >> ${NAME}.banner | |
echo >> ${NAME}.banner | |
echo "Hostname: " >> ${NAME}.banner | |
echo "Address: " >> ${NAME}.banner | |
echo "Arch: ${ARCH}" >> ${NAME}.banner | |
echo "Profile: ${PROFILE}" >> ${NAME}.banner | |
echo "CodeName: " >> ${NAME}.banner | |
echo "Kernel: " >> ${NAME}.banner | |
echo "LSB: " >> ${NAME}.banner | |
echo "Built: %DATE%" >> ${NAME}.banner | |
echo -en "\n\n" >> ${NAME}.banner | |
echo -e "* Note: Please use ${boldwhite}${NAME}.banner${clear} for information on this new build. Leave the %DATE% though for autobuilds!" | |
echo -e "${boldwhite}" | |
echo "Setup complete. Created new build: ${NAME}" | |
echo "Note: Use ${NAME}.banner for information on this new build. Leave the %DATE% though for autobuilds!" | |
echo -e "${clear}" | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment