2020-11-02 04:08:18 +00:00
|
|
|
#!/bin/sh
|
2020-09-17 10:24:35 +00:00
|
|
|
|
2020-11-08 06:05:21 +00:00
|
|
|
set -e
|
2020-11-21 18:07:26 +00:00
|
|
|
[ "$ENVSHED" = "yes" ] && return
|
|
|
|
ENVSHED=yes
|
2020-09-17 10:24:35 +00:00
|
|
|
PM=n/a
|
2020-09-19 15:33:13 +00:00
|
|
|
XDG_CONFIG_HOME=${XDG_CONFIG_HOME-"$HOME/.config"}
|
2020-11-08 16:26:14 +00:00
|
|
|
PREFIX=/usr/local
|
2020-11-08 06:05:21 +00:00
|
|
|
PDIR=$(dirname "${DIR-$0}")
|
2020-11-08 16:26:14 +00:00
|
|
|
GITHUB_PROXY=${GITHUB_PROXY-$HTTPS_PROXY}
|
2021-08-26 13:13:36 +00:00
|
|
|
WSL=$(grep -i Microsoft /proc/sys/kernel/osrelease || true)
|
2020-11-08 16:26:14 +00:00
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
in_china() {
|
2021-01-15 07:54:40 +00:00
|
|
|
! [ -f /tmp/myip_full ] && curl -s myip.ipip.net > /tmp/myip_full
|
|
|
|
grep -qF '中国' /tmp/myip_full
|
2020-09-17 10:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
lnsf() {
|
2020-11-02 04:08:18 +00:00
|
|
|
[ "$#" -ne 2 ] && echo "lnsf <target> <symlink>" && return 1
|
2020-11-08 16:57:55 +00:00
|
|
|
TARGET=$(readlink -f "$1") || (echo failed: readlink -f "$1" ; return 1)
|
2020-11-02 04:08:18 +00:00
|
|
|
SYMLNK=$2
|
|
|
|
[ -z "$TARGET" ] && echo "$1 not exists" && return 1
|
|
|
|
SYMDIR=$(dirname "$SYMLNK")
|
2020-11-04 02:48:02 +00:00
|
|
|
if [ -n "$SYMDIR" ] && [ -L "$SYMDIR" ]; then
|
2020-11-02 04:08:18 +00:00
|
|
|
rm -rf "$SYMDIR"
|
2020-09-18 18:01:58 +00:00
|
|
|
fi
|
2020-11-02 04:08:18 +00:00
|
|
|
mkdir -p "$SYMDIR"
|
|
|
|
[ ! -L "$SYMLNK" ] && rm -rf "$SYMLNK"
|
|
|
|
ln -sf "$TARGET" "$SYMLNK"
|
2020-09-17 10:24:35 +00:00
|
|
|
}
|
2020-09-17 16:02:24 +00:00
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
has_bluetooth() {
|
2021-08-26 14:39:30 +00:00
|
|
|
sudo dmesg | grep -i bluetooth
|
2020-09-17 16:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
eqv() {
|
2020-11-02 04:08:18 +00:00
|
|
|
VERSION_PATH=$1
|
|
|
|
VERSION=$2
|
|
|
|
[ ! -f "$VERSION_PATH" ] && return 1
|
|
|
|
VERSION2="$(cat "$VERSION_PATH")"
|
2020-09-19 15:33:13 +00:00
|
|
|
[ "$VERSION" = "$VERSION2" ]
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
git_clone() {
|
|
|
|
mkdir -p "$(dirname "$2")"
|
|
|
|
[ -d "$2" ] && return
|
2020-11-23 02:00:49 +00:00
|
|
|
if echo "$1" | grep -qF 'github.com'; then
|
2021-06-27 07:32:49 +00:00
|
|
|
HTTPS_PROXY=$GITHUB_PROXY git clone --depth 1 "$@"
|
2020-11-23 02:00:49 +00:00
|
|
|
else
|
2021-06-27 07:32:49 +00:00
|
|
|
git clone --depth 1 "$@"
|
2020-11-23 02:00:49 +00:00
|
|
|
fi
|
2020-11-21 18:07:26 +00:00
|
|
|
}
|
|
|
|
|
2020-11-08 16:26:14 +00:00
|
|
|
intorepo() {
|
|
|
|
ODIR=$(pwd)
|
|
|
|
REPO=$2
|
2020-11-21 18:07:26 +00:00
|
|
|
git_clone "$1" "$REPO"
|
|
|
|
cd "$REPO"
|
2020-11-08 16:26:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exitrepo() {
|
|
|
|
cd "$ODIR"
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
log() {
|
|
|
|
printf "\n\033[32m%s\033[0m\n" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
has_cmd() {
|
|
|
|
command -v "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
has_fish() {
|
|
|
|
has_cmd "$1"
|
|
|
|
}
|
|
|
|
|
2020-11-23 07:54:48 +00:00
|
|
|
enhance_vim() {
|
|
|
|
[ "$VIM_MODE" = "enhanced" ] && has_cmd nvim
|
|
|
|
}
|
|
|
|
|
2021-01-15 07:42:29 +00:00
|
|
|
pm_update() {
|
|
|
|
# skip updation on daily basis
|
|
|
|
TSFILE=/tmp/apt_updated_at_$(date +%Y%m%d)
|
2021-01-17 07:30:01 +00:00
|
|
|
CHECKSUM=$(md5sum /etc/apt/sources.list /etc/apt/sources.list.d/*.list | sort | md5sum)
|
2021-01-15 07:42:29 +00:00
|
|
|
grep -qF "$CHECKSUM" "$TSFILE" && return
|
|
|
|
case "$PM" in
|
|
|
|
apt)
|
|
|
|
sudo apt update
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unsupported os"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo "$CHECKSUM" > "$TSFILE"
|
|
|
|
}
|
|
|
|
|
2021-08-03 03:51:50 +00:00
|
|
|
win_env_path() {
|
|
|
|
cmd.exe /c 'echo '$1 2>/dev/null | awk '{sub("C:", "/mnt/c"); gsub("\\\\","/"); print}'
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
|
|
|
|
sudo mkdir -p $PREFIX
|
|
|
|
|
|
|
|
if has_cmd pacman; then
|
|
|
|
PM=pacman
|
|
|
|
elif has_cmd apt; then
|
|
|
|
PM=apt
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PM" = "n/a" ]; then
|
|
|
|
echo "Unsupported Package Manager"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-01-17 07:30:01 +00:00
|
|
|
if [ -f /etc/lsb-release ]; then
|
|
|
|
set -a
|
|
|
|
. /etc/lsb-release
|
|
|
|
set +a
|
|
|
|
export DISTRIB_RELEASE_MAJOR=${DISTRIB_RELEASE%.*}
|
|
|
|
export DISTRIB_RELEASE_MINOR=${DISTRIB_RELEASE#.*}
|
|
|
|
fi
|
2020-09-17 16:02:24 +00:00
|
|
|
|
2020-11-21 18:07:26 +00:00
|
|
|
log "Environments"
|
|
|
|
echo " PM : $PM"
|
|
|
|
echo " DIR : $DIR"
|
|
|
|
echo " PDIR : $PDIR"
|
|
|
|
echo " PREFIX : $PREFIX"
|
|
|
|
echo " GITHUB_PROXY : $GITHUB_PROXY"
|