cbsh/README.org
2022-08-04 12:29:29 +01:00

18 KiB

Cabooshy's Shell (CBSH)

CBSH, or Cabooshy's Shell, is a Post installation Script for Arch Linux, and Arch Based Distro's, it installs his Qtile Based desktop and the Apps he uses.

About CBSH

Cabooshy's Shell (CBSH) is a Post Install Script for Arch Linux and Arch based Distro's, it installs my Qtile Desktop, and programs i use on a daily basis, like Emacs.

Installing CBSH

Install Instructions

To Install CBSH you'll need to clone the repo and run the shell script like so:

git clone https://gitlab.com/cabooshyy/cbsh/cbsh_arch/cbsh.git
cd cbsh
./cbsh

Potential Bugs

Slow Download Times

These Scripts can take a LONG time to complete as there are around 200 packages. On Arch, make sure you are using ParallelDownloads in /etc/pacman.conf for faster download times, for example changing ParallelDownloads so that it downloads up to five packages at a time:

ParallelDownloads = 5

DOOM Emacs isn't launching

After the install completes, DOOM Emacs may not launch properly the very first time, killing the Emacs Daemon (Emacs Server) if it is running, and restarting it fixes this issue.

killall emacs
/usr/bin/emacs --daemon &

Updating CBSH

CBSH is updated via your package manager.

So For Example, Updating would be done the standard way, as below:

$ sudo pacman -Syu

If you have a AUR Helper installed, you can use that instead:

yay (or yay -Syu)

paru (or paru -Syu)

pikaur -Syu

You can also substitute these for your preferred AUR Helper, these are just the three i know of and have used.

Many of CBSH's Packages are actually configuration files, these will get stored in /etc/cbsh, as we don't want to overwrite any config files you may already have on your system accidentally. If you'd like to use them, then you'd need to manually copy them from /etc/cbsh into $HOME.

NOTE: You do not need to run the CBSH install script more than once, if you succeeded in installing CBSH then you'll have access to the CBSH Repos and all of the Packages stored in them, so when a new update arrives and it installs packages that you don't have, you can simply install them via Pacman or an AUR Helper.

Contributing to CBSH

Contributions from other people are welcomed. especially for distro's i have no experience with, like Fedora, but there are a few things you will need to consider before making a merge request.

Edit The README.org

I get some people are not well versed in the emacs way of doing things, but this very readme is the postinstall script. Utilising ORG-Mode's magic, i convert the README.org into both cbsh scripts. So by editing the main scripts directly and making a merge request, especially for huge changes, makes a lot more work than what is needed, as i'd have to manually edit the README.org to make it conform to the changes you proposed in your merge request. So please, edit the README.org.

I Will include a conversion script for non emacs users so they can edit the corresponding (or new!) README.org with whatever Text-Editor/IDE they want, and then convert it into the script to see if it exports correctly.

TEST. YOUR. CHANGES. LOCALLY. FIRST.

It would be a very, very good idea to have a local VM with a clean installation of your distro of choice, and clone the clean VM when you need to test the script. Please don't make a merge request without actually testing your changes first in a fresh VM (One you have not run the script on before).

Shebang plus Comments

#   ____  ____  ____   _   _
#  / ___|| __ )/ ___| | | | |
# | |    |  _ \\___ \ | |_| |
# | |___ | |_) |___) ||  _  |
#  \____||____/|____/ |_| |_|
#
# NAME: CBSH -- ARCH
# DESC: An installation and deployment script that installs Cabooshy's Desktop on Arch Linux and Arch based Distro's
# WARNING: Run this script at your own risk.
# DEPENDENCIES: dialog

Check that user is NOT root!

Don't run this script as root! This is done for safety reasons, as this script makes a lot of changes to the $HOME of the $USER of this script. For obvious reasons, we want $USER to not be 'root' and $HOME not to be '/root'. Instead, run this script as a normal user. You will be asked to enter a sudo password at several points when needed.

if [ "$(id -u)" = 0 ]; then
    echo "#######################################################################"
    echo "This script MUST NOT be run as root user since it makes changes to the"
    echo "\$HOME directory of the \$USER executing this script. We dont want"
    echo "those to be 'root' and '/root',We don't want to mess around in there"
    echo "and potentially break something, So run this script as a normal user."
    echo "You will be asked for a sudo password when necessary."
    echo "######################################################################"
    exit 1
fi

Error Handling

err() { \
    clear; printf "ERR:\\n%s\\n" "$1" >&2; exit 1;
}

Sync The Repos, and Install 'dialog'

echo "##########################################################################"
echo "###### Syncing the Repos and installing 'dialog' if not installed ######"
echo "########################################################################"
sudo pacman --noconfirm --needed -Syu dialog || error "Error syncing the repos."

The Welcome Message

welcome () { \
dialog --colors --title "\Z7\ZbInstalling CBSH!" --msgbox "\Z4This Postinstall Script will install my Qtile Desktop as well as Doom Emacs, Zsh with the Starship Prompt, ST, dmenu, and some other essential programs to make my dotfiles and programs work.\\n\\n-Cabooshy" 16 60

dialog --colors --title "\Z7\ZbStay Near your PC!" --yes-label "Continue" --no-label "Exit" --yesno "\Z4This script cannot be run as root, but when needed you will be asked for your sudo password during the installation. This will give PACMAN the necessary permissions to install the software needed. So stay near the computer" 10 60
}
welcome || err "User choose to exit."

Adding the CBSH Repos to your system.

addrepos() { \
    echo "####################################################"
    echo "## Adding the CBSH repository to /etc/pacman.conf ##"
    echo "####################################################"
    grep -qxF "[cbsh-arch-repo]" /etc/pacman.conf ||
<<<<<<< HEAD
        (echo "[cbsh-arch-repo]"; echo "SigLevel = Optional DatabaseOptional"; \
=======
        (echo "[cbsh-arch-repo]"; echo "SigLevel = Required DatabaseOptional"; \
>>>>>>> 609e97154f55e730e4e1825daf67bf9b3cfb11ce
         echo "Server = https://gitlab.com/cbsh/cbsh-arch/\$repo/-/raw/main/\$arch") | sudo tee -a /etc/pacman.conf
}
addrepos || err "Error adding the Repo to /etc/pacman.conf."

Adding keyservers to gpg.conf

addkeyservers() { \
    echo "#######################################################"
    echo "## Adding Keyservers to /etc/pacman.d/gnupg/gpg.conf ##"
    echo "#######################################################"
    grep -qxF "keyserver.ubuntu.com:80" /etc/pacman.d/gnupg/gpg.conf || echo "keyserver hkp://keyserver.ubuntu.com:80" | sudo tee -a /etc/pacman.d/gnupg/gpg.conf
    grep -qxF "keyserver.ubuntu.com:443" /etc/pacman.d/gnupg/gpg.conf || echo "keyserver hkps://keyserver.ubuntu.com:443" | sudo tee -a /etc/pacman.d/gnupg/gpg.conf
}
addkeyservers || err "Error adding the Keyservers to /etc/pacman.d/gnupg/gpg.conf"

Recieving the PGP key

recieve_keys() { \
    local _pgpkey="94424B71F1A63D9D"
    echo "#############################"
    echo "## Adding PGP key $_pgpkey ##"
    echo "#############################"
    sudo pacman-key --recv-key $_pgpkey
    sudo pacman-key --lsign-key $_pgpkey
}
recieve_keys || err "Error Recieving PGP key $_pgpkey"

Installing the packages from the repos

All packages listed are either in the standard Arch Repos or in my CBSH repos. these will all get installed with pacman. the only exception is DOOM Emacs which will be installed later in the script.

NOTE: The `-ask 4` option tells pacman that all questions regarding removing conflicting packages are automatically answered YES

# Let's install all of the packages listed in the pkglist.txt file.
sudo pacman --needed --ask 4 -Syu - < pkglist.txt

# Now that pikaur is installed, we can sync the AUR and install some needed packages (Nerd Fonts) from there.
<<<<<<< HEAD
pikaur -Syu nerd-fonts-source-code-pro nerd-fonts-fira-code librewolf-bin
=======
pikaur -Syu nerd-fonts-source-code-pro nerd-fonts-fira-code
>>>>>>> 609e97154f55e730e4e1825daf67bf9b3cfb11ce

<<<<<<< Updated upstream =====

Choosing Graphics Drivers

By Default, the script normally installed the Nvidia Drivers, due to me using a Nvidia GPU, but recently i've realised it would be a much better idea to allow the user to install the relevant drivers based on what they use (Intel HD/Iris/Xe Graphics, AMD Graphics, Nvidia Graphics) instead of just installing the Nvidia Drivers if they don't use a Nvidia card.

PS3='Set Graphics Drivers: \n
NOTE: Currently, the nvidia-open drivers have an issue where they do not work on systems with AMD APUs, such as the Laptop Ryzen chips (C/U/H/HS/HX), or the Ryzen 2/3/4/5000 Series G Families of chips on the desktop, please use the closed source drivers instead to make sure you have a working system.'

shells=("intel" "nvidia-open", "nivdia" "amd" "quit")
select choice in "${shells[@]}"; do
    case $choice in
        intel)
            sudo pacman -S xf86-video-intel vulkan-intel intel-media-driver && \
            echo -e "Intel's Graphics Drivers have been installed."
            break
            ;;
        amd)
            sudo pacman -S radeon xf86-video-radeon vulkan-radeon libva-mesa-driver mesa-vdpau radeontop && \
            echo -e "AMD Drivers have been installed."
            break
            ;;
        nvidia-open)
            sudo pacman -S nvidia-open nvidia-utils opencl-nvidia nvidia-settings \
            echo -e "Nvidia Drivers have been installed, These are the Turing (GTX1600 series and RTX2000 series) and newer \"nvidia-open\" drivers, these are considered \"ALPHA QUALITY\" so there will be issues."
            break
            ;;
        nvidia)
            sudo pacman -S nvidia nvidia-utils nvidia-settings opencl-nvidia \
            echo -e "Closed Source Nvidia Drivers have been installed, these currently support everything back to Maxwell (GTX900 Series)."
            break
            ;;
        quit)
            echo "No Graphics drivers have been installed"
            break
            ;;
        ,*)
           echo "invalid option $REPLY"
           ;;
        esac
    done

>>>>>>> Stashed changes

Copying over the configs from /etc/cbsh to $HOME

Pacman cannot install files to $HOME, so normally we would place them in /etc/skel, but as some distros such as Manjaro and Arco use /etc/skel for their own specific config files, we place them in /etc/cbsh so there are no conflicts on any arch based distro. the config files are placed here and then copied over to $HOME, we backup config just in case anything goes wrong. BEWARE!

NOTE: /opt contains the SDDM theme and the Source Code for my builds of ST and dmenu.

NOTE: The /etc/cbsh directory contains all of the files and directories that will get automatically copied to a new users $HOME when they are created using `useradd` or `adduser` depending on the distro.

echo "#########################################################"
echo "## Copying the config files from /etc/cbsh into \$HOME ##"
echo "#########################################################"
[ ! -d /etc/cbsh ] && sudo mkdir /etc/cbsh
[ -d /etc/cbsh ] && mkdir ~/cbsh-backup-$(date +%Y.%m.%d-%H%M) && cp -Rf /etc/cbsh ~/cbsh-backup-$(date +%Y.%m.%d-%H%M)
[ ! -d ~/.config ] && mkdir ~/.config
[ -d ~/.config ] && mkdir ~/.config-backup-$(date +%Y.%m.%d-%H%M) && cp -Rf ~/.config ~/.config-backup-$(date +%Y.%m.%d-%H%M)

cd /etc/cbsh
<<<<<<< HEAD
sudo mv .config/qtile/* .config/qtile
sudo mv .config/kitty/* .config/kitty
=======
>>>>>>> 609e97154f55e730e4e1825daf67bf9b3cfb11ce
sudo mv zsh/.zshrc .zshrc
cp -Rf . ~ && cd -

echo "#################################################################################################"
echo "## Copying the sddm theme from /opt/cbsh-sddm-theme into /usr/share/sddm/theme/cbsh-sddm-theme ##"
echo "#################################################################################################"
cd /opt
sudo cp -r cbsh-sddm-theme /usr/share/sddm/themes

echo "#######################################################################"
echo "## Set skel directory to /etc/cbsh, so new users can use the configs ##"
echo "#######################################################################"
cd /etc/default
sudo sed "8cSKEL=/etc/cbsh" useradd

Installing DOOM Emacs!

echo "#########################################################"
echo "## Installing Doom Emacs. This may take a few minutes. ##"
echo "#########################################################"
[ -d ~/.emacs.d ] && mv ~/.emacs.d ~/.emacs.d.bak.$(date +"%Y%m%d_%H%M%S")
[ -f ~/.emacs ] && mv ~/.emacs ~/.emacs.bak.$(date +"%Y%m%d_%H%M%S")
git clone --depth 1 https://github.com/hlissner/doom-emacs ~/.emacs.d
~/.emacs.d/bin/doom install
~/.emacs.d/bin/doom sync

The Fun part, Setting the default USER shell!

PS3='Set default USER shell (enter number): '
shells=("fish" "zsh" "bash" "quit")
select choice in "${shells[@]}"; do
    case $choice in
        fish | bash | zsh)
            sudo chsh $USER -s "/bin/$choice" && \
            echo -e "$choice has been set as the default USER shell for your account. \
                    \nLogging out is required for this to take effect."
            break
            ;;
        quit)
            echo "User quit without changing their shell."
            break
            ;;
        ,*)
           echo "invalid option $REPLY"
           ;;
        esac
    done

Make Sure SDDM is enabled so we don't boot into a TTY, and NetworkManager is too so the applet works.

# Disable Current Login Manager, if any.
<<<<<<< HEAD
echo "######################################################"
echo "## Disable previous login manager, if there is one. ##"
echo "######################################################"
sudo systemctl disable $(grep '/usr/s\?bin' /etc/systemd/system/display-manager.service | awk -F / '{print $NF}') || echo "Cannot Disable current Display Manager, or a Display Manager isn't already installed."
=======
sudo systemctl disable $(grep '/usr/s\?bin' /etc/systemd/system/display-manager.service | awk -F / '{print $NF}') || echo "Cannot Disable current Display Manager, or one is not installed."
>>>>>>> 609e97154f55e730e4e1825daf67bf9b3cfb11ce

# Then enable SDDM as the Login Manager
sudo systemctl enable sddm
echo "###################################"
echo "## Enable sddm as login manager. ##"
echo "###################################"

## Next, Set cbsh-sddm-theme as the default theme for SDDM ##
# System Configuration File
[ -f "/usr/lib/sddm/sddm.conf.d/default.conf" ] && \
    sudo cp /usr/lib/sddm/sddm.conf.d/default.conf /usr/lib/sddm/sddm.conf.d/default.conf.backup && \
    sudo sed -i 's/^Current=*.*/Current=cbsh-sddm-theme/g' /usr/lib/sddm/sddm.conf.d/default.conf

# Local SDDM Configuration File
[ -f "/etc/sddm.conf" ] && \
    sudo cp /etc/sddm.conf /etc/sddm.conf.backup && \
    sudo sed -i 's/^Current=*.*/Current=cbsh-sddm-theme/g' /etc/sddm.conf

# Create a local file if it doesnt exist (Mainline Arch Linux doesn't by default)
[ ! -f "/etc/sddm.conf" ] && \
    sudo cp /usr/lib/sddm/sddm.conf.d/default.conf /etc/sddm.conf || echo "Default SDDM system config file is not found."


# Enable NetworkManager for networking
sudo systemctl enable NetworkManager

Installation Complete!

echo "###########################################"
echo "## CBSH has been installed successfully! ##"
echo "###########################################"

while true; do
    read -p "Do you want to reboot to get into your installation of CBSH? [Y/n]" yn
    case $yn in
        [Yy]* ) reboot;;
        [Nn]* ) break;;
        "" ) reboot;;
        ,* ) echo "Please answer yes or no.";;
        esac
    done