Skip to content

Commit

Permalink
Merge pull request #29 from gpproton/dev
Browse files Browse the repository at this point in the history
Merge script improvemwnts
  • Loading branch information
gpproton authored Jul 15, 2023
2 parents 454d864 + 8c0cc4c commit 5da0493
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
4 changes: 4 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"recommendations": [
"redhat.vscode-yaml",
"ms-vscode-remote.remote-wsl",
"redhat.vscode-xml",
"wayou.vscode-todo-highlight",
"foxundermoon.shell-format"
]
}
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
# Persnal Shell Assist collections
# Personal Shell Assist collections

Scripts to perform rapid setup and simplify shell commands, although these can be done using ansible this repo is intended to keep samples for direct shell execution.

```bash
git clone https://github.com/gpproton/shell-assist.git && \
cd shell-assist && \
chmod +x ./setup.sh
```

## Setup unix alias

```bash
./setup alias
```

## Roadmap for utilities
- [x] Alias setup
- [ ] Basic servers setup
- [ ] Docker setup
- [x] Docker alias
- [x] Docker compose alias
- [x] Docker swarm alias
- [ ] Kubernetes setup
- [ ] Linux network setup
- [ ] Alias setup
- [ ] Linux Dev workstation setups
- [ ] WSL setup
- [ ] Windows package setup
- [ ] Windows Dev setup

## Compatible operating system
- [ ] OpenSuse
- [ ] Fedora
- [x] OpenSuse
- [x] Fedora
- [ ] Ubuntu
- [ ] Windows WSL
- [ ] Mac OS
- [ ] Windows
- [x] Mac OS

MIT License

Copyright (c) 2022 <Godwin peter .O>me@godwin.dev
Copyright (c) 2023 [Godwin peter .O](mailto:me@godwin.dev)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 12 additions & 6 deletions alias/docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/bash
## Docker command aliases

alias dim="docker images"
alias dps="docker ps"
alias dpsa="docker ps -a"
alias dsp="docker system prune --all"
alias dpull='docker pull'

function dnames {
for ID in $(docker ps | awk '{print $1}' | grep -v 'CONTAINER'); do
docker inspect $ID | grep Name | head -1 | awk '{print $2}' | sed 's/,//g' | sed 's%/%%g' | sed 's/"//g'
Expand Down Expand Up @@ -46,13 +53,12 @@ function drmid {
[ ! -z "$imgs" ] && docker rmi "$imgs" || echo "no dangling images."
}

alias dim="docker images"
alias dps="docker ps"
alias dpsa="docker ps -a"
alias dsp="docker system prune --all"
function dprune() {
docker rm -f $(docker ps -q) &&
docker rmi $(docker images -q) &&
echo y | docker system prune
echo y | docker system prunealias dim="docker images"
alias dps="docker ps"
alias dpsa="docker ps -a"
alias dsp="docker system prune --all"
alias dpull='docker pull'
}
alias dpull='docker pull'
20 changes: 20 additions & 0 deletions certificate/localhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[req]
prompt = no
default_bits = 2048
distinguished_name = subject
req_extensions = req_ext
x509_extensions = x509_ext
[subject]
commonName = localhost
[req_ext]
basicConstraints = critical, CA:true
subjectAltName = @alt_names
[x509_ext]
basicConstraints = critical, CA:true
keyUsage = critical, keyCertSign, cRLSign, digitalSignature,keyEncipherment
extendedKeyUsage = critical, serverAuth
subjectAltName = critical, @alt_names
1.3.6.1.4.1.311.84.1.1 = ASN1:UTF8String:ASP.NET Core HTTPS development certificate
[alt_names]
DNS.1 = localhost
DNS.2 = 127.0.0.1
33 changes: 33 additions & 0 deletions certificate/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

function setup_certificate() {
mkdir -p $HOME/certificate
certificate_root="$HOME/certificate"
certificate_config="certificate/localhost.conf"

if [[ -d $HOME/certificate ]]; then
echo "$(dirname $0)/$certificate_config"
cp "$(dirname $0)/$certificate_config" $HOME/$certificate_config

if [[ -f $HOME/$certificate_config ]]; then
echo "generating certificate keys"
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout $certificate_root/localhost.key \
-out $certificate_root/localhost.crt \
-config $certificate_root/localhost.conf
fi

if [[ $os_variant == "openSUSE" ]]; then
echo "apply private key for $os_variant"
sudo cp $certificate_root/localhost.crt /usr/share/pki/trust/anchors
sudo update-ca-certificates
fi

if [[ -f $certificate_root/localhost.crt ]]; then
echo verifing generated certificate..
openssl verify $certificate_root/localhost.crt
fi

fi

}
1 change: 1 addition & 0 deletions linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Linux quick start
File renamed without changes.
1 change: 1 addition & 0 deletions network/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Linux network info
1 change: 1 addition & 0 deletions network/Ubuntu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ubuntu networking
29 changes: 22 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash

os_defaults="$(dirname $0)/util/os-defaults.sh"
setup_alias="$(dirname $0)/setup/setup-alias.sh"
os_defaults="$(dirname $0)/util/defaults.sh"

# Load OS information
if [ -f "$os_defaults" ]; then source $os_defaults && load_os_info; fi
## Load alias setup functions
if [ -f $setup_alias ]; then source $setup_alias; fi
if [ -f "$os_defaults" ]; then
source $os_defaults && load_os_info
load_environment_variables
load_shell_properties
fi

function help_content() {
cat <<-EOF
Expand All @@ -16,7 +17,7 @@ OS VARIANT: $os_variant
========================================================
===================== SHELL-ASSIST =====================
usage: ./play [-h] [--help]
usage: ./setup [-h] [--help]
options:
Expand All @@ -26,6 +27,10 @@ options:
alias: Setup shell alias usage
usage: ./setup alias
-------------------------------------------------------
certificate: Setup self signed certificate
usage: ./setup certificate
-------------------------------------------------------
docker: Setup docker environment
Expand All @@ -42,11 +47,21 @@ EOF
case $1 in
"alias")
echo "starting alias setup..."
load_alias_script
setup_alias="$(dirname $0)/setup/setup-alias.sh"
if [ -f $setup_alias ]; then
source $setup_alias
register_profile_alias
fi

;;
"docker")
echo "Starting docker setup..."
;;
"certificate")
echo "Starting self signed certificate setup..."
certificate="$(dirname $0)/certificate/setup.sh"
if [ -f $certificate ]; then source $certificate && setup_certificate; fi
;;
"dev")
echo "Starting development work station setup..."
;;
Expand Down
15 changes: 8 additions & 7 deletions setup/setup-alias.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash

function load_alias_script() {
if [[ -x "$(command -v grep "shell-assist" -q $HOME/.bashrc)" ]]; then
## copy to newly created directory
cat >>"$HOME/.bashrc" <<SHELL
function register_profile_alias() {
alias_configured=$(cat $shell_profile_file | grep -c "shell-assist")
if [[ $alias_configured -eq 0 ]]; then
cat >>"$shell_profile_file" <<SHELL
## start shell-assist
ALIAS_PATH="\$HOME/shell-assist/alias"
Expand All @@ -15,9 +15,10 @@ if [ -d \$ALIAS_PATH ]; then
done
fi
## end shell-assist
SHELL
echo "alias configuration successful..."
else
echo "alias already configured..."
fi
## reload shell environment
echo "reloading shell environment.."
source "$HOME/.bashrc"
}
38 changes: 27 additions & 11 deletions util/os-defaults.sh → util/defaults.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/bash

function load_environment_variables() {
echo 'loading enviroment varibles from file...'
env_file='.env'
if [ -f $PWD/$env_file ]; then
env_file='.env.sample'
fi
set -a
source <(cat $env_file | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a

unset $env_file
}

function load_os_info() {
os_type=$(uname -s)
if [ $os_type == "Darwin" ]; then
Expand All @@ -22,15 +35,18 @@ function load_os_info() {
fi
}

function load_env() {
echo 'loading enviroment varibles from file...'
env_file='.env'
if [ -f $PWD/$env_file ]; then
env_file='.env.sample'
fi
set -a
source <(cat $env_file | sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g")
set +a

unset $env_file
function load_shell_properties() {
shell_profile_file="$HOME/.bashrc"
active_shell="bash"
case $SHELL in
"*zsh*")
shell_profile_file="$HOME/.zshrc"
active_shell="zsh"
;;
"*bash*")
if [[ $os_type == "Darwin" ]]; then
shell_profile_file="$HOME/.profile"
fi
;;
esac
}
26 changes: 26 additions & 0 deletions util/package-manager.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

function install() {
if [ $os_variant == "osx" ]; then
brew install $*
elif [ $os_variant == "ubuntu" || $os_variant == "debian" ]; then
sudo apt install -y $*
elif [ $os_variant == "centos" || $os_variant == "rocky" || $os_variant == "fedora" ]; then
sudo dnf install -y $*
elif [ $os_variant == "openSUSE" ]; then
sudo zypper install -y $*
else
echo "OS distribution not supported"
exit 1
fi
}

function update() {

}

function upgrade() {

}

echo "Detected Linux distribution: $os_variant"
17 changes: 1 addition & 16 deletions util/variables.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
function install() {
if [ $os_variant == "osx" ]; then
brew install $*
elif [ $os_variant == "ubuntu" || $os_variant == "debian" ]; then
sudo apt install -y $*
elif [ $os_variant == "centos" || $os_variant == "rocky" || $os_variant == "fedora" ]; then
sudo dnf install -y $*
elif [ $os_variant == "opensuse" ]; then
sudo zypper install -y $*
else
echo "OS distribution not supported"
exit 1
fi
}

echo "Detected Linux distribution: $os_variant"
#!/bin/bash
6 changes: 6 additions & 0 deletions windows/dev-tool-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Write-Output "Installing Mozilla Firefox Developer Edition"
winget install --id=Mozilla.Firefox.DeveloperEdition -e
Write-Output "Installing Github Packages"
winget install --id=Git.Git -e ; winget install --id=GitHub.cli -e ; winget install --id=GitHub.GitHubDesktop -e
Write-Output "Installing Extra package"
winget install --id=Microsoft.WindowsTerminal -e
2 changes: 2 additions & 0 deletions windows/docker-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Write-Output "Installing Docker Desktop"
winget install docker
4 changes: 4 additions & 0 deletions windows/essential-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Write-Output "Setup permission elevation package"
winget install --id=gsudo gerardog.gsudo -e
Write-Output "Installing Notepad Plus Plus"
winget install --id=Notepad++.Notepad++ -e
6 changes: 6 additions & 0 deletions windows/ide-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Write-Output "Installing VsCode"
winget install vscode
Write-Output "Installing Microsoft Visual Studio 2022"
winget install --id=Microsoft.VisualStudio.2022.Community-Preview -e
Write-Output "Installing Dev frameworks.."
winget install --id= Microsoft.DotNet.SDK.7 -e winget install --id=Microsoft.DotNet.SDK.Preview -e ; winget install --id=OpenJS.NodeJS.LTS -e
10 changes: 10 additions & 0 deletions windows/winget-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Winget stup for windows
if ((Get-ComputerInfo | Select-Object -expand OsName) -match 10) {
Write-Output "Starting Winget setup"
Invoke-WebRequest https://github.com/microsoft/winget-cli/releases/download/v1.6.1573-preview/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile ./winget.msixbundle
Add-AppPackage -path ./winget.msixbundle
Remove-Item ./winget.msixbundle
}
else {
Install-Module -Name Microsoft.WinGet.Client -Force -AllowPrerelease -AcceptLicense
}
13 changes: 13 additions & 0 deletions windows/wsl-setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Write-Output "Setting up Windows Linux SubSystem..."
Enable-WindowsOptionalFeature -Online -FeatureName 'Microsoft-Windows-Subsystem-Linux' -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform' -All -NoRestart
wsl --update
wsl --set-default-version 2

Invoke-WebRequest https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi -OutFile ./wsl-kernel.msi
Write-Output "Starting WSL kernel installation..."
Start-Process ./wsl-kernel.msi -ArgumentList "/quiet /passive"
Remove-Item ./wsl-kernel.msi

Write-Output "Installing Ubuntu image.."
wsl --install Ubuntu

0 comments on commit 5da0493

Please sign in to comment.