Small tweaks and auto-update

This commit is contained in:
2025-03-14 08:59:03 +00:00
parent 45f5c3dfeb
commit d29b44e783
2 changed files with 48 additions and 35 deletions

View File

@@ -12,18 +12,24 @@ NC='\033[0m' # No Color
mkdir -p "$HOME/dotfiles/logs"
# Clone Dotfiles if not already present
cd "$HOME/dotfiles" || exit
cd "$HOME/dotfiles"
if [ "$(pwd)" != "$HOME/dotfiles" ]; then
printf "${YELLOW}[+] Cloning dotfiles repository...${NC}\n"
printf "${YELLOW}Cloning dotfiles repository...${NC}\n"
git clone https://github.com/TrudeEH/dotfiles --depth 1
if [ $? -ne 0 ]; then
printf "${RED}[E] Error cloning dotfiles repository. Exiting...${NC}\n"
printf "${RED}Error cloning dotfiles repository. Exiting...${NC}\n"
exit 2
fi
cd dotfiles || exit
printf "${GREEN}[I] dotfiles repository cloned successfully.${NC}\n"
printf "${GREEN}dotfiles repository cloned successfully.${NC}\n"
else
printf "${GREEN}[I] dotfiles repository already present.${NC}\n"
printf "${YELLOW}Updating dotfiles repository...${NC}\n"
pull_output=$(git pull)
printf "%s\n" "$pull_output"
if ! echo "$pull_output" | grep -q "Already up to date."; then
printf "${YELLOW}Changes detected. Re-running script...${NC}\n"
exec "$0" "$@"
fi
fi
source ./scripts/p.sh
@@ -46,105 +52,105 @@ fi
p i "${programs[@]}"
# Copy files
printf "${YELLOW}[+] Installing Dotfiles...${NC}\n"
printf "${YELLOW}Installing Dotfiles...${NC}\n"
cp -r "$HOME/dotfiles/home/." "$HOME"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error copying Dotfiles.${NC}\n"
printf "${RED}Error copying Dotfiles.${NC}\n"
else
printf "${GREEN}[I] Dotfiles installed successfully.${NC}\n"
printf "${GREEN}Dotfiles installed successfully.${NC}\n"
fi
# Copy scripts
printf "${YELLOW}[+] Installing Scripts...${NC}\n"
printf "${YELLOW}Installing Scripts...${NC}\n"
mkdir -p "$HOME/.local/bin"
cp -r "$HOME/dotfiles/scripts/." "$HOME/.local/bin/"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error copying Scripts.${NC}\n"
printf "${RED}Error copying Scripts.${NC}\n"
else
printf "${GREEN}[I] Scripts installed successfully.${NC}\n"
printf "${GREEN}Scripts installed successfully.${NC}\n"
fi
# Install fonts
printf "${YELLOW}[+] Installing fonts...${NC}\n"
printf "${YELLOW}Installing fonts...${NC}\n"
if [[ "$OSTYPE" == "darwin"* ]]; then
cp -rf "$HOME/dotfiles/fonts/"* "$HOME/Library/Fonts/"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error installing fonts.${NC}\n"
printf "${RED}Error installing fonts.${NC}\n"
else
printf "${GREEN}[I] Fonts installed successfully.${NC}\n"
printf "${GREEN}Fonts installed successfully.${NC}\n"
fi
else
mkdir -p "$HOME/.local/share/fonts"
cp -rf "$HOME/dotfiles/fonts/"* "$HOME/.local/share/fonts/"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error installing fonts.${NC}\n"
printf "${RED}Error installing fonts.${NC}\n"
else
fc-cache -fv "$HOME/.local/share/fonts" >"$HOME/dotfiles/logs/font_install.log"
printf "${GREEN}[I] Fonts installed successfully.${NC}\n"
printf "${GREEN}Fonts installed successfully.${NC}\n"
fi
fi
# Load Dconf (GNOME settings)
if [[ "$OSTYPE" != "darwin"* ]]; then
printf "${YELLOW}[+] Loading Dconf settings...${NC}\n"
printf "${YELLOW}Loading Dconf settings...${NC}\n"
dconf load / <"$HOME/dotfiles/dconf-settings.ini"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error loading Dconf settings.${NC}\n"
printf "${RED}Error loading Dconf settings.${NC}\n"
else
printf "${GREEN}[I] Dconf settings loaded successfully.${NC}\n"
printf "${GREEN}Dconf settings loaded successfully.${NC}\n"
fi
fi
# UFW Firewall
if [[ "$OSTYPE" != "darwin"* ]]; then
printf "${YELLOW}[+] Setting up UFW...${NC}\n"
printf "${YELLOW}Setting up UFW...${NC}\n"
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"
printf "${YELLOW}SSH Server detected; Enabling SSH rule...${NC}\n"
sudo ufw limit 22/tcp
fi
sudo ufw enable
sudo ufw status numbered | tee "$HOME/dotfiles/logs/ufw_status.log"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error setting up UFW.${NC}\n"
printf "${RED}Error setting up UFW.${NC}\n"
else
printf "${GREEN}[I] UFW setup successfully.${NC}\n"
printf "${GREEN}UFW setup successfully.${NC}\n"
fi
else
printf "${YELLOW}[+] Enabling macOS Firewall...${NC}\n"
printf "${YELLOW}Enabling macOS Firewall...${NC}\n"
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate on
if [ $? -ne 0 ]; then
printf "${RED}[E] Error enabling Firewall.${NC}\n"
printf "${RED}Error enabling Firewall.${NC}\n"
else
printf "${GREEN}[I] Firewall enabled successfully.${NC}\n"
printf "${GREEN}Firewall enabled successfully.${NC}\n"
fi
fi
# Clone password-store
if [ "$(whoami)" = "trude" ]; then
if [ ! -d "$HOME/.password-store" ]; then
printf "${YELLOW}[+] Cloning password-store...${NC}\n"
printf "${YELLOW}Cloning password-store...${NC}\n"
git clone https://github.com/TrudeEH/password-store "$HOME/.password-store"
if [ $? -ne 0 ]; then
printf "${RED}[E] Error cloning password-store.${NC}\n"
printf "${RED}Error cloning password-store.${NC}\n"
else
printf "${GREEN}[I] Password-store cloned successfully.${NC}\n"
printf "${GREEN}Password-store cloned successfully.${NC}\n"
fi
else
printf "${CYAN}[I] Password-store already present.${NC}\n"
printf "${CYAN}Password-store already present.${NC}\n"
fi
fi
# Security Scan
if [ ! -f "$HOME/dotfiles/logs/lynis_scan.log" ]; then
printf "${YELLOW}[+] Running Lynis Security Scan...${NC}\n"
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}[E] Error running Lynis.${NC}\n"
printf "${RED}Error running Lynis.${NC}\n"
else
printf "${GREEN}[I] Lynis scan completed.${NC}\n"
printf "${GREEN}Lynis scan completed.${NC}\n"
fi
else
printf "${CYAN}[I] Previous Lynis scan detected, read the log @ $HOME/dotfiles/logs/lynis_scan.log.${NC}\n"
printf "${CYAN}Previous Lynis scan detected, read the log @ $HOME/dotfiles/logs/lynis_scan.log.${NC}\n"
fi

View File

@@ -45,26 +45,31 @@ p() (
updateP() {
if [[ ${packageManagers[@]} =~ "flatpak" ]]; then
printf "%b\n" "${YELLOW}Updating flatpak...${ENDCOLOR}"
flatpak update
flatpak uninstall --unused --delete-data
fi
if [[ ${packageManagers[@]} =~ "nix" ]]; then
printf "%b\n" "${YELLOW}Updating nix...${ENDCOLOR}"
nix-channel --update
sudo nix-channel --update
nix-collect-garbage --delete-older-than 7d
fi
if [[ ${packageManagers[@]} =~ "brew" ]]; then
printf "%b\n" "${YELLOW}Updating brew...${ENDCOLOR}"
brew update
brew doctor
brew upgrade
fi
if [[ ${packageManagers[@]} =~ "apt" ]]; then
printf "%b\n" "${YELLOW}Updating apt...${ENDCOLOR}"
sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt autoremove
sudo apt autoclean
elif [[ ${packageManagers[@]} =~ "pacman" ]]; then
printf "%b\n" "${YELLOW}Updating pacman...${ENDCOLOR}"
sudo sed -i 's/^#ParallelDownloads/ParallelDownloads/' /etc/pacman.conf
if [[ ${packageManagers[@]} =~ "paru" ]]; then
paru -Syu
@@ -73,6 +78,7 @@ p() (
fi
sudo pacman -Rsn $(pacman -Qdtq)
if [ ! "$(command -v reflector)" ]; then
printf "%b\n" "${YELLOW}Selecting fastest pacman mirrors...${ENDCOLOR}"
sudo pacman -Sy --noconfirm reflector rsync curl
iso=$(curl -4 ifconfig.co/country-iso)
extra="FR"
@@ -83,6 +89,7 @@ p() (
fi
paccache -rk1
elif [[ ${packageManagers[@]} =~ "dnf" ]]; then
printf "%b\n" "${YELLOW}Updating dnf...${ENDCOLOR}"
sudo dnf upgrade --refresh
sudo dnf autoremove
fi
@@ -237,7 +244,7 @@ p() (
}
# If no parameter or u
printf "%b\n" "${CYAN}Available package managers: ${MAGENTA}${packageManagers[@]}${ENDCOLOR}"
printf "%b\n" "${CYAN}Detected package managers: ${MAGENTA}${packageManagers[*]}${ENDCOLOR}"
if [ -z $1 ] || [ $1 = "u" ]; then
updateP
return 0