bootstrap.sh 6.4 KB

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