Refactor scripts to be POSIX compliant
This commit is contained in:
95
install.sh
95
install.sh
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#! /bin/sh
|
||||
|
||||
# -r : Only reload configurations
|
||||
|
||||
@@ -6,37 +6,36 @@
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
PURPLE='\033[0;35m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
trap "echo -e '${RED}install.sh interrupted.${NC}'; exit 1" SIGINT SIGTERM
|
||||
trap 'printf "${RED}install.sh interrupted.${NC}"; exit 1' INT TERM
|
||||
|
||||
install_gnome_extension() {
|
||||
local uuid="$1"
|
||||
uuid="$1"
|
||||
|
||||
if [ -z "$uuid" ]; then
|
||||
printf "${RED}Usage: install_gnome_extension <extension-uuid>${NC}\n"
|
||||
echo "${RED}Usage: install_gnome_extension <extension-uuid>${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! gnome-extensions list | grep -qw "$uuid"; then
|
||||
printf "${GREEN}Sent install request for %s.${NC}\n" "$uuid"
|
||||
echo "${GREEN}Sent install request for $uuid.${NC}"
|
||||
gdbus call --session --dest org.gnome.Shell.Extensions \
|
||||
--object-path /org/gnome/Shell/Extensions \
|
||||
--method org.gnome.Shell.Extensions.InstallRemoteExtension \
|
||||
"$uuid" >/dev/null 2>&1
|
||||
return 0
|
||||
elif gnome-extensions list --updates | grep -qw "$uuid"; then
|
||||
printf "${GREEN}Sent update request for %s.${NC}\n" "$uuid"
|
||||
echo "${GREEN}Sent update request for $uuid.${NC}"
|
||||
gdbus call --session --dest org.gnome.Shell.Extensions \
|
||||
--object-path /org/gnome/Shell/Extensions \
|
||||
--method org.gnome.Shell.Extensions.InstallRemoteExtension \
|
||||
"$uuid" >/dev/null 2>&1
|
||||
return 0
|
||||
else
|
||||
printf "${GREEN}GNOME Extension %s is already installed.${NC}\n" "$uuid"
|
||||
echo "${GREEN}GNOME Extension $uuid is already installed.${NC}"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
@@ -51,37 +50,34 @@ for arg in "$@"; do
|
||||
done
|
||||
|
||||
# Clone Dotfiles if not already present
|
||||
cd "$HOME/dotfiles"
|
||||
cd "$HOME/dotfiles" || exit
|
||||
if [ "$(pwd)" != "$HOME/dotfiles" ]; then
|
||||
printf "${YELLOW}Cloning dotfiles repository...${NC}\n"
|
||||
echo "${YELLOW}Cloning dotfiles repository...${NC}"
|
||||
sudo apt update
|
||||
sudo apt install -y git
|
||||
git clone https://github.com/TrudeEH/dotfiles --depth 1
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}Error cloning dotfiles repository. Exiting...${NC}\n"
|
||||
if ! git clone https://github.com/TrudeEH/dotfiles --depth 1; then
|
||||
echo "${RED}Error cloning dotfiles repository. Exiting...${NC}"
|
||||
exit 2
|
||||
fi
|
||||
cd dotfiles || exit
|
||||
printf "${GREEN}dotfiles repository cloned successfully.${NC}\n"
|
||||
echo "${GREEN}dotfiles repository cloned successfully.${NC}"
|
||||
else
|
||||
printf "${YELLOW}Updating dotfiles repository...${NC}\n"
|
||||
echo "${YELLOW}Updating dotfiles repository...${NC}"
|
||||
pull_output=$(git pull)
|
||||
printf "%s\n" "$pull_output"
|
||||
echo "%s" "$pull_output"
|
||||
if ! echo "$pull_output" | grep -q "Already up to date."; then
|
||||
printf "${YELLOW}Changes detected. Re-running script...${NC}\n"
|
||||
echo "${YELLOW}Changes detected. Re-running script...${NC}"
|
||||
exec "$0" "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$HOME/dotfiles/logs"
|
||||
|
||||
printf "${CYAN}\n"
|
||||
printf "####################\n"
|
||||
printf "#"
|
||||
printf "${PURPLE} Trude's Dotfiles${CYAN} #\n"
|
||||
printf "####################\n"
|
||||
echo "${CYAN}####################"
|
||||
echo "#${PURPLE} Trude's Dotfiles${CYAN} #"
|
||||
echo "####################"
|
||||
fetch
|
||||
printf "\n"
|
||||
echo
|
||||
|
||||
# Install Programs
|
||||
if [ "$reload" = false ]; then
|
||||
@@ -89,27 +85,27 @@ if [ "$reload" = false ]; then
|
||||
fi
|
||||
|
||||
# Copy files
|
||||
printf "${YELLOW}Installing Dotfiles...${NC}\n"
|
||||
echo "${YELLOW}Installing Dotfiles...${NC}"
|
||||
cp -r "$HOME/dotfiles/home/." "$HOME"
|
||||
|
||||
# Copy scripts
|
||||
printf "${YELLOW}Installing Scripts...${NC}\n"
|
||||
echo "${YELLOW}Installing Scripts...${NC}"
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
cp -r "$HOME/dotfiles/scripts/." "$HOME/.local/bin/"
|
||||
|
||||
# Install fonts
|
||||
printf "${YELLOW}Installing fonts...${NC}\n"
|
||||
echo "${YELLOW}Installing fonts...${NC}"
|
||||
mkdir -p "$HOME/.local/share/fonts"
|
||||
cp -rf "$HOME/dotfiles/fonts/"* "$HOME/.local/share/fonts/"
|
||||
fc-cache -fv "$HOME/.local/share/fonts" >"$HOME/dotfiles/logs/font_install.log"
|
||||
|
||||
# UFW Firewall
|
||||
if [ "$reload" = false ]; then
|
||||
printf "${YELLOW}Setting up UFW...${NC}\n"
|
||||
echo "${YELLOW}Setting up UFW...${NC}"
|
||||
sudo ufw default deny incoming
|
||||
sudo ufw default allow outgoing
|
||||
if systemctl is-active --quiet sshd; then
|
||||
printf "${YELLOW}SSH Server detected; Enabling SSH rule...${NC}\n"
|
||||
echo "${YELLOW}SSH Server detected; Enabling SSH rule...${NC}"
|
||||
sudo ufw limit 22/tcp
|
||||
fi
|
||||
sudo ufw enable
|
||||
@@ -129,50 +125,47 @@ if [ "$USER" = "trude" ]; then
|
||||
|
||||
# Clone password-store
|
||||
if [ ! -f "$HOME/.ssh/id_ed25519" ] || [ ! -f "$HOME/.ssh/id_ed25519.pub" ]; then
|
||||
printf "${RED}ED25519 key not found in ${CYAN}$HOME/.ssh/id_ed25519. ${RED}Please add your ED25519 key pair for password-store.${NC}\n"
|
||||
echo "${RED}ED25519 key not found in ${CYAN}$HOME/.ssh/id_ed25519. ${RED}Please add your ED25519 key pair for password-store.${NC}"
|
||||
elif ! gpg --list-keys "ehtrude@gmail.com" >/dev/null 2>&1; then
|
||||
printf "${RED}GPG key for ehtrude@gmail.com not found. Please import the key for password-store.${NC}\n"
|
||||
echo "${RED}GPG key for ehtrude@gmail.com not found. Please import the key for password-store.${NC}"
|
||||
else
|
||||
if [ ! -d "$HOME/.password-store" ]; then
|
||||
printf "${YELLOW}Cloning password-store...${NC}\n"
|
||||
echo "${YELLOW}Cloning password-store...${NC}"
|
||||
chmod 700 ~/.ssh
|
||||
chmod 600 ~/.ssh/*
|
||||
git clone git@github.com:TrudeEH/password-store.git "$HOME/.password-store"
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}Error cloning password-store.${NC}\n"
|
||||
if ! git clone git@github.com:TrudeEH/password-store.git "$HOME/.password-store"; then
|
||||
echo "${RED}Error cloning password-store.${NC}"
|
||||
else
|
||||
printf "${GREEN}Password-store cloned successfully.${NC}\n"
|
||||
echo "${GREEN}Password-store cloned successfully.${NC}"
|
||||
fi
|
||||
else
|
||||
printf "${CYAN}Password-store already present.${NC}\n"
|
||||
echo "${CYAN}Password-store already present.${NC}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Security Scan
|
||||
if [ "$reload" = false ] && [ ! -f "$HOME/dotfiles/logs/lynis_scan.log" ]; then
|
||||
printf "${YELLOW}Running Lynis Security Scan...${NC}\n"
|
||||
sudo lynis audit system | tee "$HOME/dotfiles/logs/lynis_scan.log"
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}Error running Lynis.${NC}\n"
|
||||
echo "${YELLOW}Running Lynis Security Scan...${NC}"
|
||||
if ! sudo lynis audit system | tee "$HOME/dotfiles/logs/lynis_scan.log"; then
|
||||
echo "${RED}Error running Lynis.${NC}"
|
||||
else
|
||||
printf "${GREEN}Lynis scan completed.${NC}\n"
|
||||
echo "${GREEN}Lynis scan completed.${NC}"
|
||||
fi
|
||||
else
|
||||
printf "${CYAN}Previous Lynis scan detected, read the log @ $HOME/dotfiles/logs/lynis_scan.log.${NC}\n"
|
||||
echo "${CYAN}Previous Lynis scan detected, read the log @ $HOME/dotfiles/logs/lynis_scan.log.${NC}"
|
||||
fi
|
||||
|
||||
# Set up GNOME Desktop
|
||||
if [[ "$XDG_CURRENT_DESKTOP" == *"GNOME"* ]]; then
|
||||
printf "${YELLOW}Installing GNOME Extensions...${NC}\n"
|
||||
case "$XDG_CURRENT_DESKTOP" in
|
||||
*GNOME*)
|
||||
echo "${YELLOW}Installing GNOME Extensions...${NC}"
|
||||
install_gnome_extension "appindicatorsupport@rgcjonas.gmail.com"
|
||||
install_gnome_extension "caffeine@patapon.info"
|
||||
|
||||
printf "${YELLOW}Loading Dconf settings...${NC}\n"
|
||||
dconf load / <"$HOME/dotfiles/dconf-settings.ini"
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "${RED}Error loading Dconf settings.${NC}\n"
|
||||
else
|
||||
printf "${GREEN}Dconf settings loaded successfully.${NC}\n"
|
||||
echo "${YELLOW}Loading Dconf settings...${NC}"
|
||||
if ! dconf load / <"$HOME/dotfiles/dconf-settings.ini"; then
|
||||
echo "${RED}Error loading Dconf settings.${NC}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user