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.

434 lines
10 KiB

5 years ago
#!/usr/bin/env sh
## Helpers #######################################
Logger() {
#cat >> /gi_log
printf "$Log\n"
unset Log
}
Clean_Packages() {
Log="Removing packages that are no longer needed..." && Logger
5 years ago
emerge -uDN @world && \
emerge -av --depclean && \
emerge --update --changed-use --deep @world
}
Clean_Source() {
Log="Removing temporary files..." && Logger
5 years ago
rm -rf /usr/portage/packages/* \
/usr/portage/distfiles/* \
/var/tmp/portage/* \
/stage3*.tar.bz2
}
Detect_Cores() {
Log="Detecting total number of cores to compile with..." && Logger
5 years ago
export CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
}
Setup_Ssh() {
Log="Setting up SSH..." && Logger
5 years ago
rc-update add sshd default
}
## Boot ##########################################
Boot_Config() {
Log="Editing system defaults..." && Logger
5 years ago
nano /etc/rc.conf
nano /etc/conf.d/keymaps
nano /etc/conf.d/hwclock
}
Boot_Grub() {
Log="Installing Grub..." && Logger
5 years ago
read -ep "Where to install Grub: " Grub_Target && \
emerge --ask --verbose sys-boot/grub:2 && \
grub-install $Grub_Target && \
grub-mkconfig -o /boot/grub/grub.cfg
5 years ago
}
## Disks #########################################
Disk_Fstab() {
Log="Editing '/etc/fstab'..." && Logger
5 years ago
echo "/swapfile none swap sw 0 0" >> /etc/fstab && \
nano /etc/fstab
5 years ago
}
Disk_Setup() {
Log="Please setup partitions and mount them before proceeding!" && Logger
5 years ago
read -ep "Proceed with installation? [Y/N]: " Proceed && \
if echo $Proceed | grep -iq "^n" ; then
exit
fi
5 years ago
}
## Environment ###################################
Env_Chroot() {
Log="Chrooting into the environment..." && Logger
5 years ago
cd /mnt/gentoo && \
chroot /mnt/gentoo /bin/bash
}
Env_Reload() {
Log="Reloading the environment..." && Logger
5 years ago
source /etc/profile && \
export PS1="(chroot) $PS1"
5 years ago
}
Env_Update() {
Log="Updating the environment..." && Logger
5 years ago
env-update && \
Env_Reload
5 years ago
}
## Host ##########################################
HostsFile() {
Log="Updating hosts file..." && Logger
5 years ago
nano /etc/hosts
}
HostName() {
Log="Setting hostname..." && Logger
5 years ago
read -ep "Hostname: " Target_Hostname && \
echo hostname="$Target_Hostname" > /etc/conf.d/hostname && \
5 years ago
nano /etc/conf.d/hostname
}
## Kernel ########################################
Kernel_Install() {
Log="Downloading, building, and installing kernel..." && Logger
5 years ago
emerge --ask sys-kernel/gentoo-sources \
5 years ago
sys-kernel/linux-firmware \
sys-apps/pciutils \
sys-kernel/genkernel &&
cd /usr/src/linux && \
make -j${CPU_CORES} defconfig && \
make -j${CPU_CORES} menuconfig && \
5 years ago
make -j${CPU_CORES} && \
make -j${CPU_CORES} modules_install && \
make -j${CPU_CORES} install && \
genkernel --install initramfs
}
## Locale ########################################
Locales() {
Log="Setting desired locales..." && Logger
5 years ago
nano /etc/locale.gen && \
locale-gen && locale -a && \
eselect locale list && \
read -ep "Target locale: " Target_Locale && \
eselect locale set ${Target_Locale}
}
## Networking ####################################
Network_Wired() {
Log="Configuring wired networking..." && Logger
5 years ago
USE="ipv6" emerge --ask --noreplace net-misc/netifrc && \
emerge --ask net-misc/dhcpcd
5 years ago
}
Network_Wireless() {
Log="Configuring wireless networking..." && Logger
5 years ago
USE="dbus" emerge --ask net-wireless/wpa_supplicant && \
USE="ethernet openvpn wifi" emerge --ask net-misc/connman
5 years ago
}
## Portage #######################################
Portage_MakeConf() {
Log="Downloading portage 'make.conf'..." && Logger
5 years ago
echo "Available GPU drivers: AMD, Intel, Nouveau, Virt (vbox & vmware)"
read -ep "Which GPU's do you have?: " Target_GPU && \
case $Target_GPU in
amd|AMD)
export Active_GPU="amdgpu radeonsi radeon"
;;
intel|intel)
export Active_GPU="intel"
;;
nouveau|Nouveau)
export Active_GPU="nouveau"
;;
virt|Virt)
export Active_GPU="virtualbox vmware"
;;
*) echo "You must select one of the available options!" ;;
esac
5 years ago
echo '# /etc/portage/make.conf
CHOST="x86_64-pc-linux-gnu"
PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"
MAKEOPTS="-j${CPU_CORES}"
EMERGE_DEFAULT_OPTS="--jobs=2"
CFLAGS="-march=native -O3 -pipe"
CXXFLAGS="${CFLAGS}"
CPU_FLAGS_X86="mmx mmxext sse sse2 sse3"
INPUT_DEVICES="libinput"
VIDEO_CARDS="$Active_GPU"
5 years ago
USE_Allow="bindist deblob minimal"
USE_Block="-multilib -doc -systemd -pulseaudio -avahi -llvm"
5 years ago
USE="${USE_Block} ${USE_Allow}"' \
> /mnt/gentoo/etc/portage/make.conf
}
Portage_Mirrors() {
Log="Setting up portage mirrors..." && Logger
5 years ago
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf && \
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/
}
Portage_Sync() {
Log="Syncing emerge and setting profile..." && Logger
5 years ago
emerge-webrsync && \
eselect profile list && \
read -ep "Which profile?: " Target_Profile && \
eselect profile set $Target_Profile && \
emerge --ask --update --deep --newuse @world
}
## Stage #########################################
Stage_Download() {
Log="Downloading and extracting Stage3 release..." && Logger
5 years ago
S3_ARCH="amd64"
S3_DATE="20170727"
5 years ago
cd /mnt/gentoo
wget http://distfiles.gentoo.org/releases/${S3_ARCH}/autobuilds/${S3_DATE}/stage3-${S3_ARCH}-nomultilib-${S3_DATE}.tar.bz2 && \
5 years ago
tar xvjpf stage3-*.tar.bz2 --xattrs --numeric-owner
}
Stage_Mounts() {
Log="Mounting hardware..." && Logger
5 years ago
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
}
Stage_Swap() {
Log="Setting up temporary swapfile..." && Logger
5 years ago
SwapFile="/mnt/gentoo/swapfile"
fallocate -l 2048M $SwapFile && \
mkswap $SwapFile && \
chmod 0600 $SwapFile && \
swapon $SwapFile
}
## Time ##########################################
Time_Date() {
Log="Setting current time via 'date'..." && Logger
5 years ago
Ye=""; Mo=""; Da=""; Ho=""; Mi=""; Se=""
date ${Ye}${Mo}${Da}${Ho}${Mi}${Se}
5 years ago
}
Time_Ntpd() {
Log="Setting current time via 'ntpd'..." && Logger
5 years ago
ntpd -q -g
}
Time_Zone() {
Log="Setting timezone..." && Logger
5 years ago
ls /usr/share/zoneinfo && \
read -ep "Target region: " Target_Region && \
ls /usr/share/zoneinfo/${Target_Region} && \
read -ep "Target city: " Target_City && \
TimeZone=${Target_Region}"/"${Target_City} && \
echo "${TimeZone}" > /etc/timezone && \
emerge --config sys-libs/timezone-data
}
## User ##########################################
User_Make() {
Log="Creating user account..." && Logger
5 years ago
read -ep "Setup a standard user? [Y/N]: " Proceed
if echo $Proceed | grep -iq "^y"; then
read -ep "Username: " Target_User && \
useradd -m -G wheel $Target_User && \
5 years ago
passwd $Target_User
else
exit
fi
}
User_Root() {
Log="Setting root password..." && Logger
5 years ago
passwd
}
## Utilities #####################################
Utils_Base() {
if grep -Rqi 'intel' /proc/cpuinfo; then
emerge --ask intel-microcode
fi
}
5 years ago
Utils_Desktop() {
Log="Installing desktop utilities..." && Logger
5 years ago
USE="-minimal" emerge --ask --verbose x11-base/xorg-drivers && \
emerge --ask x11-misc/xdotool x11-misc/wmctrl && \
Env_Update && \
USE="opengl vaapi vdpau" emerge --ask media-video/mpv && \
USE="X" emerge --ask app-editors/vim && \
MAKEOPTS="-j1" emerge --ask dev-util/cmake && \
USE="gtk3 hangouts proprietary-codecs widevine" emerge --ask www-client/chromium && \
USE="ppapi" emerge --ask www-plugins/adobe-flash && \
emerge --ask \
media-gfx/scrot \
media-sound/cmus \
media-video/ffmpeg \
net-misc/youtube-dl \
sys-firmware/alsa-firmware \
media-sound/alsa-utils \
app-misc/ranger \
app-misc/tmux \
dev-vcs/git \
net-misc/curl \
www-client/elinks \
x11-terms/st \
x11-wm/i3 \
x11-misc/dmenu \
x11-misc/i3lock \
x11-misc/i3status \
kde-frameworks/breeze-icons \
kde-plasma/breeze \
kde-plasma/breeze-gtk
5 years ago
}
Utils_Laptop() {
Log="Installing laptop utilities..." && Logger
5 years ago
USE="acpi bluetooth" emerge --ask app-laptop/laptop-mode-tools && \
rc-update add laptop_mode default
}
Utils_Server() {
Log="Installing server utilities..." && Logger
5 years ago
}
## Execution #####################################
case $1 in
init|-i)
Disk_Setup
Time_Ntpd
Stage_Download
Stage_Mounts
Stage_Swap
Portage_MakeConf
Portage_Mirrors
5 years ago
Env_Chroot
;;
base|-b)
Env_Reload
Detect_Cores
Portage_Sync
Time_Zone
Locales
Env_Update
Kernel_Install
Disk_Fstab
HostName
Network_Wired
HostsFile
User_Root
Boot_Config
Boot_Grub
Utils_base
5 years ago
User_Make
;;
desktop|-d)
5 years ago
Utils_Desktop
;;
laptop|-l)
Network_Wireless
5 years ago
Utils_Laptop
;;
server|-s)
Utils_Server
;;
clean|-c)
Clean_Packages
Clean_Source
;;
*)
Log="You entered an invalid option.\n"
Log=${Log}"Available options: init (-i), base (-b), "
Log=${Log}"desktop (-d), laptop(-l), server (-s), clean (-c)"
Logger
;;
esac