Skip to content

Commit

Permalink
Merge pull request #114 from szymonos/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
szymonos authored Sep 23, 2023
2 parents 0226b7f + 0bf8f30 commit aa53131
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 258 deletions.
4 changes: 2 additions & 2 deletions .assets/config/bash_cfg/aliases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ alias cd..='cd ../'
alias cic='set completion-ignore-case On'
alias cp='cp -iv'
alias d='bm -d'
alias exa='exa -g --color=auto --time-style=long-iso --group-directories-first'
alias eza='eza -g --color=auto --time-style=long-iso --group-directories-first'
alias gsi='sysinfo'
alias ll='exa -lah'
alias ll='eza -lah'
alias ff='fastfetch'
alias fix_stty='stty sane'
alias fix_term='printf "\ec"'
Expand Down
4 changes: 2 additions & 2 deletions .assets/config/pwsh_cfg/_aliases_linux.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if ($env:DISTRO_FAMILY -eq 'alpine') {
function ip { $input | & /usr/bin/env ip --color=auto @args }
function ls { & /usr/bin/env ls -h --color=auto --group-directories-first --time-style=long-iso @args }
}
function exa { & /usr/bin/env exa -g --color=auto --time-style=long-iso --group-directories-first @args }
function ll { exa -lah @args }
function eza { & /usr/bin/env eza -g --color=auto --time-style=long-iso --group-directories-first @args }
function ll { eza -lah @args }
function grep { $input | & /usr/bin/env grep --ignore-case --color=auto @args }
function less { $input | & /usr/bin/env less -FRXc @args }
function l { ls -1 @args }
Expand Down
19 changes: 3 additions & 16 deletions .assets/provision/install_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,7 @@ alpine)
exit 0
;;
arch)
if pacman -Qqe paru &>/dev/null; then
user=${1:-$(id -un 1000 2>/dev/null)}
if ! sudo -u $user true 2>/dev/null; then
if [ -n "$user" ]; then
printf "\e[31;1mUser does not exist ($user).\e[0m\n"
else
printf "\e[31;1mUser ID 1000 not found.\e[0m\n"
fi
exit 1
fi
sudo -u $user paru -Sy --needed --noconfirm docker
else
printf '\e[33;1mWarning: paru not installed.\e[0m\n'
fi
pacman -Sy --needed --noconfirm docker docker-compose
;;
fedora)
if rpm -q docker &>/dev/null; then
Expand All @@ -37,7 +24,7 @@ fedora)
if [ ! -f /etc/yum.repos.d/docker-ce.repo ]; then
dnf config-manager --add-repo 'https://download.docker.com/linux/fedora/docker-ce.repo'
fi
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose
;;
debian | ubuntu)
export DEBIAN_FRONTEND=noninteractive
Expand All @@ -51,7 +38,7 @@ debian | ubuntu)
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$SYS_ID \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list >/dev/null
fi
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose
;;
opensuse)
zypper in -y docker containerd docker-compose
Expand Down
100 changes: 100 additions & 0 deletions .assets/provision/install_eza.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env bash
: '
sudo .assets/provision/install_eza.sh >/dev/null
'
if [ $EUID -ne 0 ]; then
printf '\e[31;1mRun the script as root.\e[0m\n'
exit 1
fi

# determine system id
SYS_ID="$(sed -En '/^ID.*(alpine|arch|fedora|debian|ubuntu|opensuse).*/{s//\1/;p;q}' /etc/os-release)"
# check if package installed already using package manager
APP='eza'
case $SYS_ID in
alpine)
[ -f /usr/bin/eza ] && exit 0 || true
# TODO replace after eza will be added to Alpine repos
# apk -e info $APP &>/dev/null && exit 0 || true
;;
arch)
pacman -Qqe $APP &>/dev/null && exit 0 || true
;;
fedora)
[ -f /usr/bin/eza ] && exit 0 || true
# TODO replace after eza will be added to Fedora repos
# rpm -q $APP &>/dev/null && exit 0 || true
;;
debian | ubuntu)
dpkg -s $APP &>/dev/null && exit 0 || true
;;
opensuse)
rpm -q $APP &>/dev/null && exit 0 || true
;;
esac

REL=$1
retry_count=0
# try 10 times to get latest release if not provided as a parameter
while [ -z "$REL" ]; do
REL=$(curl -sk https://api.github.com/repos/eza-community/eza/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p')
((retry_count++))
if [ $retry_count -eq 10 ]; then
printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2
exit 0
fi
[[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2
done
# return latest release
echo $REL

if type $APP &>/dev/null; then
VER=$(eza --version | sed -En 's/v([0-9\.]+).*/\1/p')
if [ "$REL" = "$VER" ]; then
printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2
exit 0
fi
fi

printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2
case $SYS_ID in
alpine)
binary=true
lib='musl'
# apk add --no-cache eza >&2 2>/dev/null
;;
arch)
pacman -Sy --needed --noconfirm $APP >&2 2>/dev/null || binary=true
;;
fedora)
binary=true
lib='gnu'
;;
debian | ubuntu)
export DEBIAN_FRONTEND=noninteractive
mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | tee /etc/apt/sources.list.d/gierens.list
chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list
apt-get update >&2 && apt-get install -y $APP >&2 2>/dev/null || binary=true
;;
opensuse)
zypper in -y eza >&2 2>/dev/null || binary=true
;;
*)
binary=true
;;
esac

if [ "$binary" = true ]; then
echo 'Installing from binary.' >&2
TMP_DIR=$(mktemp -dp "$PWD")
retry_count=0
while [[ ! -f "$TMP_DIR/eza-linux-x86_64.tar.gz" && $retry_count -lt 10 ]]; do
curl -Lsk -o "$TMP_DIR/eza-linux-x86_64.tar.gz" "https://github.com/eza-community/eza/releases/download/v${REL}/eza_x86_64-unknown-linux-${lib}.tar.gz"
((retry_count++))
done
tar -zxf "$TMP_DIR/eza-linux-x86_64.tar.gz" -C "$TMP_DIR"
install -m 0755 "$TMP_DIR/eza" /usr/bin/
rm -fr "$TMP_DIR"
fi
2 changes: 1 addition & 1 deletion .assets/provision/install_terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ done
echo $REL

if type $APP &>/dev/null; then
VER=$(exa --version | grep -Po '(?<=^v)[0-9\.]+')
VER=$($APP --version | sed -En 's/Terraform v([0-9\.]+)/\1/p')
if [ "$REL" = "$VER" ]; then
printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2
exit 0
Expand Down
6 changes: 3 additions & 3 deletions .assets/provision/setup_profile_allusers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ begin {
}

process {
# *modify exa alias
# *modify eza alias
if (Test-Path $CFG_PATH/_aliases_linux.ps1) {
$exa_git = exa --version | Select-String '+git' -SimpleMatch -Quiet
$exa_git = eza --version | Select-String '+git' -SimpleMatch -Quiet
$exa_nerd = Select-String '' -Path /usr/local/share/oh-my-posh/theme.omp.json -SimpleMatch -Quiet
$exa_param = ($exa_git ? '--git ' : '') + ($exa_nerd ? '--icons ' : '')
$content = [IO.File]::ReadAllLines("$CFG_PATH/_aliases_linux.ps1").Replace('exa -g ', "exa -g $exa_param")
$content = [IO.File]::ReadAllLines("$CFG_PATH/_aliases_linux.ps1").Replace('eza -g ', "eza -g $exa_param")
[IO.File]::WriteAllLines("$CFG_PATH/_aliases_linux.ps1", $content)
}

Expand Down
6 changes: 3 additions & 3 deletions .assets/provision/setup_profile_allusers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ if [ -d .assets/config/bash_cfg ]; then
sudo -u $user mkdir -p "$CFG_PATH"
cp -f .assets/config/bash_cfg/* "$CFG_PATH"
fi
# *modify exa alias
# *modify eza alias
if [ -f "$CFG_PATH/aliases.sh" ]; then
# *set nerd fonts if oh-my-posh uses them
exa_param=''
exa --version 2>/dev/null | grep -Fqw '+git' && exa_param+='--git ' || true
eza --version 2>/dev/null | grep -Fqw '+git' && exa_param+='--git ' || true
grep -Fqw '' ""$OMP_PATH/theme.omp.json"" 2>/dev/null && exa_param+='--icons ' || true
sed -i "s/exa -g /exa -g $exa_param/" "$CFG_PATH/aliases.sh"
sed -i "s/eza -g /eza -g $exa_param/" "$CFG_PATH/aliases.sh"
fi

# *Copy global profiles
Expand Down
60 changes: 20 additions & 40 deletions .assets/scripts/linux_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fi
# parse named parameters
scope=${scope}
omp_theme=${omp_theme}
ps_modules=${ps_modules:-'do-common do-linux'}
sys_upgrade=${sys_upgrade:-false}
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
Expand Down Expand Up @@ -119,7 +118,7 @@ for sc in ${scope_arr[@]}; do
shell)
printf "\e[96minstalling shell packages...\e[0m\n"
sudo .assets/provision/install_pwsh.sh >/dev/null
sudo .assets/provision/install_exa.sh >/dev/null
sudo .assets/provision/install_eza.sh >/dev/null
sudo .assets/provision/install_bat.sh >/dev/null
sudo .assets/provision/install_ripgrep.sh >/dev/null
printf "\e[96msetting up profile for all users...\e[0m\n"
Expand All @@ -133,46 +132,27 @@ for sc in ${scope_arr[@]}; do
done
# install powershell modules
if [ -f /usr/bin/pwsh ]; then
modules=($ps_modules)
grep -qw 'az' <<<$scope && modules+=(do-az) || true
[ -f /usr/bin/git ] && modules+=(aliases-git) || true
[ -f /usr/bin/kubectl ] && modules+=(aliases-kubectl) || true
if [[ -n "$modules" && -f /usr/bin/git ]]; then
cloned=$(.assets/tools/gh_repo_clone.ps1 -OrgRepo 'szymonos/ps-modules')
if [ "$cloned" = "True" ]; then
printf "\e[96minstalling ps-modules...\e[0m\n"
target_repo='ps-modules'
# determine if target repository exists and clone if necessary
get_origin='git config --get remote.origin.url'
if [ -d "../$target_repo" ]; then
pushd "../$target_repo" >/dev/null
if eval $get_origin | grep -qw "github\.com[:/]szymonos/$target_repo"; then
git fetch --prune --quiet
git switch main --force --quiet
git reset --hard --quiet origin/main
else
printf "\e[93manother \"$target_repo\" repository exists\e[0m\n"
modules=()
fi
popd >/dev/null
else
remote=$(eval $get_origin | sed "s/\([:/]szymonos\/\).*/\1$target_repo.git/")
git clone $remote "../$target_repo"
fi
# install do-common module for all users
if grep -qw 'do-common' <<<$ps_modules; then
printf "\e[3;32mAllUsers\e[23m : do-common\e[0m\n"
sudo ../$target_repo/module_manage.ps1 'do-common' -CleanUp
fi
# install rest of the modules for the current user
modules=(${modules[@]/do-common/})
if [ -n "$modules" ]; then
# Convert the modules array to a comma-separated string with quoted elements
printf "\e[3;32mCurrentUser\e[23m : ${modules[*]}\e[0m\n"
mods=''
for element in "${modules[@]}"; do
mods="$mods'$element',"
done
pwsh -nop -c "@(${mods%,}) | ../$target_repo/module_manage.ps1 -CleanUp"
fi
printf "\e[3;32mAllUsers\e[23m : do-common\e[0m\n"
sudo ../ps-modules/module_manage.ps1 'do-common' -CleanUp

# determine current user scope modules to install
modules=('do-linux')
grep -qw 'az' <<<$scope && modules+=(do-az) || true
[ -f /usr/bin/git ] && modules+=(aliases-git) || true
[ -f /usr/bin/kubectl ] && modules+=(aliases-kubectl) || true
# Convert the modules array to a comma-separated string with quoted elements
printf "\e[3;32mCurrentUser\e[23m : ${modules[*]}\e[0m\n"
mods=''
for element in "${modules[@]}"; do
mods="$mods'$element',"
done
pwsh -nop -c "@(${mods%,}) | ../ps-modules/module_manage.ps1 -CleanUp"
else
printf '\e[33mps-modules repository cloning failed\e[0m.\n'
fi
fi

Expand Down
81 changes: 0 additions & 81 deletions .assets/tools/cert_chain_pem.ps1

This file was deleted.

Loading

0 comments on commit aa53131

Please sign in to comment.