centos or ubuntu20/21/22 安装 vscode 配置 gcc g++ cmake 开发环境

2024-02-16 13:26:43 浏览数 (2)

代码语言:shell复制
#!/bin/bash
# centos or ubuntu 安装 vscode 配置 gcc g   cmake 开发环境

UrlTest()
{
    URLList=( 192.168.122.80  10.111.111.80 )
    number="kong";
    for(( i=0;i<${#URLList[*]};i   ))
    do
        pinLG=`ping -c2 -i0.3 -w2 ${URLList[$i]} | grep from`
        if [ ${#pinLG} -gt 6 ]
        then					
            number=$i
            status="内网节点通信正常,当前内网连接: ${URLList[$i]} 序号: $number "	
            echo "内网 [ok]"		
            break		
        else
            status="并非处于内网: ${URLList[$i]}  将从外网进行下载 work.eisc.cn "		
            echo "内网 [fall]"					
        fi
    done

    if [ $number = "kong" ]
    then 
        url="work.eisc.cn"
    else
        url="${URLList[$number]}:62011"
    fi

    urlDir="/ruanjian/ubuntu/server/cmakegcc"
    downUrl=$url$urlDir

    echo "$status 下载地址: $downUrl" 
    
}
UrlTest


TarList=( cmake_release   make_release   gmp_release   mpfr_release   mpc_release   freetype_release   gcc_release )

installDirSelect()
{
    echo "选择安装路径:
    1. 安装到建议路径: /datadisk/eisc/   然后自动创建的目录是: /datadisk/eisc/server  安装到  /datadisk/eisc/server/cmake/ 目录下!
    2. 安装到当前目录 下的  ./server/cmake 目录下,脚本所在位置

    3. 任意按键退出安装!
    "
    read -p " select number:  " runIF
    case "$runIF" in
        "1") echo "[running] 安装到目录:        /datadisk/eisc/server/cmake/ " ;  localDir="/datadisk/eisc" ;;
        "2") echo "[running] 选择当前目录安装:  ./server/cmake " ;                           localDir=`pwd` ;;

        *)   echo "exit" ;exit ;;
    esac 

    sleep 5

    downDir="$localDir/download/cmake"
    installDir="$localDir/server/cmake"
    gccSoDir="$installDir/so/gcc"
}


cmake_release()
{
  ReleaseMl="cmake-3.27.0-rc4-linux-x86_64"
  ReleaseInstall="cmake327"
  ReleaseBin="cmake"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

make_release()
{
  ReleaseMl="make-4.4"
  ReleaseInstall="make44"
  ReleaseBin="make"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

gmp_release()
{
  ReleaseMl="gmp-6.2.1"
  ReleaseInstall="gmp621"
  ReleaseBin="gmp"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

mpfr_release()
{
  ReleaseMl="mpfr-4.2.0"
  ReleaseInstall="mpfr420"
  ReleaseBin="mpfr"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

mpc_release()
{
  ReleaseMl="mpc-1.2.1"
  ReleaseInstall="mpc121"
  ReleaseBin="mpc"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

freetype_release()
{
  ReleaseMl="freetype-2.9"
  ReleaseInstall="freetype29"
  ReleaseBin="freetype"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}

gcc_release()
{
  ReleaseMl="gcc-13.1.0"
  ReleaseInstall="gcc1310"
  ReleaseBin="mpc"
  Down="$downUrl/$ReleaseMl.tar.gz"
  echo "cmake 下载地址重新定义为:$Down"
}
 
downloadGF=(
    http://mirror.linux-ia64.org/gnu/gcc/releases/gcc-13.1.0/gcc-13.1.0.tar.gz
    https://ftp.gnu.org/gnu/make/make-4.4.tar.gz

    https://www.mpfr.org/mpfr-current/mpfr-4.2.0.tar.gz
    http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2
    http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2
    http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz
    http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2

    https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
)

os_release()
{


    if [ $USER = "root" ]
    then 
        qx=" "
        # 判断字符串的等号要加空格,否则无法判断
    else
        qx="sudo"
        echo "当前为普通用户,需要输入root 密码..."
        sudo date
    fi

    xitong=` cat /etc/os-release  | grep -w ID | awk -F"=" '{print $2}' | sed "s/"//g" `
    case "$xitong" in
        "centos" ) iCMD="yum" ; rpmCMD="rpm -qa " ; echo "当前是 centos 系统" ; $qx $iCMD install -y openssl-devel gcc gcc-c   g   cmake make wget nano libmpfr-dev m4 gmp  gmp-devel  mpfr  mpfr-devel  libmpc  libmpc-devel bzip2 git ;;
        "ubuntu" ) iCMD="apt" ; rpmCMD="dpkg -l " ; echo "当前是 ubuntu 系统" ; $qx $iCMD install -y  gcc g   cmake make wget nano libmpfr-dev m4   bzip2 git ;;
    esac

    $qx mkdir -p $downDir $installDir $gccSoDir ; $qx chmod 777 -R $dir  $installDir $gccSoDir

}

download()
{
    cd $downDir ; echo "当前进入目录进行下载:  cd $downDir "

    for i in ${TarList[*]}
    do
        $i          # 执行函数变量
        echo "[runing] 正在检查是否下载安装包: $ReleaseMl.tar.gz"

        [ ! -d $installDir/$ReleaseInstall ] && echo "[running] 目标安装路径不存在" || break ; 

        if [ ! -f $ReleaseMl.tar.gz ]
        then 
            echo "[runing] 当前没有下载,正在下载包:wget $Down "
            $qx wget $Down
        else
            echo  "[ok] 已经下载: $downDir/$ReleaseMl.tar.gz"
        fi

        echo "检测是否解压... "
        if [ ! -d $installDir/$ReleaseInstall ]
        then 
            echo "[running] 正在解压 $downDir/$ReleaseMl.tar.gz 到目录: $installDir/$ReleaseMl" ; 
            $qx tar -xzvf $downDir/$ReleaseMl.tar.gz -C $installDir/
            $qx mv $installDir/$ReleaseMl  $installDir/$ReleaseInstall
        else 
            echo "[ok] 已经解压 : $downDir/$ReleaseInstall "
        fi

    done
}


Finstall(){

    for i in ${TarList[*]}
    do 
        $i
        MakeFlag=1;
        soFlag=1

        echo "当前正在安装  $i"  ; sleep 1;

        case "$ReleaseInstall" in 
            "gmp621")  [ ! -f $gccSoDir/$ReleaseInstall.installd  ]  && soFlag=1 || soFlag=0            ;;
            "mpfr420") [ ! -f $gccSoDir/$ReleaseInstall.installd  ]  && soFlag=1 || soFlag=0            ;;
            "mpc121")  [ ! -f $gccSoDir/$ReleaseInstall.installd  ]  && soFlag=1 || soFlag=0            ;;
            "make44")  [ ! -f $installDir/$ReleaseInstall/make    ]  && soFlag=1 || soFlag=0  ; Fpath   ;;  
            "gcc1310") [ ! -f $installDir/$ReleaseInstall/bin/gcc ]  && soFlag=1 || soFlag=0  ; Fpath   ;;  
            "cmake327")   Fpath ;;
            "freetype29") soFlag=0;;
        esac

        if [[ ! -f  $installDir/$ReleaseInstall/bin/$ReleaseBin ]] && [[ $soFlag = "1" ]]
        then
            cd $installDir/$ReleaseInstall 
            echo "[waring] 包没有安装 $installDir/$ReleaseInstall/bin/$ReleaseBin 当前进入目录:  $installDir/$ReleaseInstall  "  ; 

            case "$ReleaseInstall" in 
                "gcc1310")   $qx ./configure --prefix=$installDir/$ReleaseInstall --with-gmp=$gccSoDir --with-mpfr=$gccSoDir --with-mpc=$gccSoDir --disable-multilib ;  # $qx ./contrib/download_prerequisites  # 检测依赖包
                             $qx ./contrib/download_prerequisites ;
                             $qx make -j 4 ; $qx make install ; Fpath ;;
                             
                "cmake327")   Fpath  ;;
                "gmp621"  )  $qx ./configure --prefix=$gccSoDir; $qx make -j 4 ; $qx make install ; $qx touch $gccSoDir/$ReleaseInstall.installd ; MakeFlag=0; Fpath ;;
                "mpfr420" )  $qx ./configure --prefix=$gccSoDir; $qx make -j 4 ; $qx make install ; $qx touch $gccSoDir/$ReleaseInstall.installd ; MakeFlag=0    ;;
                "mpc121"  )  $qx ./configure --prefix=$gccSoDir; $qx make -j 4 ; $qx make install ; $qx touch $gccSoDir/$ReleaseInstall.installd ; MakeFlag=0    ;;
                *)           echo "未定指定编译,走通用编译方法..." ; $qx ./configure --prefix=$installDir/$ReleaseInstall ; $qx make -j 4 ; $qx  make instlal; Fpath ;;
            esac 

            if [ $MakeFlag = "1" ]
            then
                $qx ./configure  ; $qx make -j 2 ; $qx make install  
            fi
        else
            echo "[ok] 已经安装: $installDir/$ReleaseInstall"     
        fi
    done


}
# cd ~/public/ ; git pull ; ./sh/cmakegcc.sh

Fpath()
{
    $qx chmod 777 /etc/profile 
    StrCmake=`cat /etc/profile | grep $ReleaseInstall`
    StrCmakeLength=${#StrCmake}
    if [ $StrCmakeLength -lt 1 ]
    then 

        case "$ReleaseInstall" in 
            "gmp621") echo "#### $ReleaseInstall ####" >> /etc/profile ;
                $qx echo "export LD_LIBRARY_PATH=$gccSoDir/lib:$LD_LIBRARY_PATH" >> /etc/profile ;

                echo "[running] 最后一次写入环境变量,即将更新。退出并且自动刷新  $ReleaseInstall 环境变量 /etc/profile  请重新执行本脚本!"  ; 
                echo  "错误: cc1plus: error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory";
                echo  "需要退出ssh后重新登陆,环境变量原因 /etc/profile  ;  并且执行命令: source /etc/profile ; bash"
                cd ; $qx chmod 644 /etc/profile 
                $qx source /etc/profile & bash  ; echo "[ok] set /etc/profile" ;; 

            "cmake327")  $qx echo "#### $ReleaseInstall ####" >> /etc/profile ;
                $qx echo "export CMAKE_HOME=$installDir/$ReleaseInstall/bin" >> /etc/profile ;
                $qx echo "export PATH=$CMAKE_HOME:$PATH" >> /etc/profile ;;
            "make44")    $qx echo "#### $ReleaseInstall ####" >> /etc/profile ;
                $qx echo "export MAKE_HOME=$installDir/$ReleaseInstall/bin" >> /etc/profile ;
                $qx echo "export PATH=$MAKE_HOME:$PATH" >> /etc/profile ;;
            "gcc1310")   $qx echo "#### $ReleaseInstall ####" >> /etc/profile ;
                $qx echo "export GCC_HOME=$installDir/$ReleaseInstall/bin" >> /etc/profile ;
                $qx echo "export PATH=$GCC_HOME:$PATH" >> /etc/profile ; $qx chmod 777 /etc/profile
                $qx source /etc/profile & bash ; echo "[ok] set /etc/profile" ;;
        esac

# 指定目录可以 写一行,指定运行文件需要两行:目录 执行路径

    else
        echo "[ok] 环境变量已经配置,继续向下执行..."

    fi    

# export LD_LIBRARY_PATH=/path/to/libmpfr.so.6:$LD_LIBRARY_PATH

}


DockerInstall()
{
    $qx $iCMD install -y docker-io
    $qx touch /etc/docker/daemon.json
    $qx chmod 777 /etc/docker/daemon.json
    echo -e "
{
"registry-mirrors": ["https://hub-mirror.c.163.com"]
}
    " > /etc/docker/daemon.json
    $qx chmod 644 /etc/docker/daemon.json
    $qx systemctl daemon-reload
    $qx systemctl restart docker 
    $qx systemctl enable docker
    $qx gpasswd -a $USER docker ; newgrp docker

}

DockerRun()
{
    read -p "输入 :" input
    name=${input[0]}
    image=${input[1]}
    SourcePort=${input[2]}
    DestPort=${input[3]}

    $qx docker run --privileged=true -dit -p $SourcePort:$DestPort  --name $name $image /usr/sbin/init

    #$qx docker run --privileged -dit -p 10022:22 -p 10080:80 --name eisc centos:7 /usr/sbin/init
}


main()
{
    installDirSelect
    os_release
    download  
    Finstall
}

main

# gcc参考文档: https://gcc.gnu.org/onlinedocs/  


# 一键部署: wget eisc.cn/file/ubuntu/shell/server/cmakegcc.sh ; sudo chmod  x cmakegcc.sh  ; ./cmakegcc.sh 






0 人点赞