start.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # @Contact : liuyuqi.gov@msn.cn
  3. # @Time : 2023/12/17 03:57:36
  4. # @License : (C)Copyright 2022 liuyuqi.
  5. # @Desc : 执行 /opt/repo_sync/repo_sync 命令
  6. # 传入两个参数,/opt/repo_sync/repo_sync create --platform github --repo_path /home/workspace/xx
  7. ###############################################################################
  8. function install() {
  9. echo "开始安装"
  10. cd /opt
  11. mkdir repo_sync
  12. cd repo_sync
  13. wget https://fileshare.yoqi.me/repo_sync/repo_sync
  14. chmod +x repo_sync
  15. echo '.env' >> .env
  16. echo "export PATH=$PATH:/opt/repo_sync" >> /etc/profile
  17. echo "安装完成"
  18. }
  19. function uninstall() {
  20. echo "开始卸载"
  21. rm -rf /opt/repo_sync
  22. sed -i '/repo_sync/d' /etc/profile
  23. echo "卸载完成"
  24. }
  25. # 打印logo,用户使用指南
  26. function print_logo() {
  27. echo -e "\033[32
  28. repo sync 项目同步工具 v1.0
  29. 作者:liuyuqi
  30. Usage:
  31. repo_sync create --platform github --repo_path /home/workspace/xx
  32. repo_sync delete --platform github --repo_path /home/workspace/xx
  33. repo_sync update --platform github --repo_path /home/workspace/xx
  34. repo_sync list --platform github --repo_path /home/workspace/xx
  35. repo_sync help
  36. \033[0m"
  37. }
  38. print_logo
  39. while true; do
  40. echo "请输入操作,create(1),push(2),pull(3),delete(4), 回车默认1"
  41. read -p "请输入操作:" action
  42. if [ $action == 1 ] || [ $action == 2 ] || [ $action == 3 ] || [ $action == 4 ] || [ $action == 5 ] || [ $action == 6 ] || [ $action == 7 ]; then
  43. break
  44. fi
  45. done
  46. while true; do
  47. # 请输入平台,github(1),gitlab(2),coding(3),gitee(4),gogs(5)
  48. echo "请输入平台,github(1),gitlab(2),coding(3),gitee(4),gogs(5)"
  49. read -p "请输入平台:" platform
  50. if [ $platform == 1 ] || [ $platform == 2 ] || [ $platform == 3 ] || [ $platform == 4 ] || [ $platform == 5 ]; then
  51. if [ $platform == 1 ]; then
  52. platform="github"
  53. elif [ $platform == 2 ]; then
  54. platform="gitlab"
  55. elif [ $platform == 3 ]; then
  56. platform="coding"
  57. elif [ $platform == 4 ]; then
  58. platform="gitee"
  59. elif [ $platform == 5 ]; then
  60. platform="gogs"
  61. fi
  62. break
  63. fi
  64. done
  65. # 请输入仓库路径,/home/workspace/xx
  66. echo "请输入仓库路径,/home/workspace/xx"
  67. read -p "请输入仓库路径:" repo_path
  68. cd /opt/repo_sync
  69. if [ $action == 1 ]; then
  70. /opt/repo_sync/repo_sync create --platform $platform --repo_path $repo_path
  71. elif [ $action == 2 ]; then
  72. /opt/repo_sync/repo_sync push --platform $platform --repo_path $repo_path
  73. elif [ $action == 3 ]; then
  74. /opt/repo_sync/repo_sync pull --platform $platform --repo_path $repo_path
  75. elif [ $action == 4 ]; then
  76. /opt/repo_sync/repo_sync delete --platform $platform --repo_path $repo_path
  77. elif [ $action == 5 ]; then
  78. /opt/repo_sync/repo_sync update --platform $platform --repo_path $repo_path
  79. elif [ $action == 6 ]; then
  80. /opt/repo_sync/repo_sync list --platform $platform --repo_path $repo_path
  81. elif [ $action == 7 ]; then
  82. print_logo
  83. else
  84. print_logo
  85. fi