Skip to content

Commit 75f0b0c

Browse files
Bwkolunny
authored andcommitted
Added gogs migration script (#532)
1 parent 833f8b9 commit 75f0b0c

File tree

1 file changed

+206
-0
lines changed

1 file changed

+206
-0
lines changed

scripts/migrate/gogs_migrate.sh

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

0 commit comments

Comments
 (0)