gh_acions_setup.bash 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env bash
  2. # 设置定量 | Quantities
  3. ## 当前脚本所在目录 | Script directory
  4. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  5. ## 仓库目录 | Repository directory
  6. REPO_DIR="$(dirname "$SCRIPT_DIR")"
  7. ## 当前语言 | Current language
  8. CURRENT_LANG=0 # 0: en-US, 1: zh-Hans-CN
  9. # 本地化 | Localization
  10. recho() {
  11. if [ "$CURRENT_LANG" == "1" ]; then
  12. ## zh-Hans-CN
  13. echo "$1";
  14. else
  15. ## en-US
  16. echo "$2";
  17. fi
  18. }
  19. # 语言检测 | Language detection
  20. if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1; fi
  21. # 显示脚本信息 | Display script info
  22. recho "开始执行 GitHub Actions 环境设置..." "Starting GitHub Actions environment setup..."
  23. recho "脚本目录: $SCRIPT_DIR" "Script directory: $SCRIPT_DIR"
  24. recho "仓库目录: $REPO_DIR" "Repository directory: $REPO_DIR"
  25. # 安装 sudo | Install sudo
  26. recho "正在安装 sudo..." "Installing sudo..."
  27. pacman -Syu --noconfirm --needed sudo
  28. # 初始化 pacman | Initialize pacman
  29. recho "正在初始化 pacman 密钥..." "Initializing pacman keys..."
  30. pacman-key --init
  31. pacman-key --populate archlinux
  32. # 创建 builder 用户和组 | Create builder user and group
  33. recho "正在创建 builder 用户和组..." "Creating builder user and group..."
  34. useradd -m -s /bin/bash builder
  35. echo 'builder ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
  36. groupadd -f alpm
  37. usermod -aG alpm builder
  38. # 修复文件权限 | Fix file permissions
  39. recho "正在修复文件权限..." "Fixing file permissions..."
  40. chown -R builder:builder $REPO_DIR
  41. # 启用 multilib 仓库 | Enable multilib
  42. recho "正在启用 multilib 仓库..." "Enabling multilib repository..."
  43. printf '\n%s\n%s\n' '[multilib]' 'Include = /etc/pacman.d/mirrorlist' >> /etc/pacman.conf
  44. grep -A1 "\[multilib\]" /etc/pacman.conf
  45. pacman -Syy --noconfirm --needed zellij|| true
  46. # 安装基础依赖 | Install base dependencies
  47. recho "正在安装基础依赖..." "Installing base dependencies..."
  48. pacman -Sy --noconfirm archiso reflector git base-devel sudo
  49. # 安装 aurutils | Install aurutils
  50. recho "正在安装 aurutils..." "Installing aurutils..."
  51. sudo -u builder git clone https://aur.archlinux.org/aurutils.git aurutils
  52. sudo -u builder makepkg -si --noconfirm -D aurutils
  53. # 完成提示 | Completion message
  54. recho "环境设置完成!" "Environment setup completed!"
  55. recho "然后需手动执行 sudo -u builder $REPO_DIR/build.bash --noconfirm" "Next, manually execute: sudo -u builder $REPO_DIR/build.bash --noconfirm"