Gentoo installation script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
7.8 KiB

#!/usr/bin/env sh
## Commands
Emerge="emerge -q"
Read="read -ep"
## Gein Defaults
Gein_Extras="enable"
Grub_Target="/dev/sda"
Hostname="gein"
Locale="en_US.UTF-8 UTF-8"
Swap_Size="4G"
Time_Zone="America/New_York"
Video_Cards="intel"
## Gentoo Defaults
#Base_Url="https://raw.githubusercontent.com/jcmdln/gein/master"
#Kernel_Config="$Base_Url/usr/src/linux/4.12-config"
#Make_Conf="$Base_Url/etc/portage/make.conf"
#Package_Env="$Base_Url/etc/portage/package.env"
#Package_Use="$Base_Url/etc/portage/package.use"
Stage3_Arch="amd64"
Stage3_Date="20171005"
Stage3_Url="http://distfiles.gentoo.org/releases"
Bootstrap() {
## Confirm the user has setup their disks
echo "Please ensure that you have performed the following: "
echo " - Edited the environment variables at the top of this script."
echo " - Partitioned and mounted your disk(s)."
$Read "Proceed with installation? [Y/N]: " Proceed && \
if echo $Proceed | grep -iq "^n"; then exit; fi &&
## Set time via ntpd
ntpd -q -g &&
## Download and extract stage3 tarball
cd /mnt/gentoo && \
wget ${Stage3_Url}/${Stage3_Arch}/autobuilds/${Stage3_Date}/stage3-${Stage3_Arch}-${Stage3_Date}.tar.bz2 && \
tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner &&
## Mount hardware devices
mount -t proc /proc /mnt/gentoo/proc && \
mount --rbind /sys /mnt/gentoo/sys && \
mount --make-rslave /mnt/gentoo/sys && \
mount --rbind /dev /mnt/gentoo/dev && \
mount --make-rslave /mnt/gentoo/dev &&
## Setup '/swapfile'
Swap_File="/mnt/gentoo/swapfile"
if [ ! -e $Swap_File ]; then
fallocate -l $Swap_Size $Swap_File && \
mkswap $Swap_File && \
chmod 0600 $Swap_File && \
swapon $Swap_File
fi &&
## Configure Portage
if [ ! -z $Make_Conf ]; then
wget $Make_Conf -O /mnt/gentoo/etc/portage/make.conf
fi && \
if [ ! -z $Package_Use ]; then
rm -rf /mnt/gentoo/etc/portage/package.use && \
wget $Package_Use -O /mnt/gentoo/etc/portage/package.use
fi && \
if [ ! -z $Package_Env ]; then
wget $Package_Env -O /mnt/gentoo/etc/portage/package.env
fi &&
## Setup Portage mirrors
mkdir -vp /mnt/gentoo/etc/portage/repos.conf && \
cp -v /mnt/gentoo/usr/share/portage/config/repos.conf \
/mnt/gentoo/etc/portage/repos.conf/gentoo.conf && \
cp -vL /etc/resolv.conf /mnt/gentoo/etc/ &&
## Add 'gein-extras' script
if [ ! -z $Gein_Extras ]; then
mkdir -vp /mnt/gentoo/usr/local/sbin && \
wget $Base_URL/usr/local/sbin/gein-extras \
-O /mnt/gentoo/usr/local/sbin/gein-extras && \
chmod +x /mnt/gentoo/usr/local/sbin/gein-extras
fi &&
## Chroot into '/mnt/gentoo'
cd /mnt/gentoo && \
echo "chroot'ing into /mnt/gentoo..."
chroot /mnt/gentoo /bin/bash
}
Minimal() {
## Adjust make.conf to store the specified video card and # of CPU cores
sed -i "s/Video_Cards/${Video_Cards}/g;
s/Make_Opts/-j$(grep -c ^processor /proc/cpuinfo)/g" \
/etc/portage/make.conf &&
## Reload profile and update PS1
source /etc/profile && \
export PS1="(chroot) $PS1"
## Sync Portage and select profile
emerge-webrsync && \
eselect profile list && \
$Read "Which profile? [Default is 1]: " Target_Profile && \
[ -z $Target_Profile ] && Target_Profile="1"
eselect profile set $Target_Profile && \
$Emerge --update --deep --newuse @world &&
## Set desired timezone
echo "${Time_Zone}" > /etc/timezone && \
emerge --config sys-libs/timezone-data &&
## Set desired locales
echo "${Locale}" > /etc/locale.gen && \
locale-gen && \
locale -a && \
eselect locale list && \
$Read "Target locale: " Target_Locale && \
eselect locale set ${Target_Locale} &&
## Update environment
env-update && \
source /etc/profile && \
export PS1="(chroot) $PS1"
## Emerge/install Linux kernel and modules
$Emerge sys-kernel/gentoo-sources \
sys-kernel/linux-firmware \
sys-apps/pciutils \
sys-kernel/genkernel && \
if grep -Rqi 'intel' /proc/cpuinfo; then
$Emerge intel-microcode
fi && \
cd /usr/src/linux && \
if [ -z $Kernel_Config ]; then
make defconfig && \
make menuconfig
else
wget $Kernel_config -O /usr/src/linux/.config
fi && \
make && \
make modules_install && \
make install && \
genkernel --install initramfs &&
## Configure '/etc/fstab/'
echo "/swapfile none swap sw 0 0" >> /etc/fstab && \
nano /etc/fstab &&
## Install neworking packages &
$Emerge --noreplace net-misc/netifrc && \
$Emerge net-misc/dhcpcd &&
## Set desired hostname and update '/etc/hosts'
echo hostname="${Hostname}" > /etc/conf.d/hostname &&
## Configure and install Grub
$Emerge sys-boot/grub:2 && \
grub-install $Grub_Target && \
grub-mkconfig -o /boot/grub/grub.cfg &&
## Set root password
passwd
}
Desktop() {
## Install Desktop drivers and packages
$Emerge dev-util/cmake \
x11-base/xorg-drivers \
x11-misc/wmctrl \
x11-misc/xdotool && \
env-update && \
source /etc/profile && \
export PS1="(chroot) $PS1" && \
$Emerge app-admin/sudo \
app-editors/vim \
app-misc/ranger \
app-misc/tmux \
media-fonts/dejavu \
x11-apps/xrandr \
x11-misc/dmenu \
x11-misc/i3lock \
x11-misc/i3status \
x11-misc/xclip \
x11-terms/rxvt-unicode \
x11-wm/i3
}
Laptop() {
$Emerge app-laptop/laptop-mode-tools \
net-misc/connman \
net-wireless/wpa_supplicant \
x11-apps/xbacklight && \
rc-update add laptop_mode default
}
Media() {
$Emerge app-shells/zsh \
app-shells/zsh-completions \
media-gfx/feh \
media-gfx/scrot \
media-libs/alsa-lib \
media-sound/alsa-utils \
media-video/mpv \
net-misc/youtube-dl \
www-client/chromium
}
Office() {
$Emerge app-office/libreoffice
}
Steam() {
$Emerge layman && \
layman -a steam-overlay && \
$Emerge steam-meta \
steam-launcher-meta
}
Cleanup() {
## Install eclean
$Emerge app-portage/gentoolkit \
app-admin/eclean-kernel &&
## Update @world, remove unused packages, and clean
$Emerge -uDN @world && \
$Emerge --depclean && \
$Emerge --update --changed-use --deep @world && \
eclean packages && \
eclean-dist --deep --fetch-restricted &&
## Remove junk created during installation
rm -rf /stage3*.tar.bz2
}
### Execution ####################################
shopt -s nocasematch && \
case $1 in
bootstrap | -b) Bootstrap;;
cleanup | -c) Cleanup;;
minimal | -m) Minimal;;
desktop | -d) Desktop;;
laptop | -l) Laptop;;
media | -M) Media;;
steam | -s) Steam;;
bloat | -B) Minimal && Desktop && Laptop && \
Media && Office && Steam && \
Cleanup ;;
help | --help | -h)
echo "Try reading the script along with the Gentoo documentation:"
echo "https://www.gentoo.org/support/documentation/"
;;
*) printf "gein - GEntoo INstaller\n\n"
echo " -h help Suggests to read the script and Gentoo documentation"
printf "\nRequired first step:\n"
echo " -b bootstrap Bootstrap the stage3 tarball"
printf "\nPost-bootstrap options:\n"
echo " -m minimal Only install required gentoo packages"
echo " -d desktop i3-based desktop"
echo " -l laptop install laptop, wifi, and backlight packages"
echo " -M media Install alsa, mpv, chromium, etc"
echo " -s steam Install Steam"
echo " -b bloat Install everything mentioned above"
;;
esac && shopt -u nocasematch