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