Ubuntu新虚拟机简易初始化脚本

#!/bin/bash

 

echo "[INIT]Backup sources.list ..."

 

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak

 

echo "[INIT]Create sources.list ..."

 

version=$(lsb_release -rs)

 

echo "[INIT]Get release version: ${version}"

 

if [ "${version}" == "14.04" ]


then


version_name="trusty"


fi


if [ "${version}" == "16.04" ]


then


version_name="xenial"


fi


if [ "${version}" == "18.04" ]


then


version_name="bionic"


fi


if [ "${version}" == "20.04" ]


then


version_name="focal"


fi


if [ "${version}" == "22.04" ]


then


version_name="jammy"


fi


if [ "${version}" == "23.04" ]


then


version_name="lunar"


fi

 

sudo echo "


# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释


deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name} main restricted universe multiverse


# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name} main restricted universe multiverse


deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-updates main restricted universe multiverse


# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-updates main restricted universe multiverse


deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-backports main restricted universe multiverse


# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-backports main restricted universe multiverse

 

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-security main restricted universe multiverse


# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${version_name}-security main restricted universe multiverse

 

deb http://security.ubuntu.com/ubuntu/ ${version_name}-security main restricted universe multiverse


# deb-src http://security.ubuntu.com/ubuntu/ ${version_name}-security main restricted universe multiverse

 

# 预发布软件源,不建议启用


# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse


# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

 

" | sudo tee /etc/apt/sources.list

 

echo "[INIT]Updating ..."

 

sudo apt update

 

echo "[INIT]Installing package ..."

 

sudo apt install -y vim


sudo apt install -y cmake


sudo apt install -y build-essential


sudo apt install -y net-tools

 

echo "[INIT]Installing vmtools ..."

 

sudo apt install -y open-vm-tools

 

echo "[INIT]Reboot system ..."

 

reboot

 

posted @ 2023-08-28 15:45  ZiwenJ  阅读(83)  评论(0)    收藏  举报