You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
4.9 KiB

  1. #!/bin/bash
  2. gitea_version=1.0.1
  3. tested_gogs_version="0.9.114.1227"
  4. gogs_binary=gogs
  5. gitea_binary=gitea
  6. download_gitea=true
  7. gitea_path=
  8. function usage() {
  9. echo "Optional parameters: [-b Gitea binary] [-i Gitea install dir] [-o gogs binary] [-h help]";
  10. exit 1;
  11. }
  12. while getopts ":b::i:o:h:" opt; do
  13. case $opt in
  14. b)
  15. gitea_binary=${OPTARG}
  16. download_gitea=false
  17. ;;
  18. i)
  19. gitea_path=${OPTARG}
  20. ;;
  21. o)
  22. gogs_binary=${OPTARG}
  23. ;;
  24. h)
  25. usage
  26. ;;
  27. \?)
  28. echo -e "Invalid option: -$OPTARG"
  29. exit 1
  30. ;;
  31. :)
  32. usage
  33. exit 1
  34. ;;
  35. esac
  36. done
  37. function exitOnError() {
  38. if [ "$?" != "0" ]; then
  39. echo -e $1
  40. exit 1
  41. fi
  42. }
  43. function checkBinary() {
  44. if [ ! -f $1 ]; then
  45. echo "Unable to find $1"
  46. exit 1
  47. fi
  48. }
  49. function continueYN(){
  50. while true; do
  51. echo -e "$1 Yes or No"
  52. read yn
  53. case $yn in
  54. [Yy]* ) break;;
  55. [Nn]* ) exit 1;;
  56. * ) echo "Please answer yes or no.";;
  57. esac
  58. done
  59. }
  60. ########## Binary checks
  61. if pidof "$gogs_binary" >/dev/null; then
  62. echo "Please stop gogs before migrating to Gitea"
  63. exit 1
  64. fi
  65. checkBinary "$gogs_binary"
  66. if [ ! -x "$gogs_binary" ]; then
  67. echo "Please make sure that you are running this script as the gogs user"
  68. exit 1
  69. fi
  70. ########## Version check
  71. gogs_version=$(./$gogs_binary --version)
  72. original_IFS=$IFS
  73. IFS="." && current_version=(${gogs_version#"Gogs version "}) && minimal_version=($tested_gogs_version)
  74. IFS=$original_IFS
  75. count=0
  76. for i in "${current_version[@]}"
  77. do
  78. if [ $i -gt ${minimal_version[$count]} ]; then
  79. echo -e "!!!--WARNING--!!!\nYour $gogs_version is newer than the tested Gogs version $tested_gogs_version\nUse this script on your own risk\n!!!--WARNING--!!!"
  80. break
  81. fi
  82. let count+=1
  83. done
  84. ########## Disclaimer
  85. continueYN "This migration script creates a backup before it starts with the actual migration
  86. If something goes wrong you could always resotre this backup.
  87. The backups are stored into your gogs folder in gogs-dump-[timestamp].zip file
  88. Migrating from gogs to gitea, are you sure?"
  89. ########## gogs dump
  90. echo "Creating a backup of gogs, this could take a while..."
  91. ./"$gogs_binary" dump
  92. exitOnError "Failed to create a gogs dump"
  93. ########## Create Gitea folder
  94. if [ -z "$gitea_path" ]; then
  95. echo "Where do you want to install Gitea?"
  96. read gitea_path
  97. fi
  98. if [ ! -d "$gitea_path" ]; then
  99. mkdir -p "$gitea_path"
  100. exitOnError
  101. fi
  102. if [ "$(ls -A $gitea_path)" ]; then
  103. continueYN "!!!--WARNING--!!!\nDirectory $gitea_path is not empty, do you want to continue?"
  104. fi
  105. ########## Download Gitea
  106. if [ $download_gitea == true ]; then
  107. ########## Detect os
  108. case "$OSTYPE" in
  109. darwin*) platform="darwin-10.6";;
  110. linux*) platform="linux" ;;
  111. freebsd*) platform="bsd" ;;
  112. netbsd*) platform="bsd" ;;
  113. openbsd*) platform="bsd" ;;
  114. *) echo "Unsupported os: $OSTYPE\n Please download/compile your own binary and run this script with the -b option" exit 1;;
  115. esac
  116. arch=""
  117. bits=""
  118. if [[ "$platform" == "linux" ]] || [[ "$platform" == "bsd" ]]; then
  119. arch="$(uname -m | sed -e 's/arm\(.*\)/arm-\1/' -e s/aarch64.*/arm64/)"
  120. fi
  121. if [[ "$platform" == "bsd" ]] && [[ "$arch" != "arm"* ]]; then
  122. echo "Currently Gitea only supports arm prebuilt binarys on bsd"
  123. exit 1
  124. fi
  125. if [[ "$arch" != "arm"* ]] && [[ "$arch" != "mips"* ]]; then
  126. arch=""
  127. case "$(getconf LONG_BIT)" in
  128. 64*) bits="amd64";;
  129. 32*) bits="386" ;;
  130. esac
  131. fi
  132. ########## Wget Gitea
  133. echo "Downloading Gitea"
  134. file="gitea-$gitea_version-$platform-$arch$bits"
  135. url="https://dl.gitea.io/gitea/$gitea_version/$file"
  136. wget "$url" -P "$gitea_path"
  137. exitOnError "Failed to download $url"
  138. wget "$url.sha256" -P "$gitea_path"
  139. exitOnError "Failed to Gitea checksum $url.sha256"
  140. echo "Comparing checksums"
  141. gogs_dir=$(pwd)
  142. cd "$gitea_path"
  143. sha256sum -c "$file.sha256"
  144. exitOnError "Downloaded Gitea checksums do not match"
  145. rm "$file.sha256"
  146. mv "$file" gitea
  147. cd "$gogs_dir"
  148. else
  149. checkBinary "$gitea_binary"
  150. if [ "$gitea_binary" != "$gitea_path/gitea" ];then
  151. cp "$gitea_binary" "$gitea_path/gitea"
  152. fi
  153. fi
  154. ########## Copy gogs data to Gitea folder
  155. echo "Copying gogs data to Gitea, this could take a while..."
  156. cp -R custom "$gitea_path"
  157. cp -R data "$gitea_path"
  158. #cp -R conf "$gitea_path"
  159. ########## Moving & deleting old files
  160. #mv $gitea_path/conf $gitea_path/options
  161. cd "$gitea_path"
  162. mv "custom/conf/app.ini" "custom/conf/gogs_app.ini"
  163. url="https://raw.githubusercontent.com/go-gitea/gitea/v$gitea_version/conf/app.ini"
  164. wget "$url" -P "custom/conf/"
  165. exitOnError "Unable to download Gitea app.ini"
  166. rm -f conf/README.md
  167. echo -e "Migration is almost complete, you only need to merge custom/conf/gogs_app.ini into custom/conf/app.ini"
  168. continueYN "Do you want to start Gitea?"
  169. ########## Starting Gitea
  170. echo "Starting Gitea"
  171. chmod +x gitea
  172. ./gitea web
  173. exitOnError "Failed to start Gitea"