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-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}
|
2020-11-04 06:05:09 +00:00
|
|
|
echo "dir: $DIR"
|
|
|
|
echo "parent dir: $PDIR"
|
2020-11-08 16:26:14 +00:00
|
|
|
echo "prefix dir: $PREFIX"
|
|
|
|
|
|
|
|
sudo mkdir -p $PREFIX
|
2020-09-17 10:24:35 +00:00
|
|
|
|
2020-11-02 04:08:18 +00:00
|
|
|
if command -v pacman > /dev/null; then
|
2020-09-17 10:24:35 +00:00
|
|
|
PM=pacman
|
2020-11-02 04:08:18 +00:00
|
|
|
elif command -v apt > /dev/null; then
|
2020-09-17 10:24:35 +00:00
|
|
|
PM=apt
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PM" = "n/a" ]; then
|
|
|
|
echo "Unsupported Package Manager"
|
2020-11-02 04:08:18 +00:00
|
|
|
exit 1
|
2020-09-17 10:24:35 +00:00
|
|
|
fi
|
|
|
|
|
2020-11-02 04:08:18 +00:00
|
|
|
in_china () {
|
2020-09-17 10:24:35 +00:00
|
|
|
if [ -z "$IS_CHINA" ]; then
|
|
|
|
IS_CHINA=no
|
|
|
|
if curl -q myip.ipip.net | grep '中国' > /dev/null; then
|
|
|
|
IS_CHINA=yes
|
|
|
|
fi
|
|
|
|
fi
|
2020-11-02 04:08:18 +00:00
|
|
|
[ "$IS_CHINA" = "no" ] && return 1
|
2020-09-17 10:24:35 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:40:17 +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-02 04:08:18 +00:00
|
|
|
has_bluetooth () {
|
2020-09-18 04:16:15 +00:00
|
|
|
dmesg | grep -i bluetooth
|
2020-09-17 16:02:24 +00:00
|
|
|
}
|
|
|
|
|
2020-09-19 15:33:13 +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-08 16:26:14 +00:00
|
|
|
intorepo() {
|
|
|
|
ODIR=$(pwd)
|
|
|
|
REPO=$2
|
|
|
|
if [ ! -d "$REPO" ]; then
|
|
|
|
HTTPS_PROXY=$GITHUB_PROXY git clone --depth 1 "$1" "$REPO"
|
|
|
|
cd "$REPO"
|
|
|
|
else
|
|
|
|
cd "$REPO"
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
exitrepo() {
|
|
|
|
cd "$ODIR"
|
|
|
|
}
|
|
|
|
|
2020-09-17 16:02:24 +00:00
|
|
|
|
|
|
|
# install basic common utilities
|
|
|
|
case "$PM" in
|
|
|
|
apt)
|
|
|
|
sudo apt install \
|
|
|
|
build-essential \
|
|
|
|
unzip p7zip \
|
2020-10-29 06:23:39 +00:00
|
|
|
openssh-client \
|
2020-10-30 19:21:28 +00:00
|
|
|
curl wget \
|
2020-09-17 16:02:24 +00:00
|
|
|
man sudo
|
|
|
|
;;
|
|
|
|
pacman)
|
2020-09-18 18:01:58 +00:00
|
|
|
sudo pacman -S --needed --needed \
|
2020-09-17 16:02:24 +00:00
|
|
|
base-devel \
|
|
|
|
unzip p7zip \
|
|
|
|
openssh \
|
2020-10-30 19:21:28 +00:00
|
|
|
curl wget \
|
2020-09-17 16:02:24 +00:00
|
|
|
man sudo
|
2020-09-22 16:22:08 +00:00
|
|
|
# install yay
|
2020-11-02 04:08:18 +00:00
|
|
|
if ! command -v yay; then
|
2020-09-22 16:22:08 +00:00
|
|
|
git clone --depth 1 https://aur.archlinux.org/yay.git /tmp/yay
|
|
|
|
cd /tmp/yay
|
|
|
|
makepkg -si
|
|
|
|
cd -
|
|
|
|
fi
|
2020-09-17 16:02:24 +00:00
|
|
|
;;
|
2020-09-18 04:16:15 +00:00
|
|
|
esac
|
2020-09-19 15:33:13 +00:00
|
|
|
|