2020-09-17 10:24:35 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
ROOT=$(readlink -f $(dirname "${BASH_SOURCE[0]}"))
|
|
|
|
PM=n/a
|
2020-09-17 16:02:24 +00:00
|
|
|
DEFAULT_SHELL=$(getent passwd $USER | cut -d: -f7)
|
|
|
|
FISH=$(which fish)
|
2020-09-19 15:33:13 +00:00
|
|
|
XDG_CONFIG_HOME=${XDG_CONFIG_HOME-"$HOME/.config"}
|
2020-09-17 10:24:35 +00:00
|
|
|
|
|
|
|
if which pacman > /dev/null; then
|
|
|
|
PM=pacman
|
|
|
|
elif which apt > /dev/null; then
|
|
|
|
PM=apt
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$PM" = "n/a" ]; then
|
|
|
|
echo "Unsupported Package Manager"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
|
|
|
|
in-china () {
|
|
|
|
if [ -z "$IS_CHINA" ]; then
|
|
|
|
IS_CHINA=no
|
|
|
|
if curl -q myip.ipip.net | grep '中国' > /dev/null; then
|
|
|
|
IS_CHINA=yes
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
[ "$IS_CHINA" = "no" ] && return -1
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-09-17 10:40:17 +00:00
|
|
|
lnsf () {
|
2020-09-19 15:33:13 +00:00
|
|
|
[ "$#" -ne 2 ] && echo "lnsf <target> <symlink>" && return -1
|
|
|
|
local TARGET=$(readlink -f $1)
|
|
|
|
local SYMLNK=$2
|
|
|
|
[ -z "$TARGET" ] && echo "$1 not exists" && return -1
|
|
|
|
local SYMDIR=$(dirname $SYMLNK)
|
|
|
|
if [ -n "$SYMDIR" ] && [ -L $SYMDIR ]; then
|
|
|
|
rm -rf $SYMDIR
|
|
|
|
mkdir -p $SYMDIR
|
2020-09-18 18:01:58 +00:00
|
|
|
fi
|
2020-09-19 15:33:13 +00:00
|
|
|
[ ! -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
|
|
|
|
|
|
|
fish-is-default-shell () {
|
|
|
|
[ "$DEFAULT_SHELL" = "$FISH" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
local VERSION_PATH=$1
|
|
|
|
local VERSION=$2
|
|
|
|
[ ! -f $VERSION_PATH ] && return -1
|
|
|
|
local VERSION2=$(cat "$VERSION_PATH")
|
|
|
|
[ "$VERSION" = "$VERSION2" ]
|
|
|
|
}
|
|
|
|
|
2020-09-17 16:02:24 +00:00
|
|
|
|
|
|
|
# install basic common utilities
|
|
|
|
case "$PM" in
|
|
|
|
apt)
|
|
|
|
sudo apt install \
|
|
|
|
build-essential \
|
|
|
|
unzip p7zip \
|
|
|
|
openssh-server openssh-client \
|
|
|
|
exfat-utils \
|
|
|
|
axel \
|
|
|
|
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 \
|
|
|
|
exfat-utils \
|
|
|
|
axel \
|
|
|
|
man sudo
|
|
|
|
;;
|
2020-09-18 04:16:15 +00:00
|
|
|
esac
|
2020-09-19 15:33:13 +00:00
|
|
|
|