forked from ToyoDAdoubiBackup/doubi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libsodium.sh
82 lines (78 loc) · 2.95 KB
/
libsodium.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: CentOS/Debian/Ubuntu
# Description: Libsodium Install
# Version: 1.0.0
# Author: Toyo
# Blog: https://doub.io/shell-jc6/
#=================================================
Libsodiumr_file="/usr/local/lib/libsodium.so"
Libsodiumr_ver_backup="1.0.15"
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Info="${Green_font_prefix}[信息]${Font_color_suffix}" && Error="${Red_font_prefix}[错误]${Font_color_suffix}" && Tip="${Green_font_prefix}[注意]${Font_color_suffix}"
Check_Libsodium_ver(){
echo -e "${Info} 开始获取 libsodium 最新版本..."
Libsodiumr_ver=$(wget -qO- "https://github.com/jedisct1/libsodium/tags"|grep "/jedisct1/libsodium/releases/tag/"|head -1|sed -r 's/.*tag\/(.+)\">.*/\1/')
[[ -z ${Libsodiumr_ver} ]] && Libsodiumr_ver=${Libsodiumr_ver_backup}
echo -e "${Info} libsodium 最新版本为 ${Green_font_prefix}[${Libsodiumr_ver}]${Font_color_suffix} !"
}
Install_Libsodium(){
if [[ -e ${Libsodiumr_file} ]]; then
echo -e "${Error} libsodium 已安装 , 是否覆盖安装(或者更新)?[y/N]"
read -e -p "(默认: n):" yn
[[ -z ${yn} ]] && yn="n"
if [[ ${yn} == [Nn] ]]; then
echo "已取消..." && exit 1
fi
else
echo -e "${Info} libsodium 未安装,开始安装..."
fi
Check_Libsodium_ver
if [[ ${release} == "centos" ]]; then
yum update
echo -e "${Info} 安装依赖..."
yum -y groupinstall "Development Tools"
echo -e "${Info} 下载..."
wget --no-check-certificate -N "https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz"
echo -e "${Info} 解压..."
tar -xzf libsodium-${Libsodiumr_ver}.tar.gz
cd libsodium-${Libsodiumr_ver}
echo -e "${Info} 编译安装..."
./configure --disable-maintainer-mode
make -j2
make install
echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
else
apt-get update
echo -e "${Info} 安装依赖..."
apt-get install -y build-essential
echo -e "${Info} 下载..."
wget --no-check-certificate -N "https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz"
echo -e "${Info} 解压..."
tar -xzf libsodium-${Libsodiumr_ver}.tar.gz
cd libsodium-${Libsodiumr_ver}
echo -e "${Info} 编译安装..."
./configure --disable-maintainer-mode
make -j2
make install
fi
ldconfig
cd ..
rm -rf libsodium-${Libsodiumr_ver}.tar.gz
rm -rf libsodium-${Libsodiumr_ver}
[[ ! -e ${Libsodiumr_file} ]] && echo -e "${Error} libsodium 安装失败 !" && exit 1
echo && echo -e "${Info} libsodium 安装成功 !" && echo
}
action=$1
[[ -z $1 ]] && action=install
case "$action" in
install)
Install_Libsodium
;;
*)
echo "输入错误 !"
echo "用法: [ install ]"
;;
esac