From 538f7053f8ed2658f3bbb3e56322b1dda7ec1940 Mon Sep 17 00:00:00 2001 From: TrudeEH Date: Fri, 5 Jan 2024 19:06:17 +0000 Subject: [PATCH] Added new PS1 prompt and universal package manager, p. --- homeConfigs/.bashrc | 12 ++ install.sh | 119 +++++++++++------- .../{maintenance.sh => arch-maintenance.sh} | 0 scripts/codeAI-ollama.sh | 8 +- scripts/p.sh | 80 ++++++++++++ 5 files changed, 168 insertions(+), 51 deletions(-) create mode 100644 homeConfigs/.bashrc rename scripts/{maintenance.sh => arch-maintenance.sh} (100%) create mode 100755 scripts/p.sh diff --git a/homeConfigs/.bashrc b/homeConfigs/.bashrc new file mode 100644 index 00000000..373a7f74 --- /dev/null +++ b/homeConfigs/.bashrc @@ -0,0 +1,12 @@ +# +# ~/.bashrc +# + +# If not running interactively, don't do anything +[[ $- != *i* ]] && return + +source ~/dotfiles/scripts/p.sh + +alias ls='ls --color=auto' +alias grep='grep --color=auto' +PS1='\n[\[\e[37m\]\u\[\e[0m\]@\[\e[37;2m\]\h\[\e[0m\]] \[\e[1m\]\w \[\e[0;2m\]J:\[\e[0m\]\j\n\$ ' diff --git a/install.sh b/install.sh index f2c2f3e3..0c647756 100755 --- a/install.sh +++ b/install.sh @@ -1,77 +1,96 @@ #! /bin/bash +source ./scripts/p.sh # Universal package manager +dist=$(d) + +if [ $dist == 0 ]; then + echo "ERROR - Distro not supported." + return 1 +fi + # Ask Y/n function ask() { - read -p "$1 (Y/n): " resp - if [ -z "$resp" ]; then - response_lc="y" # empty is Yes - else - response_lc=$(echo "$resp" | tr '[:upper:]' '[:lower:]') # case insensitive - fi + read -p "$1 (Y/n): " resp + if [ -z "$resp" ]; then + response_lc="y" # empty is Yes + else + response_lc=$(echo "$resp" | tr '[:upper:]' '[:lower:]') # case insensitive + fi - [ "$response_lc" = "y" ] + [ "$response_lc" = "y" ] } # Upgrade echo "Updating packages..." -kgx -e "sudo pacman -Syu && sudo pacman -S git" -read -p "Press enter to continue." +p +p i git # Mirrors -if ask "Choose best mirrors (LONG TIME)?"; then - kgx -e "sudo pacman -S reflector && sudo reflector --sort rate -p https --save /etc/pacman.d/mirrorlist --verbose" - read -p "Press enter to continue." +if [ $dist == 2 ]; then + if ask "Choose best mirrors (LONG TIME)?"; then + sudo pacman -S reflector + sudo reflector --sort rate -p https --save /etc/pacman.d/mirrorlist --verbose + read -p "Press enter to continue." + fi fi # Install paru -paru=$(pacman -Q paru) -if [[ -n "$paru" ]]; then - echo -e "\e[32m[I] Paru is already installed.\e[0m" -else - kgx -e "sudo pacman -S --needed base-devel && \ - git clone https://aur.archlinux.org/paru.git && \ - cd paru && \ - makepkg -si && \ - cd .. && \ - rm -rf paru" +if [ $dist == 2 ]; then + paru=$(pacman -Q paru) + if [[ -n "$paru" ]]; then + echo -e "\e[32m[I] Paru is already installed.\e[0m" + else + sudo pacman -S --needed base-devel + git clone https://aur.archlinux.org/paru.git + cd paru + makepkg -si + cd .. + rm -rf paru + fi + read -p "Press enter to continue." fi -read -p "Press enter to continue." # Enable bluetooth support -if ask "Enable bluetooth?"; then - kgx -e "sudo pacman -S bluez bluez-utils && \ - sudo systemctl start bluetooth.service; \ - sudo systemctl enable bluetooth.service" +if [ $dist == 2 ]; then + if ask "Enable bluetooth?"; then + sudo pacman -S bluez bluez-utils + sudo systemctl start bluetooth.service + sudo systemctl enable bluetooth.service + fi fi # Enable printer support -if ask "Enable CUPS (printer)?"; then - kgx -e "sudo pacman -S cups && \ - sudo systemctl start cups; \ - sudo systemctl start cups.service; \ - sudo systemctl enable cups; \ - sudo systemctl enable cups.service" +if [ $dist == 2 ]; then + if ask "Enable CUPS (printer)?"; then + sudo pacman -S cups + sudo systemctl start cups + sudo systemctl start cups.service + sudo systemctl enable cups + sudo systemctl enable cups.service + fi fi # Install Tela Icons echo "Installing Tela Icon Theme..." -kgx -e "git clone https://github.com/vinceliuice/Tela-circle-icon-theme.git && \ -cd Tela-circle-icon-theme && \ -./install.sh ; \ -cd .. && \ -rm -rf Tela-circle-icon-theme; \ -gsettings set org.gnome.desktop.interface icon-theme 'Tela-circle'" -read -p "Press enter to continue." +git clone https://github.com/vinceliuice/Tela-circle-icon-theme.git +cd Tela-circle-icon-theme +./install.sh +cd .. +rm -rf Tela-circle-icon-theme +gsettings set org.gnome.desktop.interface icon-theme 'Tela-circle' # Install Cursor theme echo "Installing Cursor Theme..." -kgx -e "paru -S bibata-cursor-theme-bin && gsettings set org.gnome.desktop.interface cursor-theme 'Bibata-Modern-Classic'" -read -p "Press enter to continue." +p i bibata-cursor-theme +gsettings set org.gnome.desktop.interface cursor-theme 'Bibata-Modern-Classic' # Install Nerd Font echo "Installing JetBrains font..." -kgx -e "sudo pacman -S ttf-jetbrains-mono-nerd" -read -p "Press enter to continue." +if [ $dist == 2 ]; then + p i ttf-jetbrains-mono-nerd +else + p i fonts-jetbrains-mono +fi # Enable minimize button echo "Enabling minimize button..." @@ -79,8 +98,12 @@ gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,close" # Enable flatpak support if ask "Enable flatpak?"; then - kgx -e "sudo pacman -S flatpak && \ - flatpak install flatseal; \ - sudo flatpak override --filesystem=$HOME/.themes; \ - sudo flatpak override --filesystem=$HOME/.icons" + p i flatpak + flatpak install flatseal + sudo flatpak override --filesystem=$HOME/.themes + sudo flatpak override --filesystem=$HOME/.icons fi + +# Copy configs +echo "Copying configs..." +cp -rf homeConfigs/.* ~ diff --git a/scripts/maintenance.sh b/scripts/arch-maintenance.sh similarity index 100% rename from scripts/maintenance.sh rename to scripts/arch-maintenance.sh diff --git a/scripts/codeAI-ollama.sh b/scripts/codeAI-ollama.sh index a2471c06..9a2569fa 100755 --- a/scripts/codeAI-ollama.sh +++ b/scripts/codeAI-ollama.sh @@ -1,10 +1,12 @@ #! /bin/bash -ollama=$(pacman -Q ollama) -if [[ -n "$ollama" ]]; then +source ./p.sh +if [[ $(p c ollama) == 0 ]]; then kgx -e "ollama serve" sleep 1 kgx -e "ollama run codellama" else - kgx -e "sudo paru -S ollama; echo 'Run the script again...'" + d i ollama + echo + echo 'Run the script again...' fi diff --git a/scripts/p.sh b/scripts/p.sh new file mode 100755 index 00000000..8c7d8263 --- /dev/null +++ b/scripts/p.sh @@ -0,0 +1,80 @@ +#! /bin/bash +# Cross-distro package manager + +# p -> update os +# p i package -> install package +# p r package -> remove package +# p c package -> check if package is installed (0 -> installed; 1 -> not installed; 2 -> ERROR) +# d -> returns 1 -> Debian; 2 -> Arch; 0 -> Error + +d() { + if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then + echo 1 + elif [ "$(grep -Ei 'arch|manjaro|artix' /etc/*release)" ]; then + echo 2 + else + echo 0 + fi +} + +p() { + # Detect distro type + if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then + distro="DEB" + update="sudo apt update; sudo apt upgrade; sudo apt autoremove" + install="sudo apt install" + remove="sudo apt remove" + elif [ "$(grep -Ei 'arch|manjaro|artix' /etc/*release)" ]; then + distro="ARCH" + update="sudo pacman -Syu" + install="sudo pacman -S" + remove="sudo pacman -R" + else + echo "DISTRO NOT SUPPORTED" + return 1 + fi + + # If no parameter + if [ -z $1 ]; then + $update + return 0 + fi + + # If first parameter is i (install) + if [ $1 == "i" ]; then + $install $2 + if [ $? == 0 ]; then + return 0 + else + return 2 + fi + fi + + # If first parameter is r (remove) + if [ $1 == "r" ]; then + $remove $2 + if [ $? == 0 ]; then + return 0 + else + return 2 + fi + fi + + if [ $1 == "c" ]; then + if [ "$distro" == "DEB" ]; then + if dpkg-query -W -f='${Status}' $2 2>/dev/null | grep -q "install ok installed"; then + echo 0 + else + echo 1 + fi + elif [ "$distro" == "ARCH" ]; then + if pacman -Qs $2 >/dev/null; then + echo 0 + else + echo 1 + fi + else + echo 2 + fi + fi +}