Parcourir la source

Use gogs binary install

Bob Mottram il y a 8 ans
Parent
révision
0657232c73
2 fichiers modifiés avec 128 ajouts et 229 suppressions
  1. 119
    141
      src/freedombone-app-gogs
  2. 9
    88
      src/freedombone-utils-go

+ 119
- 141
src/freedombone-app-gogs Voir le fichier

@@ -30,12 +30,31 @@
30 30
 
31 31
 VARIANTS='full developer'
32 32
 
33
+GOGS_USERNAME='gogs'
34
+GOGS_VERSION='0.9.97'
35
+
33 36
 GIT_DOMAIN_NAME=
34 37
 GIT_CODE=
35 38
 GIT_ONION_PORT=8090
36
-GIT_DOMAIN_REPO="https://github.com/gogits/gogs"
37 39
 GIT_ADMIN_PASSWORD=
38
-GOGS_COMMIT='37305a59ca0cdc7efe880d4e54f68ecbe3eacc29'
40
+
41
+function gogs_parameters {
42
+    CURR_ARCH=
43
+    if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
44
+        CURR_ARCH=386
45
+    fi
46
+    if [[ $ARCHITECTURE == *"amd64" ]]; then
47
+        CURR_ARCH=amd64
48
+    fi
49
+    if [[ $ARCHITECTURE == *"arm"* ]]; then
50
+        CURR_ARCH=arm
51
+    fi
52
+    if [ ! $CURR_ARCH ]; then
53
+        return
54
+    fi
55
+
56
+    GOGS_BIN=https://github.com/gogits/gogs/releases/download/v${GOGS_VERSION}/linux_${CURR_ARCH}.tar.gz
57
+}
39 58
 
40 59
 function get_mariadb_git_admin_password {
41 60
     if [ -f /home/$MY_USERNAME/README ]; then
@@ -72,11 +91,37 @@ function upgrade_gogs {
72 91
         return
73 92
     fi
74 93
 
75
-    function_check select_go_version
76
-    select_go_version
94
+    if ! grep -q "Gogs version:" $COMPLETION_FILE; then
95
+        return
96
+    fi
77 97
 
78
-    function_check set_repo_commit
79
-    set_repo_commit $GOPATH/src/github.com/gogits/gogs "Gogs commit" "$GOGS_COMMIT" $GIT_DOMAIN_REPO
98
+    CURR_GOGS_VERSION=$(cat $COMPLETION_FILE | grep "Gogs version" | head -n 1 | awk -F ':' '{print $2}')
99
+    if [[ "$CURR_GOGS_VERSION" == "$GOGS_VERSION" ]]; then
100
+        return
101
+    fi
102
+
103
+    gogs_parameters
104
+
105
+    if [ ! -d ${INSTALL_DIR} ]; then
106
+        mkdir -p ${INSTALL_DIR}
107
+    fi
108
+    cd ${INSTALL_DIR}
109
+    if [ -f linux-${CURR_ARCH}.tar.gz ]; then
110
+        rm linux-${CURR_ARCH}.tar.gz
111
+    fi
112
+    wget ${GOGS_BIN}
113
+    if [ ! -f linux-${CURR_ARCH}.tar.gz ]; then
114
+        exit 37836
115
+    fi
116
+    tar -xzf ${INSTALL_DIR}/linux_${CURR_ARCH}.tar.gz
117
+    if [ ! -d $INSTALL_DIR/gogs ]; then
118
+        exit 37823
119
+    fi
120
+    cp -r $INSTALL_DIR/gogs /home/$GOGS_USERNAME
121
+    rm linux_${CURR_ARCH}.tar.gz
122
+
123
+    sed -i "s|Gogs version.*|Gogs version:$GOGS_VERSION|g" $COMPLETION_FILE
124
+    systemctl restart gogs
80 125
 }
81 126
 
82 127
 function backup_local_gogs {
@@ -84,7 +129,7 @@ function backup_local_gogs {
84 129
         return
85 130
     fi
86 131
 
87
-    if [ ! -d /home/git/gogs-repositories ]; then
132
+    if [ ! -d /home/$GOGS_USERNAME/gogs-repositories ]; then
88 133
         return
89 134
     fi
90 135
 
@@ -96,9 +141,9 @@ function backup_local_gogs {
96 141
     backup_database_to_usb gogs
97 142
 
98 143
     function_check backup_directory_to_usb
99
-    backup_directory_to_usb $GOPATH/src/github.com/gogits/gogs/custom gogs
100
-    backup_directory_to_usb /home/git/gogs-repositories gogsrepos
101
-    backup_directory_to_usb /home/git/.ssh gogsssh
144
+    backup_directory_to_usb /home/$GOGS_USERNAME/custom gogs
145
+    backup_directory_to_usb /home/$GOGS_USERNAME/gogs-repositories gogsrepos
146
+    backup_directory_to_usb /home/$GOGS_USERNAME/.ssh gogsssh
102 147
 
103 148
     echo $"Gogs backup complete"
104 149
 }
@@ -107,20 +152,12 @@ function restore_local_gogs {
107 152
     if ! grep -q "Gogs domain" $COMPLETION_FILE; then
108 153
         return
109 154
     fi
110
-    if [ ! -d /home/git/gogs-repositories ]; then
155
+    if [ ! -d /home/$GOGS_USERNAME/gogs-repositories ]; then
111 156
         return
112 157
     fi
113 158
 
114 159
     GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
115 160
 
116
-    export GVM_ROOT=$GVM_HOME
117
-    if [ -d $GVM_ROOT/bin ]; then
118
-        cd $GVM_ROOT/bin
119
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
120
-        gvm use go${GO_VERSION} --default
121
-        systemctl set-environment GOPATH=$GOPATH
122
-    fi
123
-
124 161
     if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
125 162
         function_check gogs_create_database
126 163
         gogs_create_database
@@ -130,10 +167,10 @@ function restore_local_gogs {
130 167
         temp_restore_dir=/root/tempgogs
131 168
         if [ -d $USB_MOUNT/backup/gogs ]; then
132 169
             echo $"Restoring Gogs settings"
133
-            if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
134
-                mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
170
+            if [ ! -d /home/$GOGS_USERNAME/custom ]; then
171
+                mkdir -p /home/$GOGS_USERNAME/custom
135 172
             fi
136
-            cp -r ${temp_restore_dir}/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom
173
+            cp -r ${temp_restore_dir}/home/$GOGS_USERNAME/custom/* /home/$GOGS_USERNAME/custom
137 174
             if [ ! "$?" = "0" ]; then
138 175
                 function_check set_user_permissions
139 176
                 set_user_permissions
@@ -144,7 +181,7 @@ function restore_local_gogs {
144 181
             echo $"Restoring Gogs repos"
145 182
             function_check restore_directory_from_usb
146 183
             restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
147
-            cp -r ${temp_restore_dir}repos/home/git/gogs-repositories/* /home/git/gogs-repositories/
184
+            cp -r ${temp_restore_dir}repos/home/$GOGS_USERNAME/gogs-repositories/* /home/$GOGS_USERNAME/gogs-repositories/
148 185
             if [ ! "$?" = "0" ]; then
149 186
                 function_check set_user_permissions
150 187
                 set_user_permissions
@@ -155,10 +192,10 @@ function restore_local_gogs {
155 192
             echo $"Restoring Gogs authorized_keys"
156 193
             function_check restore_directory_from_usb
157 194
             restore_directory_from_usb ${temp_restore_dir}ssh gogsssh
158
-            if [ ! -d /home/git/.ssh ]; then
159
-                mkdir /home/git/.ssh
195
+            if [ ! -d /home/$GOGS_USERNAME/.ssh ]; then
196
+                mkdir /home/$GOGS_USERNAME/.ssh
160 197
             fi
161
-            cp -r ${temp_restore_dir}ssh/home/git/.ssh/* /home/git/.ssh/
198
+            cp -r ${temp_restore_dir}ssh/home/$GOGS_USERNAME/.ssh/* /home/$GOGS_USERNAME/.ssh/
162 199
             if [ ! "$?" = "0" ]; then
163 200
                 function_check set_user_permissions
164 201
                 set_user_permissions
@@ -169,41 +206,33 @@ function restore_local_gogs {
169 206
             rm -rf ${temp_restore_dir}
170 207
             rm -rf ${temp_restore_dir}repos
171 208
             rm -rf ${temp_restore_dir}ssh
172
-            chown -R git:git /home/git
209
+            chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
173 210
         fi
174 211
     fi
175 212
 }
176 213
 
177 214
 function backup_remote_gogs {
178
-    export GVM_ROOT=/home/git/gvm
179
-    if [ -d $GVM_ROOT/bin ]; then
180
-        cd $GVM_ROOT/bin
181
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
182
-        gvm use go${GO_VERSION} --default
183
-        systemctl set-environment GOPATH=$GOPATH
184
-    fi
185
-
186
-    if [ -d $GOPATH/src/github.com/gogits ]; then
215
+    if [ -d /home/$GOGS_USERNAME ]; then
187 216
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
188 217
         function_check suspend_site
189 218
         suspend_site ${GIT_DOMAIN_NAME}
190 219
 
191 220
         function_check backup_database_to_friend
192
-        backup_database_to_friend gogs
221
+        backup_database_to_friend $GOGS_USERNAME
193 222
 
194 223
         echo $"Obtaining Gogs settings backup"
195 224
 
196 225
         function_check backup_directory_to_friend
197
-        backup_directory_to_friend $GOPATH/src/github.com/gogits/gogs/custom gogs
226
+        backup_directory_to_friend /home/$GOGS_USERNAME/custom gogs
198 227
 
199 228
         echo $"Obtaining Gogs repos backup"
200 229
 
201
-        mv /home/git/gogs-repositories/*.git /home/git/gogs-repositories/bob
202
-        backup_directory_to_friend /home/git/gogs-repositories gogsrepos
230
+        mv /home/$GOGS_USERNAME/gogs-repositories/*.git /home/$GOGS_USERNAME/gogs-repositories/bob
231
+        backup_directory_to_friend /home/$GOGS_USERNAME/gogs-repositories gogsrepos
203 232
 
204 233
         echo $"Obtaining Gogs authorized_keys backup"
205 234
 
206
-        backup_directory_to_friend /home/git/.ssh gogsssh
235
+        backup_directory_to_friend /home/$GOGS_USERNAME/.ssh gogsssh
207 236
 
208 237
         function_check restart_site
209 238
         restart_site
@@ -213,14 +242,6 @@ function backup_remote_gogs {
213 242
 }
214 243
 
215 244
 function restore_remote_gogs {
216
-    export GVM_ROOT=$GVM_HOME
217
-    if [ -d $GVM_ROOT/bin ]; then
218
-        cd $GVM_ROOT/bin
219
-        [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
220
-        gvm use go${GO_VERSION} --default
221
-        systemctl set-environment GOPATH=$GOPATH
222
-    fi
223
-
224 245
     if grep -q "Gogs domain" $COMPLETION_FILE; then
225 246
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
226 247
 
@@ -230,32 +251,32 @@ function restore_remote_gogs {
230 251
         function_check restore_database_from_friend
231 252
         restore_database_from_friend gogs $GIT_DOMAIN_NAME
232 253
         if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
233
-            if [ ! -d $GOPATH/src/github.com/gogits/gogs/custom ]; then
234
-                mkdir -p $GOPATH/src/github.com/gogits/gogs/custom
254
+            if [ ! -d /home/$GOGS_USERNAME/custom ]; then
255
+                mkdir -p /home/$GOGS_USERNAME/custom
235 256
             fi
236
-            cp -r /root/tempgogs/$GOPATH/src/github.com/gogits/gogs/custom/* $GOPATH/src/github.com/gogits/gogs/custom/
257
+            cp -r /root/tempgogs/home/$GOGS_USERNAME/custom/* /home/$GOGS_USERNAME/custom/
237 258
             if [ ! "$?" = "0" ]; then
238
-                exit 5885
259
+                exit 58852
239 260
             fi
240 261
             echo $"Restoring Gogs repos"
241 262
             restore_directory_from_friend /root/tempgogsrepos gogsrepos
242
-            cp -r /root/tempgogsrepos/home/git/gogs-repositories/* /home/git/gogs-repositories/
263
+            cp -r /root/tempgogsrepos/home/$GOGS_USERNAME/gogs-repositories/* /home/$GOGS_USERNAME/gogs-repositories/
243 264
             if [ ! "$?" = "0" ]; then
244 265
                 exit 7649
245 266
             fi
246 267
             echo $"Restoring Gogs authorized_keys"
247 268
             restore_directory_from_friend /root/tempgogsssh gogsssh
248
-            if [ ! -d /home/git/.ssh ]; then
249
-                mkdir /home/git/.ssh
269
+            if [ ! -d /home/$GOGS_USERNAME/.ssh ]; then
270
+                mkdir /home/$GOGS_USERNAME/.ssh
250 271
             fi
251
-            cp -r /root/tempgogsssh/home/git/.ssh/* /home/git/.ssh/
272
+            cp -r /root/tempgogsssh/home/$GOGS_USERNAME/.ssh/* /home/$GOGS_USERNAME/.ssh/
252 273
             if [ ! "$?" = "0" ]; then
253 274
                 exit 74239
254 275
             fi
255 276
             rm -rf /root/tempgogs
256 277
             rm -rf /root/tempgogsrepos
257 278
             rm -rf /root/tempgogsssh
258
-            chown -R git:git /home/git
279
+            chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
259 280
             echo $"Restore of Gogs complete"
260 281
         fi
261 282
     fi
@@ -280,7 +301,7 @@ function remove_gogs {
280 301
     function_check drop_database
281 302
     drop_database gogs
282 303
     rm /etc/systemd/system/gogs.service
283
-    rm -rf $GOPATH/src/github.com/gogits
304
+    rm -rf /home/$GOGS_USERNAME/*
284 305
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
285 306
     sed -i '/install_gogs/d' $COMPLETION_FILE
286 307
     sed -i '/Gogs /d' $COMPLETION_FILE
@@ -295,83 +316,37 @@ function install_gogs {
295 316
         return
296 317
     fi
297 318
 
298
-    function_check select_go_version
299
-    select_go_version
319
+    adduser --disabled-login --gecos 'Gogs' $GOGS_USERNAME
300 320
 
301
-    if [ -d $GOPATH/src/github.com/gogits ]; then
302
-        rm -rf $GOPATH/src/github.com/gogits
303
-    fi
321
+    gogs_parameters
304 322
 
305
-    if [ -d /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits ]; then
306
-        rm -rf /home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits
323
+    if [ ! -d ${INSTALL_DIR} ]; then
324
+        mkdir -p ${INSTALL_DIR}
307 325
     fi
308
-
309
-    if [ -d /home/git/gogs-repositories ]; then
310
-        rm -rf /home/git/gogs-repositories
326
+    cd ${INSTALL_DIR}
327
+    if [ -f linux-${CURR_ARCH}.tar.gz ]; then
328
+        rm linux-${CURR_ARCH}.tar.gz
311 329
     fi
312
-
313
-    if [ ! -d /home/git ]; then
314
-        # add a gogs user account
315
-        adduser --disabled-login --gecos 'Gogs' git
330
+    wget ${GOGS_BIN}
331
+    if [ ! -f linux-${CURR_ARCH}.tar.gz ]; then
332
+        exit 37836
316 333
     fi
317
-    if [ -d /home/git/Maildir ]; then
318
-        rm -rf /home/git/Maildir
334
+    tar -xzf ${INSTALL_DIR}/linux_${CURR_ARCH}.tar.gz
335
+    if [ ! -d $INSTALL_DIR/gogs ]; then
336
+        exit 37823
319 337
     fi
338
+    cp -r $INSTALL_DIR/gogs /home/$GOGS_USERNAME
339
+    rm linux_${CURR_ARCH}.tar.gz
320 340
 
321
-    if [ -d $GOPATH/src/github.com/gogits ]; then
322
-        rm -rf $GOPATH/src/github.com/gogits
341
+    if [ ! -f /home/$GOGS_USERNAME/gogs ]; then
342
+        echo 'Gogs binary not installed'
343
+        exit 345562
323 344
     fi
324 345
 
325
-    # install Go
326
-    apt-get -y install golang libpam0g-dev
327
-    if ! grep -q "export GOPATH=" ~/.bashrc; then
328
-        echo "export GOPATH=$GOPATH" >> ~/.bashrc
329
-    else
330
-        sed -i "s|export GOPATH=.*|export GOPATH=$GOPATH|g" ~/.bashrc
331
-    fi
332
-    systemctl set-environment GOPATH=$GOPATH
333
-    if ! grep -q "systemctl set-environment GOPATH=" ~/.bashrc; then
334
-        echo "systemctl set-environment GOPATH=$GOPATH" >> ~/.bashrc
335
-    else
336
-        sed -i "s|systemctl set-environment GOPATH=.*|systemctl set-environment GOPATH=$GOPATH|g" ~/.bashrc
337
-    fi
338
-    if [ ! -d $GOPATH ]; then
339
-        mkdir -p $GOPATH
340
-    fi
341
-    GO_PACKAGE_MANAGER_REPO2=$(echo "$GO_PACKAGE_MANAGER_REPO" | sed 's|https://||g')
342
-    go get -u $GO_PACKAGE_MANAGER_REPO2
343
-    if [ ! "$?" = "0" ]; then
344
-        echo $'install_gogs: go get failed'
345
-        exit 479832
346
-    fi
347
-
348
-    # clone the repo
349
-    if [ ! -d $GOPATH/src/github.com/gogits ]; then
350
-        mkdir -p $GOPATH/src/github.com/gogits
351
-    fi
352
-    function_check git_clone
353
-    git_clone $GIT_DOMAIN_REPO $GOPATH/src/github.com/gogits/gogs
354
-    if [ ! -d $GOPATH/src/github.com/gogits/gogs ]; then
355
-        echo $"Unable to clone repo $GOPATH/src/github.com/gogits/gogs"
356
-        exit 85482
357
-    fi
358
-    cd $GOPATH/src/github.com/gogits/gogs
359
-
360
-    # install
361
-    go get -u ./...
362
-
363
-    git checkout $GOGS_COMMIT -b $GOGS_COMMIT
364
-    if ! grep -q "Gogs commit" $COMPLETION_FILE; then
365
-        echo "Gogs commit:$GOGS_COMMIT" >> $COMPLETION_FILE
366
-    else
367
-        sed -i "s/Gogs commit.*/Gogs commit:$GOGS_COMMIT/g" $COMPLETION_FILE
368
-    fi
369
-
370
-    go build
371
-    if [ ! "$?" = "0" ]; then
372
-        echo $'install_gogs: go build failed'
373
-        exit 546750
374
-    fi
346
+    echo "export GOROOT=/home/go" >> /home/$GOGS_USERNAME/.bashrc
347
+    echo "export GOPATH=\$GOROOT/go${GO_VERSION}/bin" >> /home/$GOGS_USERNAME/.bashrc
348
+    echo 'export PATH=$PATH:$GOPATH' >> /home/$GOGS_USERNAME/.bashrc
349
+    chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
375 350
 
376 351
     function_check install_mariadb
377 352
     install_mariadb
@@ -382,7 +357,7 @@ function install_gogs {
382 357
     function_check
383 358
     gogs_create_database
384 359
 
385
-    if [ ! -f $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql ]; then
360
+    if [ ! -f /home/$GOGS_USERNAME/scripts/mysql.sql ]; then
386 361
         echo $'MySql template for Gogs was not found'
387 362
         exit 72528
388 363
     fi
@@ -417,11 +392,10 @@ function install_gogs {
417 392
     fi
418 393
 
419 394
     function_check initialise_database
420
-    initialise_database gogs $GOPATH/src/github.com/gogits/gogs/scripts/mysql.sql
395
+    initialise_database gogs /home/$GOGS_USERNAME/scripts/mysql.sql
421 396
 
422
-    chmod 600 $GOPATH/src/github.com/gogits/gogs/custom/conf/app.ini
397
+    chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
423 398
 
424
-    chown -R git:git /home/git
425 399
     echo '[Unit]' > /etc/systemd/system/gogs.service
426 400
     echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service
427 401
     echo 'After=syslog.target' >> /etc/systemd/system/gogs.service
@@ -432,14 +406,13 @@ function install_gogs {
432 406
     echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service
433 407
     echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service
434 408
     echo 'Type=simple' >> /etc/systemd/system/gogs.service
435
-    echo 'User=git' >> /etc/systemd/system/gogs.service
436
-    echo 'Group=git' >> /etc/systemd/system/gogs.service
437
-    echo "WorkingDirectory=$GOPATH/src/github.com/gogits/gogs" >> /etc/systemd/system/gogs.service
438
-    echo "ExecStart=$GOPATH/src/github.com/gogits/gogs/gogs web" >> /etc/systemd/system/gogs.service
409
+    echo 'User=gogs' >> /etc/systemd/system/gogs.service
410
+    echo 'Group=some_group' >> /etc/systemd/system/gogs.service
411
+    echo 'WorkingDirectory=/home/$GOGS_USERNAME' >> /etc/systemd/system/gogs.service
412
+    echo 'ExecStart=/home/$GOGS_USERNAME/gogs web' >> /etc/systemd/system/gogs.service
439 413
     echo 'Restart=always' >> /etc/systemd/system/gogs.service
440 414
     echo 'RestartSec=10' >> /etc/systemd/system/gogs.service
441
-    echo 'TimeoutStartSec=120' >> /etc/systemd/system/gogs.service
442
-    echo "Environment=\"USER=git\" \"HOME=/home/git\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/gogs.service
415
+    echo "Environment=\"USER=$GOGS_USERNAME\" \"HOME=/home/$GOGS_USERNAME\" \"GOPATH=$GOPATH\" \"GVM_ROOT=$GVM_HOME\"" >> /etc/systemd/system/gogs.service
443 416
     echo '' >> /etc/systemd/system/gogs.service
444 417
     echo '[Install]' >> /etc/systemd/system/gogs.service
445 418
     echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service
@@ -574,12 +547,12 @@ function install_gogs {
574 547
     fi
575 548
 
576 549
     # create the configuration
577
-    GOGS_CONFIG_PATH=/home/git/gvm/pkgsets/go${GO_VERSION}/global/src/github.com/gogits/gogs/custom/conf
550
+    GOGS_CONFIG_PATH=/home/$GOGS_USERNAME/custom/conf
578 551
     if [ ! -d $GOGS_CONFIG_PATH ]; then
579 552
         mkdir -p $GOGS_CONFIG_PATH
580 553
     fi
581 554
     GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini
582
-    echo 'RUN_USER = git' > $GOGS_CONFIG_FILE
555
+    echo "RUN_USER = $GOGS_USERNAME" > $GOGS_CONFIG_FILE
583 556
     echo 'RUN_MODE = prod' >> $GOGS_CONFIG_FILE
584 557
     echo '' >> $GOGS_CONFIG_FILE
585 558
     echo '[database]' >> $GOGS_CONFIG_FILE
@@ -592,7 +565,7 @@ function install_gogs {
592 565
     echo 'PATH = data/gogs.db' >> $GOGS_CONFIG_FILE
593 566
     echo '' >> $GOGS_CONFIG_FILE
594 567
     echo '[repository]' >> $GOGS_CONFIG_FILE
595
-    echo 'ROOT = /home/git/gogs-repositories' >> $GOGS_CONFIG_FILE
568
+    echo "ROOT = /home/$GOGS_USERNAME/gogs-repositories" >> $GOGS_CONFIG_FILE
596 569
     echo '' >> $GOGS_CONFIG_FILE
597 570
     echo '[server]' >> $GOGS_CONFIG_FILE
598 571
     if [[ $ONION_ONLY == 'no' ]]; then
@@ -630,7 +603,7 @@ function install_gogs {
630 603
     echo 'SHOW_FOOTER_VERSION = false' >> $GOGS_CONFIG_FILE
631 604
 
632 605
     chmod 750 $GOGS_CONFIG_FILE
633
-    chown -R git:git /home/git
606
+    chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
634 607
 
635 608
     systemctl restart gogs
636 609
 
@@ -640,6 +613,11 @@ function install_gogs {
640 613
 
641 614
     function_check configure_firewall_for_git
642 615
     configure_firewall_for_git
616
+    if ! grep -q "Gogs version:" $COMPLETION_FILE; then
617
+        echo "Gogs version:$GOGS_VERSION" >> $COMPLETION_FILE
618
+    else
619
+        sed -i "s|Gogs version.*|Gogs version:$GOGS_VERSION|g" $COMPLETION_FILE
620
+    fi
643 621
     echo 'install_gogs' >> $COMPLETION_FILE
644 622
 }
645 623
 

+ 9
- 88
src/freedombone-utils-go Voir le fichier

@@ -131,7 +131,10 @@ EOF
131 131
 }
132 132
 
133 133
 function mesh_upgrade_golang {
134
-    chroot "$rootdir" adduser --disabled-login --gecos 'go' go
134
+    prefix=
135
+    if [ $rootdir ]; then
136
+        prefix="chroot $rootdir"
137
+    $prefix adduser --disabled-login --gecos 'go' go
135 138
 
136 139
     GOARCH=
137 140
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
@@ -157,7 +160,7 @@ function mesh_upgrade_golang {
157 160
     if [ ! -f ${rootdir}${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz ]; then
158 161
         exit 26524
159 162
     fi
160
-    chroot "$rootdir" tar -C /home/go -xzf ${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz
163
+    $prefix tar -C /home/go -xzf ${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz
161 164
     if [ ! -d ${rootdir}/home/go/go/bin ]; then
162 165
         echo 'Go binary not installed'
163 166
         exit 763562
@@ -174,8 +177,8 @@ function mesh_upgrade_golang {
174 177
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/root/.bashrc
175 178
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/$MY_USERNAME/.bashrc
176 179
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/go/.bashrc
177
-    chroot "$rootdir" chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME
178
-    chroot "$rootdir" chown -R go:go /home/go
180
+    $prefix chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME
181
+    $prefix chown -R go:go /home/go
179 182
     cp ${rootdir}/home/go/go${GO_VERSION}/bin/* ${rootdir}/usr/bin
180 183
 }
181 184
 
@@ -184,90 +187,8 @@ function upgrade_golang {
184 187
         return
185 188
     fi
186 189
 
187
-    # NOTE: this is annoyingly hacky and going in the opposite
188
-    # direction of a pure blend, but it's necessary if you want
189
-    # to run the latest version of gogs
190
-
191
-    # update to the next commit
192
-    function_check set_repo_commit
193
-    set_repo_commit $INSTALL_DIR/gvm "gvm commit" "$GVM_COMMIT" $GVM_REPO
194
-
195
-    if grep -Fxq "upgrade_golang" $COMPLETION_FILE; then
196
-        return
197
-    fi
198
-
199
-    export GVM_ROOT=$GVM_HOME
200
-
201
-    apt-get -y install build-essential libc6-dev-i386 gcc-multilib g++-multilib
202
-    apt-get -y install gcc curl git mercurial make binutils bison
203
-    if [ ! -d $INSTALL_DIR ]; then
204
-        mkdir $INSTALL_DIR
205
-    fi
206
-    cd $INSTALL_DIR
207
-    function_check git_clone
208
-    git_clone $GVM_REPO gvm
209
-    cd $INSTALL_DIR/gvm
210
-    git checkout $GVM_COMMIT -b $GVM_COMMIT
211
-    if [ ! -f binscripts/gvm-installer ]; then
212
-        echo $'gvm installer not found'
213
-    fi
214
-    chmod +x binscripts/gvm-installer
215
-
216
-    if [ -d /root/.gvm ]; then
217
-        rm -rf /root/.gvm
218
-    fi
219
-    if [ -d $GVM_ROOT ]; then
220
-        rm -rf $GVM_ROOT
221
-    fi
222
-    sed -i "s|export GVM_ROOT=.*|export GVM_ROOT=$GVM_ROOT|g" ~/.bashrc
223
-
224
-    if [ ! -d /home/git ]; then
225
-        # add a gogs user account within which the gvm home directory will exist
226
-        adduser --disabled-login --gecos 'Gogs' git
227
-    fi
228
-    if [ -d /home/git/Maildir ]; then
229
-        rm -rf /home/git/Maildir
230
-    fi
231
-
232
-    # TODO: this script is all over the place
233
-    # and contains hardcoded github. See if you can do better
234
-    ./binscripts/gvm-installer master /home/git
235
-
236
-    if [ ! -d $GVM_ROOT ]; then
237
-        echo $'Unable to install gvm'
238
-        exit 83537
239
-    fi
240
-
241
-    [[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
242
-    if [ ! -f $GVM_ROOT/bin/gvm ]; then
243
-        echo $'gvm was not installed'
244
-    fi
245
-    if ! grep -q "export GVM_ROOT=" ~/.bashrc; then
246
-        echo "export GVM_ROOT=$GVM_ROOT" >> ~/.bashrc
247
-    fi
248
-    if ! grep -q 'PATH=$PATH:$GVM_ROOT/bin' ~/.bashrc; then
249
-        echo 'PATH=$PATH:$GVM_ROOT/bin' >> ~/.bashrc
250
-    fi
251
-
252
-    export GOROOT_BOOTSTRAP=$GOROOT
253
-
254
-    cd $GVM_ROOT/bin
255
-    gvm install go${GO_INTERMEDIATE_VERSION}
256
-    gvm use go${GO_INTERMEDIATE_VERSION}
257
-    gvm install go${GO_VERSION}
258
-    if [ ! "$?" = "0" ]; then
259
-        echo $'Unable to upgrade golang'
260
-        exit 529252
261
-    fi
262
-    gvm use go${GO_VERSION} --default
263
-
264
-    chown -R git:git $GVM_HOME
265
-
266
-    if ! grep -q "gvm commit" $COMPLETION_FILE; then
267
-        echo "gvm commit:$GVM_COMMIT" >> $COMPLETION_FILE
268
-    else
269
-        sed -i "s/gvm commit.*/gvm commit:$GVM_COMMIT/g" $COMPLETION_FILE
270
-    fi
190
+    rootdir=
191
+    mesh_upgrade_golang
271 192
 
272 193
     echo 'upgrade_golang' >> $COMPLETION_FILE
273 194
 }