2024-07-30 22:33:30 +01:00
#!/bin/sh -e
2024-09-12 21:14:50 +01:00
2024-08-15 07:13:56 +01:00
. ../common-script.sh
2024-07-30 22:33:30 +01:00
setupDWM( ) {
2024-09-19 19:50:57 +01:00
printf "%b\n" " ${ YELLOW } Installing DWM-Titus... ${ RC } "
2024-07-30 22:33:30 +01:00
case " $PACKAGER " in # Install pre-Requisites
pacman)
2024-09-21 15:06:52 +01:00
" $ESCALATION_TOOL " " $PACKAGER " -S --needed --noconfirm base-devel libx11 libxinerama libxft imlib2 libxcb git unzip flameshot lxappearance feh
2024-07-30 22:33:30 +01:00
; ;
2024-09-16 14:36:45 +01:00
apt-get| nala)
2024-09-21 15:06:52 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y build-essential libx11-dev libxinerama-dev libxft-dev libimlib2-dev libx11-xcb-dev libfontconfig1 libx11-6 libxft2 libxinerama1 libxcb-res0-dev git unzip flameshot lxappearance feh
2024-07-30 22:33:30 +01:00
; ;
2024-09-02 22:33:47 +01:00
dnf)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " groupinstall -y "Development Tools"
2024-09-21 15:06:52 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y libX11-devel libXinerama-devel libXft-devel imlib2-devel libxcb-devel unzip flameshot lxappearance feh # no need to include git here as it should be already installed via "Development Tools"
2024-09-02 22:33:47 +01:00
; ;
*)
2024-09-22 17:01:10 +01:00
printf "%b\n" " ${ RED } Unsupported package manager: " " $PACKAGER " " ${ RC } "
2024-09-02 22:33:47 +01:00
exit 1
; ;
2024-07-30 22:33:30 +01:00
esac
}
2024-09-18 19:38:36 +01:00
makeDWM( ) {
cd " $HOME " && git clone https://github.com/ChrisTitusTech/dwm-titus.git # CD to Home directory to install dwm-titus
# This path can be changed (e.g. to linux-toolbox directory)
cd dwm-titus/ # Hardcoded path, maybe not the best.
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " make clean install # Run make clean install
2024-09-18 19:38:36 +01:00
}
2024-09-02 22:33:47 +01:00
install_nerd_font( ) {
FONT_DIR = " $HOME /.local/share/fonts "
FONT_ZIP = " $FONT_DIR /Meslo.zip "
FONT_URL = "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip"
FONT_INSTALLED = $( fc-list | grep -i "Meslo" )
# Check if Meslo Nerd-font is already installed
if [ -n " $FONT_INSTALLED " ] ; then
2024-09-17 03:58:17 +01:00
printf "%b\n" " ${ GREEN } Meslo Nerd-fonts are already installed. ${ RC } "
2024-09-02 22:33:47 +01:00
return 0
fi
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Installing Meslo Nerd-fonts ${ RC } "
2024-09-02 22:33:47 +01:00
# Create the fonts directory if it doesn't exist
if [ ! -d " $FONT_DIR " ] ; then
mkdir -p " $FONT_DIR " || {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to create directory: $FONT_DIR ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
}
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } $FONT_DIR exists, skipping creation. ${ RC } "
2024-09-02 22:33:47 +01:00
fi
# Check if the font zip file already exists
if [ ! -f " $FONT_ZIP " ] ; then
# Download the font zip file
2024-09-12 21:02:00 +01:00
curl -sSLo " $FONT_ZIP " " $FONT_URL " || {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to download Meslo Nerd-fonts from $FONT_URL ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
}
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Meslo.zip already exists in $FONT_DIR , skipping download. ${ RC } "
2024-09-02 22:33:47 +01:00
fi
# Unzip the font file if it hasn't been unzipped yet
if [ ! -d " $FONT_DIR /Meslo " ] ; then
unzip " $FONT_ZIP " -d " $FONT_DIR " || {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to unzip $FONT_ZIP ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
}
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Meslo font files already unzipped in $FONT_DIR , skipping unzip. ${ RC } "
2024-09-02 22:33:47 +01:00
fi
# Remove the zip file
rm " $FONT_ZIP " || {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to remove $FONT_ZIP ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
}
# Rebuild the font cache
fc-cache -fv || {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to rebuild font cache ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
}
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Meslo Nerd-fonts installed successfully ${ RC } "
2024-09-02 22:33:47 +01:00
}
picom_animations( ) {
2024-09-21 15:06:52 +01:00
# clone the repo into .local/share & use the -p flag to avoid overwriting that dir
mkdir -p " $HOME /.local/share/ "
if [ ! -d " $HOME /.local/share/ftlabs-picom " ] ; then
if ! git clone https://github.com/FT-Labs/picom.git " $HOME /.local/share/ftlabs-picom " ; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to clone the repository ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
fi
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Repository already exists, skipping clone ${ RC } "
2024-09-02 22:33:47 +01:00
fi
2024-09-21 15:06:52 +01:00
cd " $HOME /.local/share/ftlabs-picom " || { printf "%b\n" " ${ RED } Failed to change directory to picom ${ RC } " ; return 1; }
2024-09-02 22:33:47 +01:00
# Build the project
if ! meson setup --buildtype= release build; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Meson setup failed ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
fi
if ! ninja -C build; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Ninja build failed ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
fi
# Install the built binary
2024-09-19 01:03:32 +01:00
if ! " $ESCALATION_TOOL " ninja -C build install; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to install the built binary ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
fi
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Picom animations installed successfully ${ RC } "
2024-09-02 22:33:47 +01:00
}
clone_config_folders( ) {
# Ensure the target directory exists
[ ! -d ~/.config ] && mkdir -p ~/.config
# Iterate over all directories in config/*
for dir in config/*/; do
# Extract the directory name
dir_name = $( basename " $dir " )
# Clone the directory to ~/.config/
if [ -d " $dir " ] ; then
cp -r " $dir " ~/.config/
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Cloned $dir_name to ~/.config/ ${ RC } "
2024-09-02 22:33:47 +01:00
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Directory $dir_name does not exist, skipping ${ RC } "
2024-09-02 22:33:47 +01:00
fi
done
}
configure_backgrounds( ) {
2024-09-07 16:52:41 +01:00
# Set the variable PIC_DIR which stores the path for images
PIC_DIR = " $HOME /Pictures "
2024-09-02 22:33:47 +01:00
# Set the variable BG_DIR to the path where backgrounds will be stored
2024-09-07 16:52:41 +01:00
BG_DIR = " $PIC_DIR /backgrounds "
2024-09-02 22:33:47 +01:00
# Check if the ~/Pictures directory exists
2024-09-07 16:52:41 +01:00
if [ ! -d " $PIC_DIR " ] ; then
2024-09-02 22:33:47 +01:00
# If it doesn't exist, print an error message and return with a status of 1 (indicating failure)
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Pictures directory does not exist ${ RC } "
2024-09-02 22:33:47 +01:00
mkdir ~/Pictures
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Directory was created in Home folder ${ RC } "
2024-09-02 22:33:47 +01:00
fi
2024-09-07 16:52:41 +01:00
2024-09-02 22:33:47 +01:00
# Check if the backgrounds directory (BG_DIR) exists
if [ ! -d " $BG_DIR " ] ; then
# If the backgrounds directory doesn't exist, attempt to clone a repository containing backgrounds
2024-09-07 16:52:41 +01:00
if ! git clone https://github.com/ChrisTitusTech/nord-background.git " $PIC_DIR /nord-background " ; then
2024-09-02 22:33:47 +01:00
# If the git clone command fails, print an error message and return with a status of 1
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to clone the repository ${ RC } "
2024-09-02 22:33:47 +01:00
return 1
fi
# Rename the cloned directory to 'backgrounds'
2024-09-07 16:52:41 +01:00
mv " $PIC_DIR /nord-background " " $PIC_DIR /backgrounds "
2024-09-02 22:33:47 +01:00
# Print a success message indicating that the backgrounds have been downloaded
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Downloaded desktop backgrounds to $BG_DIR ${ RC } "
2024-09-02 22:33:47 +01:00
else
# If the backgrounds directory already exists, print a message indicating that the download is being skipped
2024-09-17 03:58:17 +01:00
printf "%b\n" " ${ GREEN } Path $BG_DIR exists for desktop backgrounds, skipping download of backgrounds ${ RC } "
2024-09-02 22:33:47 +01:00
fi
}
2024-09-03 21:14:21 +01:00
setupDisplayManager( ) {
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Setting up Xorg ${ RC } "
2024-09-03 21:14:21 +01:00
case " $PACKAGER " in
pacman)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " -S --needed --noconfirm xorg-xinit xorg-server
2024-09-03 21:14:21 +01:00
; ;
2024-09-16 14:36:45 +01:00
apt-get| nala)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y xorg xinit
2024-09-03 21:14:21 +01:00
; ;
dnf)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y xorg-x11-xinit xorg-x11-server-Xorg
2024-09-03 21:14:21 +01:00
; ;
*)
2024-09-19 19:05:36 +01:00
printf "%b\n" " ${ RED } Unsupported package manager: " $PACKAGER " ${ RC } "
2024-09-03 21:14:21 +01:00
exit 1
; ;
esac
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Xorg installed successfully ${ RC } "
printf "%b\n" " ${ YELLOW } Setting up Display Manager ${ RC } "
2024-09-03 23:26:45 +01:00
currentdm = "none"
for dm in gdm sddm lightdm; do
2024-09-12 21:14:50 +01:00
if systemctl is-active --quiet " $dm .service " ; then
currentdm = " $dm "
2024-09-03 23:26:45 +01:00
break
fi
done
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Current display manager: $currentdm ${ RC } "
2024-09-03 23:26:45 +01:00
if [ " $currentdm " = "none" ] ; then
DM = "sddm"
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } No display manager found, installing $DM ${ RC } "
2024-09-03 23:26:45 +01:00
case " $PACKAGER " in
pacman)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " -S --needed --noconfirm " $DM "
2024-09-03 23:26:45 +01:00
; ;
2024-09-16 14:36:45 +01:00
apt-get| nala)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y " $DM "
2024-09-03 23:26:45 +01:00
; ;
dnf)
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " " $PACKAGER " install -y " $DM "
2024-09-03 23:26:45 +01:00
; ;
*)
2024-09-19 19:05:36 +01:00
printf "%b\n" " ${ RED } Unsupported package manager: " $PACKAGER " ${ RC } "
2024-09-03 23:26:45 +01:00
exit 1
; ;
esac
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } $DM installed successfully ${ RC } "
2024-09-12 21:14:50 +01:00
systemctl enable " $DM "
2024-09-03 23:26:45 +01:00
# Prompt user for auto-login
2024-09-12 21:14:50 +01:00
# Using printf instead of echo -n as It's more posix-compliant.
printf "Do you want to enable auto-login? (Y/n) "
read -r answer
case " $answer " in
[ Yy] *)
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Configuring SDDM for autologin ${ RC } "
2024-09-12 21:14:50 +01:00
SDDM_CONF = "/etc/sddm.conf"
if [ ! -f " $SDDM_CONF " ] ; then
2024-09-19 01:03:32 +01:00
echo "[Autologin]" | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
echo " User= $USER " | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
echo "Session=dwm" | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
2024-09-03 23:26:45 +01:00
else
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " sed -i '/^\[Autologin\]/d' " $SDDM_CONF "
" $ESCALATION_TOOL " sed -i '/^User=/d' " $SDDM_CONF "
" $ESCALATION_TOOL " sed -i '/^Session=/d' " $SDDM_CONF "
echo "[Autologin]" | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
echo " User= $USER " | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
echo "Session=dwm" | " $ESCALATION_TOOL " tee -a " $SDDM_CONF "
2024-09-03 23:26:45 +01:00
fi
2024-09-17 03:44:20 +01:00
printf "%b\n" " {YELLOW}Checking if autologin group exists ${ RC } "
2024-09-12 21:14:50 +01:00
if ! getent group autologin > /dev/null; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Creating autologin group ${ RC } "
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " groupadd autologin
2024-09-12 21:14:50 +01:00
else
2024-09-17 03:58:17 +01:00
printf "%b\n" " ${ GREEN } Autologin group already exists ${ RC } "
2024-09-12 21:14:50 +01:00
fi
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Adding user with UID 1000 to autologin group ${ RC } "
2024-09-12 21:14:50 +01:00
USER_UID_1000 = $( getent passwd 1000 | cut -d: -f1)
if [ -n " $USER_UID_1000 " ] ; then
2024-09-19 01:03:32 +01:00
" $ESCALATION_TOOL " usermod -aG autologin " $USER_UID_1000 "
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } User $USER_UID_1000 added to autologin group ${ RC } "
2024-09-12 21:14:50 +01:00
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } No user with UID 1000 found - Auto login not possible ${ RC } "
2024-09-12 21:14:50 +01:00
fi
; ;
*)
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Auto-login configuration skipped ${ RC } "
2024-09-12 21:14:50 +01:00
; ;
esac
2024-09-03 23:26:45 +01:00
fi
2024-09-03 21:14:21 +01:00
}
2024-09-02 22:33:47 +01:00
2024-09-15 09:45:27 +01:00
install_slstatus( ) {
2024-09-15 14:46:43 +01:00
printf "Do you want to install slstatus? (y/N): " # using printf instead of 'echo' to avoid newline, -n flag for 'echo' is not supported in POSIX
read -r response # -r flag to prevent backslashes from being interpreted
if [ " $response " = "y" ] || [ " $response " = "Y" ] ; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ YELLOW } Installing slstatus ${ RC } "
2024-09-19 01:35:00 +01:00
cd " $HOME /dwm-titus/slstatus " || { printf "%b\n" " ${ RED } Failed to change directory to slstatus ${ RC } " ; return 1; }
2024-09-19 01:03:32 +01:00
if " $ESCALATION_TOOL " make clean install; then
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } slstatus installed successfully ${ RC } "
2024-09-15 14:46:43 +01:00
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ RED } Failed to install slstatus ${ RC } "
2024-09-15 14:46:43 +01:00
return 1
fi
else
2024-09-17 03:44:20 +01:00
printf "%b\n" " ${ GREEN } Skipping slstatus installation ${ RC } "
2024-09-15 14:46:43 +01:00
fi
2024-09-15 15:12:23 +01:00
cd " $HOME "
2024-09-15 09:45:27 +01:00
}
2024-07-30 22:33:30 +01:00
checkEnv
2024-08-23 14:12:47 +01:00
checkEscalationTool
2024-09-03 21:14:21 +01:00
setupDisplayManager
2024-07-30 22:33:30 +01:00
setupDWM
2024-08-15 07:13:56 +01:00
makeDWM
2024-09-15 09:45:27 +01:00
install_slstatus
2024-09-02 22:33:47 +01:00
install_nerd_font
clone_config_folders
2024-09-19 19:50:57 +01:00
configure_backgrounds