系统初始化脚本

此脚本用于修改Ubuntu软件源,和安装一些常用软件。仅支持Ubuntu x64系统,已经在Ubuntu 18.04 x64下通过测试。

init.sh Version:0.0.1

#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#fonts color
Green="\033[32m" 
Yellow="\033[33m"
Red="\033[31m" 
Font="\033[0m"

#notification information
OK="${Green}[OK]${Font}"
Info="${Yellow}[Info]${Font}"
Error="${Red}[Error]${Font}"

#system infomation
source /etc/os-release
KernelBit="$(getconf LONG_BIT)"

#folder
Install_Dir=/opt


about() {
    echo ""
    echo " ========================================================= "
    echo " #            System Required: Ubuntu x64          "
    echo " #            Description: Install Softwares         "
    echo " #            Version: 0.0.1                 "
    echo " #            Author: Jianrry                 "
    echo " #            Blog: https://jianrry.com            "
    echo " =========================================================  "
    echo ""
}

 
# 系统检测、仅支持 ubuntu x64
check_system(){
    
    if [[ "${ID}" == "ubuntu" && "${KernelBit}" == "64" ]];then
        echo -e "${OK} ${Green} 当前系统为 ${ID} ${VERSION_ID} ${KernelBit}bit ${Font}\n "
    else
        echo -e "${Error} ${Red} 当前系统为不在支持的系统列表内,安装中断 ${Font}\n "
        exit 1
    fi

}


# 判定是否为root用户
is_root(){

    if [ `id -u` == 0 ]
        then echo -e "${OK} ${Green} 当前用户是root用户,进入安装流程 ${Font}\n "
        sleep 1
    else
        echo -e "${Error} ${Red} 当前用户不是root用户,请切换到root用户后重新执行脚本 ${Font}\n" 
        exit 1
    fi

}


# 打开WiFi开关
wifi(){

# 方法一:
cat > /etc/modprobe.d/black_ideapad_laptop.conf <<EOF
blacklist ideapad_laptop
EOF

# 方法二:
echo -e "${Info} ${Yellow} 请输入当前用户的sudo密码: ${Font}\n"
read myPass 
echo -e ""

cat > /etc/rc.local <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "$myPass" |sudo modprobe -r ideapad_laptop
exit 0
EOF

chmod +x /etc/rc.local
echo -e "${OK} ${Green} WiFi开关已打开 ${Font} \n"

}


# 修改ubuntu源
ubuntu_source(){


    if [[ -f /etc/apt/sources.list.bak ]]; then
        echo -e "${Info} ${Yellow} sources.list.bak已存在 ${Font} \n"
    else
        cp /etc/apt/sources.list /etc/apt/sources.list.bak
    fi

    rm /etc/apt/sources.list
    
    echo "
    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse

    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse

    deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

    ## Not recommended
    # deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    # deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse " > /etc/apt/sources.list


    sed -i "s/bionic/$UBUNTU_CODENAME/"g /etc/apt/sources.list

    apt-get update

}


# 读取软件包列表
update(){

    apt-get update
    echo -e "${OK} ${Green} 读取软件包列表完成 ${Font} \n"

}


# 更新软件包
upgrade(){

    apt-get -y upgrade
    echo -e "${OK} ${Green} 更新软件包完成 ${Font}\n "

}


# 安装chrome浏览器
chrome(){

    wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/
    wget -q -O - https://dl.google.com/linux/linux_signing_key.pub  | sudo apt-key add -
    apt-get update
    apt-get -y install google-chrome-stable
    echo -e "${OK} ${Green} Chrome浏览器已经安装完成 ${Font}\n "

}


# 安装electron-ssr
electron_ssr(){

    apt-get -y install libcanberra-gtk-module libcanberra-gtk3-module gconf2 gconf-service libappindicator1
    wget https://down.jianrry.com/electron-ssr-0.2.6.deb
    dpkg -i electron-ssr-0.2.6.deb
    rm electron-ssr-0.2.6.deb
    echo -e "${OK} ${Green} electron_ssr已经安装完成 ${Font}\n "

}


# 安装keepassxc
keepassxc(){

    add-apt-repository ppa:phoerious/keepassxc
    apt-get update
    apt-get -y install keepassxc
    echo -e "${OK} ${Green} keepassxc已经安装完成 ${Font}\n "
}



# 安装dropbox
dropbox(){

    wget https://down.jianrry.com/dropbox_2019.01.31_amd64.deb
    dpkg -i dropbox_2019.01.31_amd64.deb
    rm dropbox_2019.01.31_amd64.deb

    wget https://down.jianrry.com/dropbox-lnx.x86_64-68.4.102.tar.gz
    tar zxvf dropbox-lnx.x86_64-68.4.102.tar.gz 
    mv .dropbox-dist ~
    rm dropbox-lnx.x86_64-68.4.102.tar.gz

    apt-get -y install proxychains
    echo "socks5 127.0.0.1 1080" >> /etc/proxychains.conf 
    proxychains dropbox start -i
    echo -e "${OK} ${Green} dropbox已经安装完成 ${Font}\n "

}


# 安装fcitx
fcitx(){

    apt-get -y install fcitx
    wget https://down.jianrry.com/sogoupinyin_2.2.0.0108_amd64.deb
    dpkg -i sogoupinyin_2.2.0.0108_amd64.deb
    rm sogoupinyin_2.2.0.0108_amd64.deb
    echo -e "${OK} ${Green} fcitx已经安装完成 ${Font}\n "

}


# 安装shutter
shutter(){

    apt-get -y install shutter
    echo -e "${OK} ${Green} shutter已经安装完成 ${Font}\n "

}


# 安装remmina
remmina(){

    apt-get -y install remmina remmina-plugin-*
    echo -e "${OK} ${Green} remmina已经安装完成 ${Font}\n "

}


# 安装virtualbox
virtualbox(){

    apt-get -y install virtualbox
    echo -e "${OK} ${Green} virtualbox已经安装完成 ${Font}\n "

}


# 安装samba
samba(){

    apt-get -y install samba smbclient 

    mkdir -m 777 -p /share

    cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

    echo "
    [share]

        path = /share

        browseable = yes

        writable = yes

        comment = smb share test

        public = yes " > /etc/samba/smb.conf

}


# 安装komorebi
komorebi(){

    wget https://down.jianrry.com/komorebi-2.1-64-bit.deb
    dpkg -i komorebi-2.1-64-bit.deb
    rm komorebi-2.1-64-bit.deb
    echo -e "${OK} ${Green} komorebi已经安装完成 ${Font}\n"

}


# 安装steam
steam(){

    apt-get -y install steam
    echo -e "${OK} ${Green} komorebi已经安装完成 ${Font}\n "

}


# 安装软件
install_software(){

    while :
    do
        echo -e "${Info} ${Yellow} 请输入对应的数字: ${Font}\n"
        echo '1)安装Chrome(谷歌浏览器)'
        echo '2)安装Electron SSR(影梭)'
        echo '3)安装KeePassXC(KeePassXC密码管理器)'
        echo '4)安装DropBox(DropBox网盘)'
        echo '5)安装Fcitx(小企鹅输入法)'
        echo '6)安装Shutter(Shutter截图工具)'
        echo '7)安装Remmina(Remmina远程桌面客户端)'
        echo '8)安装VirtualBox(VirtualBox虚拟机)'
        echo '9)安装Samba(Samba服务器)'
        echo '10)安装Komorebi(Komorebi动态桌面)'
        echo '11)安装Steam(Steam游戏平台)'
        echo -e '12)返回上一级菜单\n'
        echo -e "${Info} ${Yellow} 你输入的数字为: ${Font}\n"
        read myNum 
        echo ''
        case $myNum in
                1)  chrome;;
                2)  electron_ssr;;
                3)  keepassxc;;
                4)  dropbox;;
                5)  fcitx;;
                6)  shutter;;
                7)  remmina;;
                8)  virtualbox;;
            9)  samba;;
                10)  komorebi;;
                11) steam;;
                   12)  echo -e "${Info} ${Yellow} 已返回上一级菜单 ${Font}\n"
                break;;
                *)  echo -e "${Error} ${Red} 你输入的数字不正确,请重新输入 ${Font}\n";;
        esac
    done

}


# 打印菜单
menu(){

    while :
    do
        echo -e "${Info} ${Yellow} 请输入对应的数字: ${Font}\n"
        echo '1)打开WiFi开关'
        echo '2)修改Ubuntu软件源'
        echo '3)读取软件包列表'
        echo '4)更新软件包'
        echo '5)安装软件'
        echo -e '6)离开\n'
        echo -e "${Info} ${Yellow} 你输入的数字为: ${Font}\n"
        read myNum 
        echo ''
        case $myNum in
            1)  wifi;;
                2)  ubuntu_source;;
                3)  update;;
                4)  upgrade;;
                5)  install_software;;
                   6)  echo -e "${Info} ${Yellow} 系统即将退出 ${Font}\n"
                break;;
                *)  echo -e "${Error} ${Red} 你输入的数字不正确,请重新输入 ${Font}\n";;
        esac
    done

}


main(){

about
check_system
is_root
menu

}

main

最后修改:2019 年 07 月 31 日 10 : 36 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论