bootstrap.sh 6.2 KB

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