1 Star 0 Fork 4

skymysky / lego

forked from iDev_周晶 / lego 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
get.sh 3.83 KB
一键复制 编辑 原始数据 按行查看 历史
周晶 提交于 2019-10-27 16:26 . auto-complete support
#!/usr/bin/env bash
### BEGIN ###
# Author: idevz
# Since: 18:07:28 2019/10/26
# Description: online install lego
# get ./get.sh
#
# this online installation script is came from "wtool" which created by qindi@weibo.com
#
# Environment variables that control this script:
#
### END ###
set -e
function logo() {
echo "
██▓ ▓█████ ▄████ ▒█████
▓██▒ ▓█ ▀ ██▒ ▀█▒▒██▒ ██▒
▒██░ ▒███ ▒██░▄▄▄░▒██░ ██▒
▒██░ ▒▓█ ▄ ░▓█ ██▓▒██ ██░
░██████▒░▒████▒░▒▓███▀▒░ ████▓▒░
░ ▒░▓ ░░░ ▒░ ░ ░▒ ▒ ░ ▒░▒░▒░
░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ▒ ▒░
░ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░ ░ ░"
}
function get_type() {
echo "1 : Download and install to current folder"
echo "2 : Download only"
echo "q : Quit"
local choice=
while (true); do
echo -n "Enter a value:"
read choice </dev/tty
if [ "$choice" = "q" ]; then exit 0; fi
if [ "$choice" -gt "0" ] 2>/dev/null && [ "$choice" -lt "4" ] 2>/dev/null; then
return "$choice"
else
echo "$choice is not valid option!"
fi
done
}
function do_download() {
local fetch_dir=${1}
if [ ! -d "$fetch_dir" ]; then
echo "$fetch_dir is not vaild!"
exit 1
fi
cd "$fetch_dir"
test_exists "$fetch_dir"
local has_git=
type "git" >/dev/null 2>/dev/null || has_git=$?
if [ "$has_git" -eq 0 ]; then
echo "fetching source from github"
do_fetch "$fetch_dir"
else
echo "can't locate git ,using archive mode."
do_download_archive "$fetch_dir"
fi
echo "lego is downloaded to $fetch_dir/lego"
}
function do_download_archive() {
mkdir lego && cd lego
curl -L https://github.com/idevz/lego/tarball/master | tar -xf - --strip-components=1
}
function test_exists() {
if [ -e o ] || [ -e runX.sh ]; then
echo "$1/lego already exist!"
local choice=
while (true); do
echo -n "(q)uit or (r)eplace?"
read choice </dev/tty
if [ "$choice" = "q" ]; then
exit 0
elif [ "$choice" = "r" ]; then
rm -fr $1/lego
break
else
echo "$choice is not valid!"
fi
done
fi
}
function do_fetch() {
local fetch_dir=$1
if [ ! -d "$fetch_dir" ]; then
echo "$fetch_dir is not vaild!"
exit 1
fi
cd "$fetch_dir"
test_exists lego
git clone https://github.com/idevz/lego.git lego --depth=1
cd lego
return 0
}
function do_install() {
echo '***install need sudo, please enter password***'
sudo make install
echo 'lego had been installed to /usr/local/bin as command "o", have fun.'
}
function main() {
logo
local type=
if [ "$1" = "install" ]; then
type="1"
elif [ "$1" = "download" ]; then
type="2"
else
get_type || type=$?
fi
local current_folder=
current_folder="$(pwd)"
case "$type" in
"1")
echo "Launching lego installer..."
do_download "${current_folder}"
do_install
;;
"2")
echo "Start downloading lego ..."
do_download "${current_folder}"
;;
esac
echo ""
echo "***************************************************************"
echo "***please add following commands to .bashrc for tab completing***"
echo ""
echo "source ${current_folder}/lego/lego/ac/auto-complete"
echo "***************************************************************"
}
main "$@"
Shell
1
https://gitee.com/skymysky/lego.git
git@gitee.com:skymysky/lego.git
skymysky
lego
lego
master

搜索帮助