1emulator="qemu" 2defpackman="apt-get" 3export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static 4export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup 5 6banner() 7{ 8 echo "|------------------------------------------|" 9 echo "| Welcome to the DragonOS bootstrap |" 10 echo "|------------------------------------------|" 11} 12 13congratulations() 14{ 15 echo "|-----------Congratulations!---------------|" 16 echo "| |" 17 echo "| 你成功安装了DragonOS所需的依赖项! |" 18 echo "| 您可以通过以下命令运行它: |" 19 echo "| |" 20 echo "| make run-docker -j 你的cpu核心数 |" 21 echo "| |" 22 echo "|------------------------------------------|" 23} 24 25#################################### 26# 当检测到ubuntu或Debian时,执行此函数 # 27# 参数:第一个参数为包管理器 # 28#################################### 29install_ubuntu_debian_pkg() 30{ 31 echo "检测到 Ubuntu/Debian" 32 echo "正在更新包管理器的列表..." 33 sudo "$1" update 34 echo "正在安装所需的包..." 35 sudo "$1" install -y \ 36 ca-certificates \ 37 curl \ 38 gnupg \ 39 lsb-release \ 40 llvm-dev libclang-dev clang gcc-multilib \ 41 gcc build-essential fdisk dosfstools 42 43 if [ -z "$(which docker)" ]; then 44 echo "正在安装docker..." 45 sudo mkdir -p /etc/apt/keyrings 46 curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg 47 echo \ 48 "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ 49 $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 50 sudo $1 update 51 sudo "$1" install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin 52 else 53 echo "您的计算机上已经安装了docker" 54 fi 55 56 if [ -z "$(which qemu-system-x86_64)" ]; then 57 echo "正在安装QEMU虚拟机..." 58 sudo $1 install -y qemu qemu-system qemu-kvm 59 else 60 echo "QEMU已经在您的电脑上安装!" 61 fi 62 63} 64 65install_osx_pkg() 66{ 67 echo "Detected OSX! 暂不支持Mac OSX的一键安装!" 68 exit 1 69} 70 71#################################################################################### 72# This function takes care of everything associated to rust, and the version manager 73# That controls it, it can install rustup and uninstall multirust as well as making 74# sure that the correct version of rustc is selected by rustup 75#################################################################################### 76rustInstall() { 77 # Check to see if multirust is installed, we don't want it messing with rustup 78 # In the future we can probably remove this but I believe it's good to have for now 79 if [ -e /usr/local/lib/rustlib/uninstall.sh ] ; then 80 echo "您的系统上似乎安装了multirust。" 81 echo "该工具已被维护人员弃用,并将导致问题。" 82 echo "如果您愿意,此脚本可以从系统中删除multirust" 83 printf "卸载 multirust (y/N):" 84 read multirust 85 if echo "$multirust" | grep -iq "^y" ;then 86 sudo /usr/local/lib/rustlib/uninstall.sh 87 else 88 echo "请手动卸载multistrust和任何其他版本的rust,然后重新运行bootstrap.sh" 89 exit 90 fi 91 fi 92 # If rustup is not installed we should offer to install it for them 93 if [ -z "$(which rustup)" ]; then 94 echo "您没有安装rustup," 95 echo "我们强烈建议使用rustup, 是否要立即安装?" 96 echo "*WARNING* 这将会发起这样的一个命令 'curl | sh' " 97 printf "(y/N): " 98 read rustup 99 if echo "$rustup" | grep -iq "^y" ;then 100 #install rustup 101 curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly 102 # You have to add the rustup variables to the $PATH 103 echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc 104 # source the variables so that we can execute rustup commands in the current shell 105 source ~/.cargo/env 106 source "$HOME/.cargo/env" 107 else 108 echo "Rustup will not be installed!" 109 fi 110 fi 111 # 112 if [ -z "$(which rustc)" ]; then 113 echo "Rust 还未被安装" 114 echo "请再次运行脚本,接受rustup安装" 115 echo "或通过以下方式手动安装rustc(不推荐):" 116 echo "curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly" 117 exit 118 else 119 echo "是否为Rust换源为Gitee镜像源?" 120 echo "如果您在国内,我们推荐您这样做,以提升网络速度。" 121 echo "*WARNING* 这将会替换原有的镜像源设置。" 122 printf "(y/N): " 123 read change_src 124 if echo "$change_src" | grep -iq "^y" ;then 125 touch ~/.cargo/config 126 bash change_rust_src.sh 127 else 128 echo "取消换源,您原有的配置不会被改变。" 129 fi 130 echo "正在安装DragonOS所需的rust组件...首次安装需要一些时间来更新索引,请耐心等待..." 131 cargo install cargo-binutils 132 rustup toolchain install nightly 133 rustup default nightly 134 rustup component add rust-src 135 rustup component add llvm-tools-preview 136 rustup target add x86_64-unknown-none 137 echo "Rust已经成功的在您的计算机上安装!请运行 source ~/.cargo/env 以使rust在当前窗口生效!" 138 fi 139} 140 141############ 开始执行 ############### 142banner 143rustInstall 144 145if [ "Darwin" == "$(uname -s)" ]; then 146 install_osx_pkg "$emulator" || exit 1 147else 148 # Here we will use package managers to determine which operating system the user is using. 149 150 # Suse and derivatives 151 if hash 2>/dev/null zypper; then 152 suse "$emulator" || exit 1 153 # Debian or any derivative of it 154 elif hash 2>/dev/null apt-get; then 155 install_ubuntu_debian_pkg "$defpackman" || exit 1 156 # Fedora 157 elif hash 2>/dev/null dnf; then 158 fedora "$emulator" || exit 1 159 # Gentoo 160 elif hash 2>/dev/null emerge; then 161 gentoo "$emulator" || exit 1 162 # SolusOS 163 elif hash 2>/dev/null eopkg; then 164 solus "$emulator" || exit 1 165 # Arch linux 166 elif hash 2>/dev/null pacman; then 167 archLinux "$emulator" || exit 1 168 # FreeBSD 169 elif hash 2>/dev/null pkg; then 170 freebsd "$emulator" || exit 1 171 # Unsupported platform 172 else 173 printf "\e[31;1mFatal error: \e[0;31mUnsupported platform, please open an issue\[0m" || exit 1 174 fi 175fi 176 177# 创建磁盘镜像 178bash create_hdd_image.sh 179bash grub_auto_install.sh 180# 解决kvm权限问题 181USR=$USER 182sudo adduser $USR kvm 183sudo chown $USR /dev/kvm 184 185congratulations 186