这是一段postinstall脚本,也就是在安装完ubuntu之后你可以执行的一些操作。比如,安装chromel浏览器,升级系统等。在这个例子中展示了一种使用bash脚本实现菜单选项的写法,废话不多说,直接上代码:
#!/bin/bash
function app_chrome() {
#CHROME
cd /home/
sudo wget https://dl.google.com/linux/linux_signing_key.pub
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get install -f
sudo rm -f google-chrome*.deb
sudo rm -f *signing_key.pub
echo -e "\e[44m_____End Chrome_____\e[0m"
}
function app_slack() {
#SLACK
cd /home/
sudo wget https://downloads.slack-edge.com/linux_releases/slack-desktop-4.12.2-amd64.deb
sudo dpkg -i slack-desktop-*.deb
sudo rm -f slack*.deb
echo -e "\e[44m_____End Slack_____\e[0m"
}
function app_zoom() {
#ZOOM
cd /home/
sudo wget https://zoom.us/client/latest/zoom_amd64.deb
sudo dpkg -i zoom*.deb
sudo rm -f zoom*.deb
echo -e "\e[44m_____End Zoom_____\e[0m"
}
function app_git() {
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt update; sudo apt install -y git
echo -e "\e[44m_____End Git_____\e[0m"
}
function update_system() {
sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y
}
function all() {
app_chrome
app_slack
app_zoom
app_git
update_system
echo -e "\e[44m_____End ALL\e[0m"
}
menu(){
echo -ne "
**OPTIONS**
2) Install Zoom
3) Update_system
4) Install Chrome
5) Install Slack
6) Install Git
1) --ALL--
0) Exit
Choose an option:"
read a
case $a in
1) all ; menu ;;
2) app_zoom ; menu ;;
3) update_system ; menu ;;
4) app_chrome ; menu ;;
5) app_slack ; menu ;;
6) app_git ; menu ;;
0) exit 0 ;;
*) echo -e $red"Wrong option."$clear; WrongCommand;;
esac
}
# 执行menu函数
menu