bootstrap.sh 7.8 KB

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