rebrand.bash 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env bash
  2. # 设置定量 | Quantities
  3. ## 仓库所在目录 | Repository directory
  4. REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
  5. ## 当前语言 | Current language
  6. CURRENT_LANG=0 ### 0: en-US, 1: zh-Hans-CN
  7. ## 用户界面 ID | User界面 ID
  8. UI_ID=$1
  9. ## 登录页面直链 | Login page direct link
  10. LOGIN_URL=$2
  11. ## 登录页面路径 | Login page path
  12. LOGIN_PATH=""
  13. ## 系统名称 | System name
  14. SYS_NAME=$3
  15. # 本地化 | Localization
  16. recho() {
  17. if [ "$CURRENT_LANG" == "1" ]; then
  18. ## zh-Hans-CN
  19. echo "$1";
  20. else
  21. ## en-US
  22. echo "$2";
  23. fi
  24. }
  25. # 语言检测 | Language detection
  26. if [ $(echo ${LANG/_/-} | grep -Ei "\\b(zh|cn)\\b") ]; then CURRENT_LANG=1; fi
  27. # 检查依赖命令 | Check dependency command
  28. if ! command -v curl &> /dev/null; then
  29. recho "错误: 未找到 curl 命令" "Error: curl command not found"
  30. exit 1
  31. fi
  32. if ! command -v sed &> /dev/null; then
  33. recho "错误: 未找到 sed 命令" "Error: sed command not found"
  34. exit 1
  35. fi
  36. # 检查参数数量 | Check number of parameters
  37. if [ $# -gt 3 ]; then
  38. recho "错误: 参数过多。用法: $0 [UI_ID] [LOGIN_URL] [SYS_NAME]" "Error: Too many arguments. Usage: $0 [UI_ID] [LOGIN_URL] [SYS_NAME]"
  39. exit 1
  40. fi
  41. # 如果登录页面直链不为空,下载登录页面直链的文件至指定位置 | If the login page direct link is not empty, download the file to the specified location
  42. if [ -n "$LOGIN_URL" ]; then
  43. # 创建目标目录(如果不存在)| Create the destination directory (if it does not exist)
  44. DEST_DIR="$REPO_DIR/airootfs/usr/local/lib/pageos-greet"
  45. if [ ! -d "$DEST_DIR" ]; then
  46. recho "正在创建目录: $DEST_DIR" "Creating directory: $DEST_DIR"
  47. mkdir -p "$DEST_DIR"
  48. if [ $? -ne 0 ]; then
  49. recho "错误: 无法创建目录 $DEST_DIR" "Error: Failed to create directory $DEST_DIR"
  50. exit 1
  51. fi
  52. fi
  53. # 下载登录页面 | Download login page
  54. recho "正在下载登录页面: $LOGIN_URL" "Downloading login page: $LOGIN_URL"
  55. curl -s -f -o "$REPO_DIR/airootfs/usr/local/lib/pageos-greet/login-page.html" "$LOGIN_URL"
  56. if [ $? -ne 0 ]; then
  57. recho "错误: 无法下载登录页面 $LOGIN_URL" "Error: Failed to download login page $LOGIN_URL"
  58. exit 1
  59. fi
  60. recho "已下载登录页面: $LOGIN_URL" "Downloaded login page: $LOGIN_URL"
  61. LOGIN_PATH="/usr/local/lib/pageos-greet/login-page.html"
  62. fi
  63. # 如果用户界面 ID 为空,则设为 pageos-ui | If the user interface ID is empty, set it to pageos-ui
  64. if [ -z "$UI_ID" ]; then
  65. UI_ID="pageos-ui"
  66. fi
  67. # 如果用户界面 ID 不为 pageos-ui 或登录页面路径不为空,替换 airootfs/etc/greetd/config.toml 中 pageos-session 的参数 | If the user interface ID is not pageos-ui or the login page path is not empty, replace the parameter pageos-session in airootfs/etc/greetd/config.toml
  68. if [ "$UI_ID" != "pageos-ui" ] || [ -n "$LOGIN_PATH" ]; then
  69. CONFIG_FILE="$REPO_DIR/airootfs/etc/greetd/config.toml"
  70. # 检查配置文件是否存在 | Check if the configuration file exists
  71. if [ ! -f "$CONFIG_FILE" ]; then
  72. recho "错误: 配置文件不存在: $CONFIG_FILE" "Error: Config file does not exist: $CONFIG_FILE"
  73. exit 1
  74. fi
  75. # 检查配置文件中是否存在要替换的行 | Check if the line to be replaced exists in the configuration file
  76. if ! grep -q 'command = "pageos-session pageos-ui"' "$CONFIG_FILE"; then
  77. recho "错误: 配置文件中未找到要替换的命令行" "Error: Command line to replace not found in config file"
  78. exit 1
  79. fi
  80. # 替换配置文件中的命令 | Replace the command in the configuration file
  81. sed -i "s|command = \"pageos-session pageos-ui\"|command = \"pageos-session $UI_ID $LOGIN_PATH\"|" "$CONFIG_FILE"
  82. if [ $? -ne 0 ]; then
  83. recho "错误: 无法更新配置文件" "Error: Failed to update config file"
  84. exit 1
  85. fi
  86. recho "已将用户界面 ID 设置为: $UI_ID" "User interface ID has been set to: $UI_ID"
  87. fi
  88. # 如果系统名称不为空,替换 profiledef.sh 中的 iso_name | If the system name is not empty, replace iso_name in profiledef.sh
  89. if [ -n "$SYS_NAME" ] && [ "$SYS_NAME" != "pageos" ]; then
  90. PROFILEDEF_FILE="$REPO_DIR/profiledef.sh"
  91. # 检查配置文件是否存在 | Check if the configuration file exists
  92. if [ ! -f "$PROFILEDEF_FILE" ]; then
  93. recho "错误: 配置文件不存在: $PROFILEDEF_FILE" "Error: Config file does not exist: $PROFILEDEF_FILE"
  94. exit 1
  95. fi
  96. # 检查配置文件中是否存在要替换的行 | Check if the line to be replaced exists in the configuration file
  97. if ! grep -q 'iso_name="pageos"' "$PROFILEDEF_FILE"; then
  98. recho "错误: 配置文件中未找到要替换的 iso_name 行" "Error: iso_name line to replace not found in config file"
  99. exit 1
  100. fi
  101. # 替换配置文件中的 iso_name | Replace the iso_name in the configuration file
  102. sed -i "s|iso_name=\"pageos\"|iso_name=\"$SYS_NAME\"|" "$PROFILEDEF_FILE"
  103. if [ $? -ne 0 ]; then
  104. recho "错误: 无法更新配置文件" "Error: Failed to update config file"
  105. exit 1
  106. fi
  107. recho "已将 ISO 名称设置为: $SYS_NAME" "ISO name has been set to: $SYS_NAME"
  108. fi