Skip to content

Commit

Permalink
Merge pull request #1091 from yyyangw/gitlfs_install
Browse files Browse the repository at this point in the history
增加"安装gitlfs"和"判断操作系统"脚本
  • Loading branch information
Lingghh authored Jun 19, 2024
2 parents 82b7892 + a9b4a7d commit d18e4fd
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 0 deletions.
1 change: 1 addition & 0 deletions quick_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TCA_PROJECT_PATH=${TCA_PROJECT_PATH:-"$CURRENT_SCRIPT_PATH"}
TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$TCA_PROJECT_PATH/scripts"}

source $TCA_SCRIPT_ROOT/utils.sh
source $TCA_SCRIPT_ROOT/base/install_git_lfs.sh
source $TCA_SCRIPT_ROOT/base/install_bin.sh
source $TCA_SCRIPT_ROOT/base/install_docker.sh

Expand Down
83 changes: 83 additions & 0 deletions scripts/base/get_os.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

function get_os(){
ret=""
# 判断当前操作系统的类型是不是linux
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# 检查当前操作系统是 Ubuntu、Debian 还是 CentOS
if command -v lsb_release > /dev/null; then
#检查 lsb_release 命令是否可用,如果该命令可用,用下面这种方式判断
if [[ $(lsb_release -si) == "Ubuntu" ]]; then
#echo "Your Operating system is Ubuntu"
ret="Ubuntu"

elif [[ $(lsb_release -si) == "Debian" ]]; then
#echo "Your Operating system is Debian"
ret="Debian"


elif [[ $(lsb_release -si) == "TencentOS" ]]; then
#echo "Your Operating system is TencentOS"
ret="TencentOS"


elif [[ $(lsb_release -si) == "CentOS" ]]; then
#echo "Your Operating system is CentOS"
ret="CentOS"

fi
else
# 检查 /etc/os-release 文件中是否包含“NAME="CentOS"”字符串,如果包含,则用下面这种方式判断。
if [[ -f /etc/os-release ]]; then
if grep -q "Ubuntu" /etc/os-release; then
#echo "Your Operating system is Ubuntu"
ret="Ubuntu"

elif grep -q "Debian" /etc/os-release; then
#echo "Your Operating system is Debian"
ret="Debian"

elif grep -q "TencentOS" /etc/os-release; then
#echo "Your Operating system is TencentOS"
ret="TencentOS"


elif grep -q "CentOS" /etc/os-release; then
#echo "Your Operating system is CentOS"
ret="CentOS"

fi
fi
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# 检查当前操作系统是 macOS
#echo "Your Operating system is macOS"
ret="macOS"

elif [[ "$OSTYPE" == "msys" ]]; then
# 检查当前操作系统是 Windows
#echo "Your Operating system is Windows"
ret="Windows"

elif [[ "$OSTYPE" == "win32" ]]; then
# 检查当前操作系统是 Windows
#echo "Your Operating system is Windows"
ret="Windows"

else
#echo "Unknown operating system"
ret="others"
fi

echo "$ret"

}









214 changes: 214 additions & 0 deletions scripts/base/install_git_lfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/bin/bash

CURRENT_SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")";pwd)
TCA_SCRIPT_ROOT=${TCA_SCRIPT_ROOT:-"$( cd "$(dirname $CURRENT_SCRIPT_PATH)"; pwd )"}

source $TCA_SCRIPT_ROOT/utils.sh
source $TCA_SCRIPT_ROOT/base/get_os.sh

# 检查git lfs 是否安装
function check_git_lfs(){
ret=""
#判断是否存在 git lfs命令
if command_exists git-lfs; then
ret="true"
else
ret="false"
fi
echo "$ret"
}

function check_install_curl () {
if command -v curl >/dev/null 2>&1; then
echo "curl installed"
else
echo "curl is not installed. Start the installation"
apt-get update -y && apt-get install curl -y
fi
}

function check_install_sudo() {
if command -v sudo >/dev/null 2>&1; then
echo "sudo installed"
else
echo "sudo is not installed. Start the installation"
apt-get update
apt-get install sudo
fi
}

function check_install_sudo_centos() {
if command -v sudo >/dev/null 2>&1; then
echo "sudo installed"
else
echo "sudo is not installed. Start the installation"
yum update
yum -y install sudo

if [ $? -ne 0 ]; then
echo "Installation failed, you can try to add a mirror source. url: http://mirror.centos.org "
exit 1
fi

fi
}

function check_install_brew() {
if command -v brew >/dev/null 2>&1; then
echo "brew installed"
else
echo "brew is not installed. Start the installation. Please go to the official website to install yourself, url: https://brew.sh/ "
fi
}


function ubuntu_debian_install(){
LOG_INFO "git lfs installation requires administrator permissions. Are you sure to use administrator permissions?"
read -p "Please enter:[Y/N]" result
case $result in
[yY])
sleep 2
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
;;
[nN])
echo -e "Cancel install git lfs"
exit 1
;;
*)
LOG_ERROR "Invalid input. Stop."
exit 1
;;
esac
}

function centos_install(){
LOG_INFO "git lfs installation requires administrator permissions. Are you sure to use administrator permissions?"
read -p "Please enter:[Y/N]" result
case $result in
[yY])
sleep 2
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
sudo yum install git-lfs

if [ $? -ne 0 ]; then
echo "Installation failed, you can try to add a mirror source. url: http://mirror.centos.org "
exit 1
fi
;;
[nN])
echo -e "Cancel install git lfs"
exit 1
;;
*)
LOG_ERROR "Invalid input. Stop."
exit 1
;;
esac


}

function macos_install() {
brew install git-lfs
}

function windows_install(){
LOG_WARN "The current version of Windows does not have built-in support for the automatic installation of Git LFS."
LOG_WARN "Please download manually, url: https://git-lfs.com/"
}


function install_git_lfs(){
ret=$( check_git_lfs )
if [ "$ret" == "true" ]; then
LOG_WARN "This machine had installed git lfs"
return 0
fi

LOG_INFO "Download git lfs and install"


ret=$( get_os )

case $ret in
"Ubuntu")
LOG_WARN "Your Operating system is Ubuntu"
check_install_curl
check_install_sudo
ubuntu_debian_install
;;
"Debian")
LOG_WARN "Your Operating system is Debian"
check_install_curl
check_install_sudo
ubuntu_debian_install
;;
"TencentOS")
LOG_WARN "Your Operating system is TencentOS"
check_install_sudo_centos
centos_install
;;
"CentOS")
LOG_WARN "Your Operating system is CentOS"
check_install_sudo_centos
centos_install
;;
"macOS")
LOG_WARN "Your Operating system is macOS"
check_install_brew
macos_install
;;
"Windows")
LOG_WARN "Your Operating system is Windows"
windows_install
exit 1;
;;
*)
LOG_ERROR "Your operating system is not recognized."
;;
esac


retval=$?
if [ "$retval" -ne 0 ]; then
LOG_WARN "Download git lfs failed."
LOG_WARN " Please install git lfs manually, git lfs installation guide : https://github.com/git-lfs/git-lfs?tab=readme-ov-file#installing"
exit 1;
fi

}

function interactive_install_git_lfs() {
ret=$( check_git_lfs )
if [ "$ret" == "true" ]; then
LOG_WARN "This machine had installed git lfs"
return 0
fi

LOG_WARN "Current machine has not installed git lfs."
LOG_INFO "Do you want to install git lfs by this script?"
read -p "Please enter:[Y/N]" result
case $result in
[yY])
sleep 2
install_git_lfs
;;
[nN])
echo -e "Cancel install git lfs"
return 1
;;
*)
LOG_ERROR "Invalid input. Stop."
exit 1
;;
esac

}

interactive_install_git_lfs





0 comments on commit d18e4fd

Please sign in to comment.