Browse Source

Update variables; improve formatting

* Improve variable naming conventions
* Make all variables lowercase, and NOT camelcase
* Unset variables immediately after they are no longer needed
* Remove most comments and replace with placeholders
* Improve or deprecate some behaviors (ie $VideoCards)

One additional item that I've started work on is using variables to
store the state of whether a "pass" (ie each function) has completed in
order to better control execution, specifically when prior actions are
required. This has not been completed yet though the placeholders have
been added as part of this commit.
master
jcmdln 1 year ago
parent
commit
ad5370bcf5
1 changed files with 137 additions and 175 deletions
  1. 137
    175
      gein.sh

+ 137
- 175
gein.sh View File

@@ -5,135 +5,79 @@
##


# $Source is the protocol and domain that will be the top-level reference
# when retrieving configuration files.
# This section describes variables that will define the resulting
# system. '$Hostname', '$Locale', and '$TimeZone' are mostly obvious in
# terms of their use, though '$VideoCards' is used as the value of
# 'VIDEO_CARDS' within '/etc/portage/make.conf'.

Source="https://gein.io"
cpu_cores="$(grep -c ^processor /proc/cpuinfo)"
hostname="gein"
locale="en_US.UTF-8 UTF-8"
timezone="America/New_York"
video_cards="false"


# This section defines some command aliases that will be used later on,
# and is primarily used as a mechanism to inhibit or control output in a
# way that can be easily updated or changed if needed.
# This section contains aliases for commands which are used throughout
# the script. By default commands have their output and prompts
# suppressed, though should you want to review or debug this script you
# may want to adjust these as desired.

Emerge="emerge -v --quiet-build"
EmergeSync="emerge -q --sync"
Make="make -s -j$CPUCores"
Mkdir="mkdir -p"
Rm="rm"
Wget="wget -q"
curl="curl -sSf"
emerge="emerge -v --quiet-build"
emerge_sync="emerge -q --sync"
make="make -s -j$cpu_cores"
mkdir="mkdir -p"
rm="rm"
wget="wget -q"


# The following variables will be called later on to perform the
# following:
# This section describes two variables: '$AutoKernel'
#
# * $Hostname is used to set the hostname.
# * $Locale is your language and encoding of choice
# * $TimeZone is the target within '/usr/share/zoneinfo' of your region

Hostname="gein"
Locale="en_US.UTF-8 UTF-8"
TimeZone="America/New_York"
kernel_autobuild="true"
#kernel_config=""


# The 'PartitionBoot' variable *MUST* be set to proceed with the
# installation. The example uses '/dev/sda' which will later install
# GRUB to the MBR rather than a partition. Change this to your desired
# '/boot' partition.

#PartitionBoot="/dev/sda1"
#PartitionUefi="/dev/sda2"
#PartitionRoot="/dev/sda3"
#PartitionHome="/dev/sda4"
#PartitionSwap="/dev/sda5"


# The 'VideoCards' variable *MUST* be set to proceed with the
# installation. Several examples have been provided based on brand or
# target, though if you have any specific needs then set this variable
# accordingly. If you don't need any video support, then set
# 'VideoCards' to false like the last example.
#
#

#VideoCards="i915 i965 intel"
#VideoCards="amdgpu radeonsi"
#VideoCards="nouveau nvidia"
#VideoCards="virtualbox vmware"
#VideoCards="false"
#partition_boot="/dev/sda1"
#partition_uefi="/dev/sda2"
#partition_root="/dev/sda3"
#partition_home="/dev/sda4"
#partition_swap="/dev/sda5"


## Portage
#
# Leave 'CPUCores' as-is. It will count the number of available cores
# which will be used during this script and set in the 'make.conf'.
# Changing this to 'Cores + 1', despite this being suggested in many
# corners of the web, is not a good idea and will actually increase the
# total time needed to compile.
#

case "$(uname -m)" in
i486|i586)
CPUDir="x86"
CPUArch="i486";;
cpu_dir="x86"
cpu_arch="i486";;
i686|x86|x86_32)
CPUDir="x86"
CPUArch="i686";;
cpu_dir="x86"
cpu_arch="i686";;
amd64|x86_64)
CPUDir="amd64"
CPUArch="amd64";;
cpu_dir="amd64"
cpu_arch="amd64";;

*)
echo "gein: error: your architecture has not been defined yet" \
| fold -s
echo "gein: Submit an issue with the output of 'uname -m'" \
"Submit an issue with the output of 'uname -m'" | fold -s
echo "gein: Exiting..." \
| fold -s
exit 1
esac

CPUCores="$(grep -c ^processor /proc/cpuinfo)"


## Gentoo Stage3
#
# This section exists to automate identifying and downloading the latest
# stage3 archive under the condition that cURL is present. This is not
# an issue when using the Gentoo installation CD's though prevents
# errors when executing MINIMAL() or DESKTOP() due to cURL missing
# after completing the BOOTSTRAP().

S3_Source="http://distfiles.gentoo.org/releases/$CPUDir/autobuilds"

if [ -x "$(command -v curl)" ]; then
S3_Release="curl -s $S3_Source/latest-stage3-$CPUArch.txt"
S3_Current="$($S3_Release|tail -1|awk '{print $1}')"
Stage3="$S3_Source/$S3_Current"
else
echo "gein: error: curl not present!"
echo "gein: Exiting..."
exit 1
fi


# By default, 'AutoKernel' is set to 'true' which means that the kernel
# will be built using 'make defconfig'. If you want to run
# 'make defconfig; make menuconfig' then set $AutoKernel to 'false'. You
# may also supply your own URL to $KernelConfig while setting
# 'AutoKernel' to 'false' to use a pre-built kernel config. An example
# kernel config is provided though commented out as it may quickly become
# irrelevant or dangerous to use.

AutoKernel="true"
#KernelConfig=""


# `gein` relies on downloading configuration files from the main
# repository. Here we will create the 'Source' variable which points to
# the main repository, and 'Config' is the list of all configuration
# files that will be installed.
#

ConfigSource="$Source"
config_source="https://gein.io"

CONFIG() {
# This is a list of all config files that need to be downloaded and
# moved into place.
Configs="
config_files="
/etc/portage/make.conf

/etc/portage/package.accept_keywords/development
@@ -155,31 +99,33 @@ CONFIG() {

/usr/local/sbin/gpkg
/usr/local/sbin/kbuild
"
"

# Files/Folders that need to be removed and re-created. Sometimes
# 'package.use' is a file, sometimes it's a folder. We need it to
# be a folder so we'll remove it outright and create what we need.
# Sure, this is wasting a little time, I know.
ConfigFolders="
config_dirs="
/etc/portage/package.accept_keywords
/etc/portage/package.use
/etc/portage/sets
"
"

for Folder in $ConfigFolders; do
if [ ! -d "$Folder" ]; then
$Rm "$Folder"
for dir in $config_dirs; do
if [ ! -d "$dir" ]; then
$rm "$dir"
fi

if [ ! -e "$Folder" ]; then
$Mkdir "$Folder"
if [ ! -e "$dir" ]; then
$mkdir "$dir"
fi
done

for File in $Configs; do
$Wget "$Source/$File" -O "$File"
unset config_dirs dir

for file in $config_files; do
$wget "$config_source/$file" -O "$file"
done

unset config_files file

config_complete="true"
}


@@ -187,7 +133,7 @@ CONFIG() {
#

PREREQUISITES() {
if [ -z "$PartitionBoot" ] || [ -z "$VideoCards" ]; then
if [ -z "$partition_boot" ] || [ -z "$video_cards" ]; then
echo "gein: error: required variables are unset!" | fold -s
echo "gein: please ensure you have partitioned and mounted" \
"your disks, as well as updated the variables associated" \
@@ -197,6 +143,8 @@ PREREQUISITES() {
echo "gein: Exiting..." | fold -s
exit 1
fi

prerequisites_complete="true"
}


@@ -212,13 +160,13 @@ PARTITION() {
echo "gein: Exiting..." | fold -s
exit 1
fi

partition_complete="true"
}


# Bootstrapping a Gentoo stage3 archive is a fairly quick process though
# we must also ensure this script will be accessible from the chroot as
# well as other housekeeping tasks. The Portage configuration files are
# setup in this section.
#
#

BOOTSTRAP() {
echo "gein: Ensuring we are in /mnt/gentoo..."
@@ -233,19 +181,25 @@ BOOTSTRAP() {
fi

echo "gein: Downloading and extracting Stage3 tarball..."
if [ -n "$Stage3" ]; then
$Wget "$Stage3"
if [ -x "$(command -v curl)" ]; then
stage3_source="http://distfiles.gentoo.org/releases/$cpu_dir/autobuilds"
stage3_release="curl -s $stage3_source/latest-stage3-$cpu_arch.txt"
stage3_current="$($stage3_release|tail -1|awk '{print $1}')"

$wget "$stage3_source/$stage3_current"
tar -xpf stage3-* --xattrs --numeric-owner
rm -rf stage3-*

unset stage3_source stage3_release stage3_current
else
echo "gein: 'Stage3' variable is not set! Is cURL missing?" | fold -s
echo "gein: Exiting..." | fold -s
exit
echo "gein: error: curl not present!"
echo "gein: Exiting..."
exit 1
fi

echo "gein: Mounting hardware devices..."
HW="proc sys dev"
for target in $HW; do
hardware_mountpoints="proc sys dev"
for target in $hardware_mountpoints; do
if [ -e /mnt/gentoo/"$target" ]; then
case "$target" in
proc) mount -t proc /proc /mnt/gentoo/proc ;;
@@ -264,10 +218,12 @@ BOOTSTRAP() {
fi
done

if [ ! -e "$SwapFile" ]; then
unset hardware_mountpoints target

if [ ! -e "$partition_swap" ]; then
echo "gein: Setting up swapfile..." | fold -s
mkswap "$PartitionSwap"
swapon "$PartitionSwap"
mkswap "$partition_swap"
swapon "$partition_swap"
echo "/swapfile none swap sw 0 0" >> /mnt/gentoo/etc/fstab
fi

@@ -275,20 +231,25 @@ BOOTSTRAP() {
cp -L /etc/resolv.conf /mnt/gentoo/etc/

echo "gein: Chroot'ing into /mnt/gentoo..." | fold -s
chroot /mnt/gentoo /usr/bin/env -i \
HOME="/root" TERM="$TERM" PS1="[chroot \u@\h \W]$ " \
PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin" \
PATH="$PATH:/usr/bin:/sbin:/bin:/opt/bin" \
MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
MANPATH="$MANPATH:/usr/local/share/man" \
/bin/bash --login
chroot \
/mnt/gentoo /usr/bin/env -i \
HOME="/root" \
TERM="$TERM" \
PS1="[chroot \u@\h \W]$ " \
PATH="/usr/local/sbin/:/usr/local/bin:/usr/sbin" \
PATH="$PATH:/usr/bin:/sbin:/bin:/opt/bin" \
MANPATH="/usr/man:/usr/share/man:/usr/local/man" \
MANPATH="$MANPATH:/usr/local/share/man" \
/bin/bash --login

bootstrap_complete="true"
}


# In this section we will update various configuration files, select the
# desired profile, compile the kernel, and install some basic packages.
#
#

MINIMAL() {
INSTALL() {
CONFIG

echo "gein: Setting CPU cores and GPU type..." | fold -s
@@ -296,52 +257,50 @@ MINIMAL() {
/etc/portage/make.conf

echo "gein: Syncing Portage and selecting profile..." | fold -s
$EmergeSync
$emerge_sync
eselect profile list | grep -Evi "dev|exp"

echo "gein: Choose the latest stable release" | fold -s
TargetProfile=""
while [ -z "$TargetProfile" ]; do
read -p "Which profile?: " TargetProfile
profile_target=""
while [ -z "$profile_target" ]; do
read -p "Which profile?: " profile_target
done
eselect profile set "$TargetProfile"
$Emerge -uDN @world
eselect profile set "$profile_target"
$emerge -uDN @world

echo "gein: Setting timezone..." | fold -s
echo "$TimeZone" > /etc/timezone
$Emerge --config sys-libs/timezone-data
echo "$timezone" > /etc/timezone
$emerge --config sys-libs/timezone-data

echo "gein: Setting locale..." | fold -s
echo "$Locale" > /etc/locale.gen
locale-gen
echo "$Locale" > /etc/locale.gen && locale-gen
L="$(echo $Locale | awk -F '[-]' '{print $1}')"
LSet="$(eselect locale list|grep -i $L|awk -F '[][]' '{print $2}')"
eselect locale set "$LSet"
LL="$(eselect locale list|grep -i $L|awk -F '[][]' '{print $2}')"
eselect locale set "$LL"
env-update && source /etc/profile
export PS1="[chroot \u@\h \W]$ "

echo "gein: Emerging base system packages..." | fold -s
$Emerge @gein-base

$emerge @gein-base
if grep -Rqi 'intel' /proc/cpuinfo; then
echo "gein: Emerging intel-microcode"
$Emerge intel-microcode
$emerge intel-microcode
fi

echo "gein: Configuring Linux kernel..."
cd /usr/src/linux
if [ "$AutoKernel" = "true" ]; then
if [ -z "$KernelConfig" ]; then
if [ "$kernel_autobuild" = "true" ]; then
if [ -z "$kernel_config" ]; then
make defconfig
else
$Wget "$KernelConfig" -O /usr/src/linux/.config
$wget "$kernel_config" -O /usr/src/linux/.config
fi
elif [ "$AutoKernel" = "false" ]; then
if [ -z "$KernelConfig" ]; then
elif [ "$kernel_autobuild" = "false" ]; then
if [ -z "$kernel_config" ]; then
make defconfig
make menuconfig
else
$Wget "$KernelConfig" -O /usr/src/linux/.config
$wget "$kernel_config" -O /usr/src/linux/.config
make menuconfig
fi
else
@@ -349,8 +308,9 @@ MINIMAL() {
fi

echo "gein: Compiling Linux kernel and modules..."
$Make && $Make modules && $Make install && $Make modules install
$Make distclean
$make && $make modules && \
$make install && $make modules install && \
$make distclean
cd /

echo "gein: Adding services to OpenRC..."
@@ -358,17 +318,18 @@ MINIMAL() {
rc-update add cronie default

echo "gein: Setting hostname..."
echo "hostname=$Hostname" > /etc/conf.d/hostname
echo "hostname=$hostname" > /etc/conf.d/hostname

echo "gein: Installing Grub to $PartitionBoot..."
grub-install "$PartitionBoot"
echo "gein: Installing Grub to $partition_boot..."
grub-install "$partition_boot"
grub-mkconfig -o /boot/grub/grub.cfg

install_complete="true"
}


# This section is for completing tasks after the installation is
# complete. The user will have a complete system already installed and
# may skip these steps if desired.
#
#

POSTINSTALL() {
echo "gein: Setting root password..."
@@ -378,22 +339,23 @@ POSTINSTALL() {
# groupadd power
# poweroff reboot shutdown

read -p "gein: Setup a standard user? [Y/N]: " SetupUser
if echo "$SetupUser" | grep -iq "^y"; then
read -p "gein: Setup a standard user? [Y/N]: " user_setup
if echo "$user_setup" | grep -iq "^y"; then
echo "gein: Creating user account"
read -p "Username: " Username
read -p "Username: " username
useradd -m -G wheel,audio,video \
-s /bin/bash "$Username"
passwd $Username
-s /bin/bash "$username"
passwd "$username"
fi

echo "gein: Installation complete."

postinstall_complete="true"
}


# This is the CLI that controls what will be run. Keep in mind that the
# BOOTSTRAP() needs to be run to completion before running the MINIMAL()
# or DESKTOP() passes.
#
#

case $1 in
-p|--partition)
@@ -408,7 +370,7 @@ case $1 in

-i|--install)
PREREQUISITES
MINIMAL
INSTALL
POSTINSTALL
;;


Loading…
Cancel
Save