Last active
January 2, 2024 02:49
-
-
Save xiaojueguan/14fa256c31fcaee8012eafac2cbcb9d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pmt='apt' | |
pkgs=('python3-pip') | |
# Check the distribution | |
if [[ -f /etc/os-release ]]; then | |
source /etc/os-release | |
if [[ -n "$PRETTY_NAME" ]]; then | |
echo "Distribution: $PRETTY_NAME" | |
# Check specific distributions | |
if [[ "$ID" == "ubuntu" ]]; then | |
echo "Perform actions for Ubuntu" | |
pmt='apt' | |
# Actions specific to Ubuntu | |
elif [[ "$ID" == "centos" ]]; then | |
echo "Perform actions for CentOS" | |
pmt='yum' | |
# Actions specific to CentOS | |
elif [[ "$ID" == "fedora" ]]; then | |
echo "Perform actions for Fedora" | |
pmt='dnf' | |
# Actions specific to Fedora | |
else | |
echo "Perform default actions for other Linux distributions" | |
# Default actions for other Linux distributions | |
fi | |
fi | |
else | |
exit 1 | |
fi | |
for pkg in "${pkgs[@]}"; do | |
$pmt install -y $pkg | |
done | |
# List of servers | |
servers=("mirrors.aliyun.com" "pypi.org") | |
# Initialize minimum latency as a very large number | |
min_latency=1000000 | |
min_server="" | |
# Loop through all servers | |
for server in ${servers[@]}; do | |
# Ping the server and get the average latency | |
latency=$(ping -c 4 $server | tail -1| awk '{print $4}' | cut -d '/' -f 2) | |
# Check if the latency is less than the minimum latency | |
if (( $(echo "$latency < $min_latency" | bc -l) )); then | |
min_latency=$latency | |
min_server=$server | |
fi | |
done | |
# Print the server with the minimum latency | |
echo "The server with the minimum latency is $min_server with a latency of $min_latency ms" | |
if [ min_server == "pypi.org" ]; then | |
index_url="https://${min_server}/simple/" | |
else | |
index_url="https://${min_server}/pypi/simple/" | |
fi | |
mkdir -p ~/.pip | |
cat > ~/.pip/pip.conf << EOF | |
[global] | |
trusted-host=${min_server} | |
index-url=${index_url} | |
EOF | |
pip_pkgs=('virtualenv', 'virtualenvwrapper') | |
for pkg in "${pip_kgs[@]}"; do | |
pip install $pkg | |
done | |
cat <<EOF>> ~/.bashrc | |
export VIRTUALENVWRAPPER_PYTHON=$(which python3) | |
source virtualenvwrapper.sh | |
EOF | |
source ~/.bashrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget 'https://gist.githubusercontent.com/xiaojueguan/14fa256c31fcaee8012eafac2cbcb9d2/raw/31c246ced2cdf8e59a44000513c765b3032b6735/install_virtualenvwrapper.sh' -O - | bash -