lazy/utils.sh
2023-10-25 14:36:22 +08:00

59 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
git_clone() {
local repo=$1
local dir=$2
if [ ! -d "$dir" ]; then
if [ "$3" = "--depth=1" ]; then
git clone --depth=1 "$github/$repo" $dir
elif [ "$3" = "--norecursive" ]; then
git clone --single-branch "$github/$repo" $dir
else
git clone --single-branch --recursive "$github/$repo" $dir
fi
fi
}
check_google_access() {
abroad=0
local response=$(curl -s -o /dev/null -w "%{http_code}" -m 5 "http://www.google.com")
if [ "$response" -eq 200 ]; then
abroad=1
echo "Internet: abroad"
github="https://github.com"
else
abroad=0
echo "Internet: internal"
github="https://g.nano.ac/https://github.com"
fi
}
update_file() {
local A="$1"
local B="$2"
if [ -f "$A" ] && [ -f "$B" ] && [ "$(cat "$A")" != "$(cat "$B")" ]; then
cp "$A" "$B"
echo "File $B has been updated."
fi
}
confirm_action() {
local prompt="$1"
local default_response="$2"
read -p "$prompt [$default_response]: " response
if [[ -z "$response" ]]; then
response="$default_response"
fi
[[ $response =~ ^[Yy]$ ]]
}
# ============================================================
check_google_access