gh_acions_setup.bash 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # 启用 multilib 仓库 | Enable multilib
  39. recho "正在启用 multilib 仓库..." "Enabling multilib repository..."
  40. printf '\n%s\n%s\n' '[multilib]' 'Include = /etc/pacman.d/mirrorlist' >> /etc/pacman.conf
  41. grep -A1 "\[multilib\]" /etc/pacman.conf
  42. pacman -Syy --noconfirm --needed zellij|| true
  43. # 安装基础依赖 | Install base dependencies
  44. recho "正在安装基础依赖..." "Installing base dependencies..."
  45. pacman -Sy --noconfirm archiso reflector git base-devel sudo
  46. # 安装 aurutils | Install aurutils
  47. recho "正在安装 aurutils..." "Installing aurutils..."
  48. sudo -u builder git clone https://aur.archlinux.org/aurutils.git /home/builder/aurutils
  49. cd /home/builder/aurutils && cd $REPO_DIR
  50. sudo -u builder makepkg -si --noconfirm
  51. # 修复文件权限 | Fix file permissions
  52. recho "正在修复文件权限..." "Fixing file permissions..."
  53. chown -R builder:builder $REPO_DIR
  54. # 完成提示 | Completion message
  55. recho "环境设置完成!" "Environment setup completed!"
  56. recho "然后需手动执行 sudo -u builder $REPO_DIR/build.bash --noconfirm" "Next, manually execute: sudo -u builder $REPO_DIR/build.bash --noconfirm"