171 lines
4.1 KiB
Bash
Executable File
171 lines
4.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
ROOT_PATH=$(cd "$(dirname ${0})";pwd)
|
|
CFG_VERSION=${1}
|
|
|
|
if [[ ! -n ${CFG_VERSION} ]]; then
|
|
CFG_VERSION="9.6.1"
|
|
fi
|
|
|
|
#discription:SunloginClient9.6.1
|
|
install_path="/opt/sunlogin"
|
|
script_path="${install_path}/sunloginclient/scripts"
|
|
version="SunloginClient9.6.1"
|
|
download_url="http://download.oray.com/sunlogin/linux/${version}.tar.gz"
|
|
desktop_restart_service="/usr/share/applications/sunlogin-restart.desktop"
|
|
desktop_stop_service="/usr/share/applications/sunlogin-stop.desktop"
|
|
user_name="smart"
|
|
user_home_path="/home/smart/桌面/"
|
|
|
|
#color
|
|
red='\033[0;31m'
|
|
green='\033[0;32m'
|
|
yellow='\033[0;33m'
|
|
plain='\033[0m'
|
|
|
|
#安装目录
|
|
create_documoent(){
|
|
mkdir $install_path
|
|
cd $install_path
|
|
}
|
|
|
|
#下载文件
|
|
function download_file(){
|
|
wget $download_url
|
|
tar -zxf ./${version}.tar.gz
|
|
cd ${install_path}/sunloginclient
|
|
echo "Download is ok!"
|
|
}
|
|
|
|
#桌面快捷方式
|
|
function desktop_file(){
|
|
touch ${desktop_restart_service}
|
|
chmod 777 ${desktop_restart_service}
|
|
cat > "${desktop_restart_service}" <<EOF
|
|
#!/usr/bin/env xdg-open
|
|
[Desktop Entry]
|
|
Name=sunlogin_restart
|
|
Name[zh_CN]=向日葵重启
|
|
Comment= run sunlogin
|
|
Exec=${script_path}/sudo_restart.sh
|
|
Terminal=true
|
|
Type=Application
|
|
EOF
|
|
ln -s ${desktop_restart_service} ${user_home_path}
|
|
}
|
|
|
|
function stop_service_file(){
|
|
touch ${desktop_stop_service}
|
|
chmod 777 ${desktop_stop_service}
|
|
cat > "${desktop_stop_service}" <<EOF
|
|
#!/usr/bin/env xdg-open
|
|
[Desktop Entry]
|
|
Name=sunlogin_stop
|
|
Name[zh_CN]=向日葵停止
|
|
Comment= run sunlogin
|
|
Exec=${script_path}/sudo_stop.sh
|
|
Terminal=true
|
|
Type=Application
|
|
EOF
|
|
ln -s ${desktop_stop_service} ${user_home_path}
|
|
}
|
|
|
|
#重启文件
|
|
function sudo_restart_file(){
|
|
cd ${script_path}
|
|
touch sudo_restart.sh
|
|
chmod 777 sudo_restart.sh
|
|
cat > "sudo_restart.sh" <<EOF
|
|
#!/bin/bash
|
|
sudo sh ${script_path}/stop.sh
|
|
sudo sh ${script_path}/start.sh
|
|
EOF
|
|
}
|
|
|
|
#停止文件
|
|
function sudo_stop_file(){
|
|
cd ${script_path}
|
|
touch sudo_stop.sh
|
|
chmod 777 sudo_stop.sh
|
|
cat > "sudo_stop.sh" <<EOF
|
|
#!/bin/bash
|
|
sudo sh ${script_path}/stop.sh
|
|
EOF
|
|
}
|
|
|
|
|
|
#安装
|
|
function install_script(){
|
|
if [[ -d ${install_path} ]]
|
|
then
|
|
echo "${install_path} is existed, please uninstall!"
|
|
exit 1
|
|
else
|
|
sed -i "2a $user_name ALL=(root) NOPASSWD:/bin/sh" /etc/sudoers
|
|
create_documoent
|
|
download_file
|
|
\cp ${ROOT_PATH}/install.sh ${install_path}/sunloginclient/install.sh
|
|
sudo_restart_file
|
|
sudo_stop_file
|
|
desktop_file
|
|
stop_service_file
|
|
sh ${install_path}/sunloginclient/install.sh
|
|
writeSunVersion
|
|
reportConnectionCodes
|
|
echo "================================================================="
|
|
echo "Please visit http://<this machine ip>:30080 to configure remote client!"
|
|
echo "================================================================="
|
|
fi
|
|
}
|
|
|
|
#卸载
|
|
function uninstall(){
|
|
if [[ -d ${install_path} ]]
|
|
then
|
|
echo "${install_path} is existed"
|
|
sh ${script_path}/uninstall.sh
|
|
sed -i '3d' /etc/sudoers
|
|
rm -rf ${install_path}
|
|
rm -f ${desktop_restart_service}
|
|
rm -f ${desktop_stop_service}
|
|
rm -f ${user_home_path}/sunlogin-restart.desktop
|
|
rm -f ${user_home_path}/sunlogin-stop.desktop
|
|
echo "Uninstall is ok!"
|
|
else
|
|
echo "${install_path} is not exist"
|
|
fi
|
|
}
|
|
|
|
#重新安装
|
|
function reinstall(){
|
|
uninstall
|
|
install_script
|
|
}
|
|
|
|
#上报访问信息
|
|
reportConnectionCodes()
|
|
{
|
|
#尝试6次
|
|
try=6
|
|
while [[ ${try} -ge 0 ]]; do
|
|
sleep 10
|
|
REPORT=$(curl -sS http://localhost:30080 | grep 'Quick Code')
|
|
if [[ -n ${REPORT} ]]; then
|
|
quick_code=$(echo ${REPORT} | awk -F ': ' '{print $2}' | awk -F '<' '{print $1}')
|
|
security_code=$(echo ${REPORT} | awk -F ': ' '{print $3}' | awk -F '<' '{print $1}')
|
|
hostname=$(hostname)
|
|
echo "Follow up writing: quick_code is ${quick_code},security_code is ${security_code}"
|
|
# 回访写入
|
|
curl -sS -D /dev/null -o /dev/null -H "hostname:${hostname}" "http://c.baobaot.com/api/software/report_sunlogin_codes?quick_code=${quick_code}&security_code=${security_code}"
|
|
break
|
|
fi
|
|
try=$[${try} - 1]
|
|
done
|
|
}
|
|
|
|
writeSunVersion()
|
|
{
|
|
echo ${CFG_VERSION} > ${install_path}/.version
|
|
}
|
|
|
|
reinstall |