Automoation of dependencies setup

This commit is contained in:
hypeit
2023-12-25 12:08:05 +01:00
parent 774f4dbc0d
commit caf25db22b
2 changed files with 155 additions and 146 deletions

258
.bashrc
View File

@@ -7,7 +7,7 @@ iatest=$(expr index "$-" i)
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
. /etc/bashrc
fi
# Enable bash programmable completion features in interactive shells
@@ -58,14 +58,14 @@ alias snano='sedit'
alias vim='nvim'
# Replace batcat with cat on Fedora as batcat is not available as a RPM in any form
if command -v lsb_release > /dev/null; then
DISTRIBUTION=$(lsb_release -si)
if command -v lsb_release >/dev/null; then
DISTRIBUTION=$(lsb_release -si)
if [ "$DISTRIBUTION" = "Fedora" ]; then
alias cat='bat'
else
alias cat='batcat'
fi
if [ "$DISTRIBUTION" = "Fedora" ]; then
alias cat='bat'
else
alias cat='batcat'
fi
fi
# To have colors for ls and all grep commands such as grep, egrep and zgrep
@@ -149,20 +149,20 @@ alias bd='cd "$OLDPWD"'
alias rmd='/bin/rm --recursive --force --verbose '
# Alias's for multiple directory listing commands
alias la='ls -Alh' # show hidden files
alias la='ls -Alh' # show hidden files
alias ls='ls -aFh --color=always' # add colors and file type extensions
alias lx='ls -lXBh' # sort by extension
alias lk='ls -lSrh' # sort by size
alias lc='ls -lcrh' # sort by change time
alias lu='ls -lurh' # sort by access time
alias lr='ls -lRh' # recursive ls
alias lt='ls -ltrh' # sort by date
alias lm='ls -alh |more' # pipe through 'more'
alias lw='ls -xAh' # wide listing format
alias ll='ls -Fls' # long listing format
alias labc='ls -lap' #alphabetical sort
alias lf="ls -l | egrep -v '^d'" # files only
alias ldir="ls -l | egrep '^d'" # directories only
alias lx='ls -lXBh' # sort by extension
alias lk='ls -lSrh' # sort by size
alias lc='ls -lcrh' # sort by change time
alias lu='ls -lurh' # sort by access time
alias lr='ls -lRh' # recursive ls
alias lt='ls -ltrh' # sort by date
alias lm='ls -alh |more' # pipe through 'more'
alias lw='ls -xAh' # wide listing format
alias ll='ls -Fls' # long listing format
alias labc='ls -lap' #alphabetical sort
alias lf="ls -l | egrep -v '^d'" # files only
alias ldir="ls -l | egrep '^d'" # directories only
# alias chmod commands
alias mx='chmod a+x'
@@ -228,21 +228,19 @@ alias kssh="kitty +kitten ssh"
#######################################################
# Use the best version of pico installed
edit ()
{
if [ "$(type -t jpico)" = "file" ]; then
edit() {
if [[ $(type -t jpico) == "file" ]] || ([[ $(type -t jpico) == "alias" ]] && [[ -n $(which jpico) ]]); then
# Use JOE text editor http://joe-editor.sourceforge.net/
jpico -nonotice -linums -nobackups "$@"
elif [ "$(type -t nano)" = "file" ]; then
elif [[ $(type -t nano) == "file" ]] || ([[ $(type -t nano) == "alias" ]] && [[ -n $(which nano) ]]); then
nano -c "$@"
elif [ "$(type -t pico)" = "file" ]; then
elif [[ $(type -t pico) == "file" ]] || ([[ $(type -t pico) == "alias" ]] && [[ -n $(which pico) ]]); then
pico "$@"
else
nvim "$@"
fi
}
sedit ()
{
sedit() {
if [ "$(type -t jpico)" = "file" ]; then
# Use JOE text editor http://joe-editor.sourceforge.net/
sudo jpico -nonotice -linums -nobackups "$@"
@@ -256,22 +254,22 @@ sedit ()
}
# Extracts any archive(s) (if unp isn't installed)
extract () {
extract() {
for archive in "$@"; do
if [ -f "$archive" ] ; then
if [ -f "$archive" ]; then
case $archive in
*.tar.bz2) tar xvjf $archive ;;
*.tar.gz) tar xvzf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.gz) gunzip $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
*.tar.bz2) tar xvjf $archive ;;
*.tar.gz) tar xvzf $archive ;;
*.bz2) bunzip2 $archive ;;
*.rar) rar x $archive ;;
*.gz) gunzip $archive ;;
*.tar) tar xvf $archive ;;
*.tbz2) tar xvjf $archive ;;
*.tgz) tar xvzf $archive ;;
*.zip) unzip $archive ;;
*.Z) uncompress $archive ;;
*.7z) 7z x $archive ;;
*) echo "don't know how to extract '$archive'..." ;;
esac
else
echo "'$archive' is not a valid file!"
@@ -280,8 +278,7 @@ extract () {
}
# Searches for text in all files in the current folder
ftext ()
{
ftext() {
# -i case-insensitive
# -I ignore binary files
# -H causes filename to be printed
@@ -293,11 +290,10 @@ ftext ()
}
# Copy file with a progress bar
cpp()
{
cpp() {
set -e
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 |
awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
@@ -314,9 +310,8 @@ cpp()
}
# Copy and go to the directory
cpg ()
{
if [ -d "$2" ];then
cpg() {
if [ -d "$2" ]; then
cp "$1" "$2" && cd "$2"
else
cp "$1" "$2"
@@ -324,9 +319,8 @@ cpg ()
}
# Move and go to the directory
mvg ()
{
if [ -d "$2" ];then
mvg() {
if [ -d "$2" ]; then
mv "$1" "$2" && cd "$2"
else
mv "$1" "$2"
@@ -334,21 +328,18 @@ mvg ()
}
# Create and go to the directory
mkdirg ()
{
mkdirg() {
mkdir -p "$1"
cd "$1"
}
# Goes up a specified number of directories (i.e. up 4)
up ()
{
up() {
local d=""
limit=$1
for ((i=1 ; i <= limit ; i++))
do
d=$d/..
done
for ((i = 1; i <= limit; i++)); do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
if [ -z "$d" ]; then
d=..
@@ -367,39 +358,37 @@ up ()
# }
# Returns the last 2 fields of the working directory
pwdtail ()
{
pwd|awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
pwdtail() {
pwd | awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
}
# Show the current distribution
distribution ()
{
distribution() {
local dtype
# Assume unknown
dtype="unknown"
# First test against Fedora / RHEL / CentOS / generic Redhat derivative
if [ -r /etc/rc.d/init.d/functions ]; then
source /etc/rc.d/init.d/functions
[ zz`type -t passed 2>/dev/null` == "zzfunction" ] && dtype="redhat"
[ zz$(type -t passed 2>/dev/null) == "zzfunction" ] && dtype="redhat"
# Then test against SUSE (must be after Redhat,
# I've seen rc.status on Ubuntu I think? TODO: Recheck that)
elif [ -r /etc/rc.status ]; then
source /etc/rc.status
[ zz`type -t rc_reset 2>/dev/null` == "zzfunction" ] && dtype="suse"
[ zz$(type -t rc_reset 2>/dev/null) == "zzfunction" ] && dtype="suse"
# Then test against Debian, Ubuntu and friends
elif [ -r /lib/lsb/init-functions ]; then
source /lib/lsb/init-functions
[ zz`type -t log_begin_msg 2>/dev/null` == "zzfunction" ] && dtype="debian"
[ zz$(type -t log_begin_msg 2>/dev/null) == "zzfunction" ] && dtype="debian"
# Then test against Gentoo
elif [ -r /etc/init.d/functions.sh ]; then
source /etc/init.d/functions.sh
[ zz`type -t ebegin 2>/dev/null` == "zzfunction" ] && dtype="gentoo"
[ zz$(type -t ebegin 2>/dev/null) == "zzfunction" ] && dtype="gentoo"
# For Mandriva we currently just test if /etc/mandriva-release exists
# and isn't empty (TODO: Find a better way :)
elif [ -s /etc/mandriva-release ]; then
@@ -414,8 +403,7 @@ distribution ()
}
# Show the current version of the operating system
ver ()
{
ver() {
local dtype
dtype=$(distribution)
@@ -447,8 +435,7 @@ ver ()
}
# Automatically install the needed support files for this .bashrc file
install_bashrc_support ()
{
install_bashrc_support() {
local dtype
dtype=$(distribution)
@@ -476,8 +463,7 @@ install_bashrc_support ()
}
# Show current network information
netinfo ()
{
netinfo() {
echo "--------------- Network Information ---------------"
/sbin/ifconfig | awk /'inet addr/ {print $2}'
echo ""
@@ -491,33 +477,33 @@ netinfo ()
# IP address lookup
alias whatismyip="whatsmyip"
function whatsmyip ()
{
function whatsmyip() {
# Dumps a list of all IP addresses for every device
# /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }';
### Old commands
# Internal IP Lookup
#echo -n "Internal IP: " ; /sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
#
# # External IP Lookup
#
# # External IP Lookup
#echo -n "External IP: " ; wget http://smart-ip.net/myip -O - -q
# Internal IP Lookup.
if [ -e /sbin/ip ];
then
echo -n "Internal IP: " ; /sbin/ip addr show wlan0 | grep "inet " | awk -F: '{print $1}' | awk '{print $2}'
if [ -e /sbin/ip ]; then
echo -n "Internal IP: "
/sbin/ip addr show wlan0 | grep "inet " | awk -F: '{print $1}' | awk '{print $2}'
else
echo -n "Internal IP: " ; /sbin/ifconfig wlan0 | grep "inet " | awk -F: '{print $1} |' | awk '{print $2}'
echo -n "Internal IP: "
/sbin/ifconfig wlan0 | grep "inet " | awk -F: '{print $1} |' | awk '{print $2}'
fi
# External IP Lookup
echo -n "External IP: " ; curl -s ifconfig.me
# External IP Lookup
echo -n "External IP: "
curl -s ifconfig.me
}
# View Apache logs
apachelog ()
{
apachelog() {
if [ -f /etc/httpd/conf/httpd.conf ]; then
cd /var/log/httpd && ls -xAh && multitail --no-repeat -c -s 2 /var/log/httpd/*_log
else
@@ -526,8 +512,7 @@ apachelog ()
}
# Edit the Apache configuration
apacheconfig ()
{
apacheconfig() {
if [ -f /etc/httpd/conf/httpd.conf ]; then
sedit /etc/httpd/conf/httpd.conf
elif [ -f /etc/apache2/apache2.conf ]; then
@@ -540,8 +525,7 @@ apacheconfig ()
}
# Edit the PHP configuration file
phpconfig ()
{
phpconfig() {
if [ -f /etc/php.ini ]; then
sedit /etc/php.ini
elif [ -f /etc/php/php.ini ]; then
@@ -560,8 +544,7 @@ phpconfig ()
}
# Edit the MySQL configuration file
mysqlconfig ()
{
mysqlconfig() {
if [ -f /etc/my.cnf ]; then
sedit /etc/my.cnf
elif [ -f /etc/mysql/my.cnf ]; then
@@ -582,7 +565,7 @@ mysqlconfig ()
}
# For some reason, rot13 pops up everywhere
rot13 () {
rot13() {
if [ $# -eq 0 ]; then
tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'
else
@@ -591,11 +574,10 @@ rot13 () {
}
# Trim leading and trailing spaces (for scripts)
trim()
{
trim() {
local var=$*
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
echo -n "$var"
}
# GitHub Titus Additions
@@ -603,40 +585,39 @@ trim()
gcom() {
git add .
git commit -m "$1"
}
}
lazyg() {
git add .
git commit -m "$1"
git push
}
_z_cd() {
cd "$@" || return "$?"
cd "$@" || return "$?"
if [ "$_ZO_ECHO" = "1" ]; then
echo "$PWD"
fi
if [ "$_ZO_ECHO" = "1" ]; then
echo "$PWD"
fi
}
z() {
if [ "$#" -eq 0 ]; then
_z_cd ~
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
if [ -n "$OLDPWD" ]; then
_z_cd "$OLDPWD"
else
echo 'zoxide: $OLDPWD is not set'
return 1
fi
else
_zoxide_result="$(zoxide query -- "$@")" && _z_cd "$_zoxide_result"
fi
if [ "$#" -eq 0 ]; then
_z_cd ~
elif [ "$#" -eq 1 ] && [ "$1" = '-' ]; then
if [ -n "$OLDPWD" ]; then
_z_cd "$OLDPWD"
else
echo 'zoxide: $OLDPWD is not set'
return 1
fi
else
_zoxide_result="$(zoxide query -- "$@")" && _z_cd "$_zoxide_result"
fi
}
zi() {
_zoxide_result="$(zoxide query -i -- "$@")" && _z_cd "$_zoxide_result"
_zoxide_result="$(zoxide query -i -- "$@")" && _z_cd "$_zoxide_result"
}
alias za='zoxide add'
alias zq='zoxide query'
@@ -644,22 +625,21 @@ alias zqi='zoxide query -i'
alias zr='zoxide remove'
zri() {
_zoxide_result="$(zoxide query -i -- "$@")" && zoxide remove "$_zoxide_result"
_zoxide_result="$(zoxide query -i -- "$@")" && zoxide remove "$_zoxide_result"
}
_zoxide_hook() {
if [ -z "${_ZO_PWD}" ]; then
_ZO_PWD="${PWD}"
elif [ "${_ZO_PWD}" != "${PWD}" ]; then
_ZO_PWD="${PWD}"
zoxide add "$(pwd -L)"
fi
if [ -z "${_ZO_PWD}" ]; then
_ZO_PWD="${PWD}"
elif [ "${_ZO_PWD}" != "${PWD}" ]; then
_ZO_PWD="${PWD}"
zoxide add "$(pwd -L)"
fi
}
case "$PROMPT_COMMAND" in
*_zoxide_hook*) ;;
*) PROMPT_COMMAND="_zoxide_hook${PROMPT_COMMAND:+;${PROMPT_COMMAND}}" ;;
*_zoxide_hook*) ;;
*) PROMPT_COMMAND="_zoxide_hook${PROMPT_COMMAND:+;${PROMPT_COMMAND}}" ;;
esac
alias lookingglass="~/looking-glass-B5.0.1/client/build/looking-glass-client -F"
#######################################################
@@ -674,7 +654,10 @@ export PATH=$PATH:"$HOME/.local/bin:$HOME/.cargo/bin:/var/lib/flatpak/exports/bi
eval "$(starship init bash)"
#Autojump
# Install zoxide
eval "$(zoxide init bash)"
#Autojump and fzf
if [ -f "/usr/share/autojump/autojump.sh" ]; then
. /usr/share/autojump/autojump.sh
@@ -684,3 +667,4 @@ else
echo "can't found the autojump script"
fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

View File

@@ -5,8 +5,8 @@ RED='\e[31m'
YELLOW='\e[33m'
GREEN='\e[32m'
command_exists () {
command -v $1 >/dev/null 2>&1;
command_exists() {
command -v $1 >/dev/null 2>&1
}
checkEnv() {
@@ -31,7 +31,6 @@ checkEnv() {
exit 1
fi
## Check if the current directory is writable.
GITPATH="$(dirname "$(realpath "$0")")"
if [[ ! -w ${GITPATH} ]]; then
@@ -53,7 +52,7 @@ checkEnv() {
echo -e "${RED}You need to be a member of the sudo group to run me!"
exit 1
fi
}
installDepend() {
@@ -68,22 +67,45 @@ installDepend() {
else
echo "Command yay already installed"
fi
yay --noconfirm -S ${DEPENDENCIES}
else
sudo ${PACKAGER} install -yq ${DEPENDENCIES}
yay --noconfirm -S ${DEPENDENCIES}
else
sudo ${PACKAGER} install -yq ${DEPENDENCIES}
fi
}
installStarship(){
installStarship() {
if command_exists starship; then
echo "Starship already installed"
return
fi
if ! curl -sS https://starship.rs/install.sh|sh;then
if ! curl -sS https://starship.rs/install.sh | sh; then
echo -e "${RED}Something went wrong during starship install!${RC}"
exit 1
fi
if command_exists fzf; then
echo "Fzf already installed"
else
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
fi
}
installZoxide() {
if command_exists zoxide; then
echo "Zoxide already installed"
return
fi
if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then
echo -e "${RED}Something went wrong during zoxide install!${RC}"
exit 1
fi
}
install_additional_dependencies() {
sudo apt update
sudo apt install -y trash-cli bat meld jpico
}
linkConfig() {
@@ -108,6 +130,9 @@ linkConfig() {
checkEnv
installDepend
installStarship
installZoxide
install_additional_dependencies
if linkConfig; then
echo -e "${GREEN}Done!\nrestart your shell to see the changes.${RC}"
else