Skip to content

Instantly share code, notes, and snippets.

@eplord
Forked from weehongkoh/README.md
Created July 13, 2023 15:14
Show Gist options
  • Select an option

  • Save eplord/ebfbd52461308dfc284a9fc932913c8d to your computer and use it in GitHub Desktop.

Select an option

Save eplord/ebfbd52461308dfc284a9fc932913c8d to your computer and use it in GitHub Desktop.
Download Latest Zsh, Go and Python Package With Bash Script
# Download ZSH
bash -c "$(curl -fsSL https://gist.githubusercontent.com/weehongayden/e56d8161fa47e3ac8416ad8340ee3f82/raw/ff75af227e14b5301c0830abb50e21e6d3e95c3f/zsh_installer.sh)"
# Download Latest Go
bash -c "$(curl -fsSL https://gist.githubusercontent.com/weehongayden/e56d8161fa47e3ac8416ad8340ee3f82/raw/0d3a20a82afe98e84efdac3d775c8d4b2b565145/go_installer.sh)"
# Download Latest Python 3
bash -c "$(curl -fsSL https://gist.githubusercontent.com/weehongayden/e56d8161fa47e3ac8416ad8340ee3f82/raw/0f5baaa1cade757f54ca6a9f0fd6fb01e6db73de/python_installer.sh)"
#!/bin/bash
os="$(uname -s)"
arch="$(uname -m)"
case $os in
"Linux")
os=linux
;;
"Darwin")
os=darwin
;;
esac
case $arch in
"x86_64")
arch="amd64"
;;
"386")
arch="386"
;;
esac
if [ -z "$GOPATH" ]; then
echo "Please provide GOPATH: (Default: $HOME/go)"
read go_path
[ -z "$go_path" ] && go_path="$HOME/go"
else
go_path=$GOPATH
fi
echo "Checking Shell Type ..."
if [ $SHELL == "/bin/zsh" ] || [ $SHELL == "/usr/bin/zsh" ]; then
shell="$HOME/.zshrc"
shell_name=zsh
else
shell="$HOME/.bashrc"
shell_name=bash
fi
echo -e "Active Shell Type: $shell_name\n"
# Extract the latest Golang version
echo "Fetching the latest Go version ..."
http_response=$(curl -s -w "\n%{http_code}" https://go.dev/VERSION\?m=text)
go_version=$(echo "$http_response" | sed -E 's/[0-9]{3}$//')
go_package="$go_version.$os-$arch.tar.gz"
echo -e "Version detected: $go_version\n"
echo "Downloading Go package in silent mode ..."
(cd ~ && curl -sOL "https://go.dev/dl/$go_package")
echo -e "Download Completed\n"
echo "Remove existing Go package and replace with the latest version"
(cd ~ &&
sudo rm -rf /usr/local/go &&
sudo tar -C /usr/local -xzf $go_package &&
sudo rm -rf $go_package)
echo -e "Installation completed\n"
echo "Add GOPATH to $shell"
if grep -q GOPATH= "$shell"; then
sed -i "s/^\(export GOPATH=\).*$/\1${go_path//\//\\/}/" "$shell"
else
{
if [[ "$(tail -n 1 "$shell")" != "" && ! "$(tail -n 1 "$shell")" =~ ^\# ]]; then
echo ""
fi
echo 'export PATH=$PATH:/usr/local/go/bin'
echo "export GOPATH=$go_path"
} >> "$shell"
fi
echo "Check if src, pkg and bin directories exist under GOPATH"
is_exists=false
directories=("$GOPATH/src" "$GOPATH/pkg" "$GOPATH/bin")
for dir in "${directories[@]}"; do
if [ ! -d "$dir" ]; then
is_exists=false
break
else
is_exists=true
fi
done
if [ "$is_exists" = false ]; then
echo "The src, pkg and bin directories does not exist under GOPATH"
read -p "Do you wish to create src, pkg and bin under GOPATH? [y/N] " yn
case $yn in
y | Y)
echo "Creating src, pkg and bin directories under GOPATH"
eval mkdir -p $go_path/{src,pkg,bin}
;;
n | N) exit ;;
*)
echo invalid response
exit 1
;;
esac
fi
echo -e 'Directories has been created under $GOPATH\n';
echo "Reload $shell_name"
exec $shell_name
echo "Script executed successfully"
#!/bin/bash
# Checking Shell
if [ -n "echo $ZSH_VERSION" ]; then
shell_profile="$HOME/.zshrc"
elif [ -n "echo $BASH_VERSION" ]; then
shell_profile="$HOME/.bashrc"
elif [ -n "echo $FISH_VERSION" ]; then
shell="fish"
if [ -d "$XDG_CONFIG_HOME" ]; then
shell_profile="$XDG_CONFIG_HOME/fish/config.fish"
else
shell_profile="$HOME/.config/fish/config.fish"
fi
fi
# Install all the require packages
echo "Install require package"
sudo apt-get install wget build-essential zlib1g-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev -y
# Extract the latest Python version
RESPONSE_BODY=$(curl -s -w "\n%{http_code}" https://python-version-scraper.onrender.com/python-stable)
PYTHON_VERSION=$(echo "$RESPONSE_BODY" | sed -E 's/[0-9]{3}$//')
# Download Python3
echo "Download Python3"
(cd ~ && curl -OL "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz")
EXTRACT_VERSION=${PYTHON_VERSION%.*}
# Installing Python3
echo "Installing Python3"
(cd ~ \
&& tar -xvf Python-$PYTHON_VERSION.tgz \
&& cd Python-$PYTHON_VERSION \
&& ./configure --with-ensurepip=install \
&& make -j8 \
&& sudo make install \
&& alias python3="python$EXTRACT_VERSION" \
&& alias python="python$EXTRACT_VERSION" \
&& cd ~ \
&& rm -rf Python-$PYTHON_VERSION.tgz Python-$PYTHON_VERSION)
# Checking Shell
echo "Checking Shell"
if [ -n "echo $ZSH_VERSION" ]; then
shell_profile="$HOME/.zshrc"
elif [ -n "echo $BASH_VERSION" ]; then
shell_profile="$HOME/.bashrc"
elif [ -n "echo $FISH_VERSION" ]; then
shell="fish"
if [ -d "$XDG_CONFIG_HOME" ]; then
shell_profile="$XDG_CONFIG_HOME/fish/config.fish"
else
shell_profile="$HOME/.config/fish/config.fish"
fi
fi
echo "Configuring shell profile in: $shell_profile"
touch "$shell_profile"
if [ "$shell" == "fish" ]; then
{
echo '# Python'
echo "alias python3=python$EXTRACT_VERSION"
echo "alias python=python$EXTRACT_VERSION"
} >> "$shell_profile"
else
{
echo '# Python'
echo "alias python3=python$EXTRACT_VERSION"
echo "alias python=python$EXTRACT_VERSION"
} >> "$shell_profile"
fi
# Install Python3 PIP
echo "Installing Python3 PIP"
python3 -m pip install --upgrade pip
gp="git push"
gb="git branch"
gc="git checkout"
ns="npm start"
npmlogs='rm -rf ~/.npm/logs/*'
#!/bin/bash
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install libncurses5-dev -y
RESPONSE_BODY=$(curl -s -w "\n%{http_code}" https://zsh-version-scraper.onrender.com/zsh-version)
version=$(echo "$RESPONSE_BODY" | sed -E 's/[0-9]{3}$//')
url=https://sourceforge.net/projects/zsh/files/zsh/${version}/zsh-${version}.tar.xz/download
curl -L $url > "zsh-${version}.tar.xz"
if ! command -v make &> /dev/null; then
echo "make command not found. Downloading..."
sudo apt-get install build-essential -y
fi
tar -xvf "zsh-${version}.tar.xz" -C zsh &&
cd "zsh/zsh-${version}" &&
./configure &&
make &&
sudo make install
zsh_path=$(which zsh)
chsh -s "$zsh_path"
exec zsh -l
echo "System Message: Kindly restart your terminal to switch to the ZSH Shell. Thank you."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment