ソースを参照

Use gogs binary install

Bob Mottram 8 年 前
コミット
0657232c73
共有2 個のファイルを変更した128 個の追加229 個の削除を含む
  1. 119
    141
      src/freedombone-app-gogs
  2. 9
    88
      src/freedombone-utils-go

+ 119
- 141
src/freedombone-app-gogs ファイルの表示

30
 
30
 
31
 VARIANTS='full developer'
31
 VARIANTS='full developer'
32
 
32
 
33
+GOGS_USERNAME='gogs'
34
+GOGS_VERSION='0.9.97'
35
+
33
 GIT_DOMAIN_NAME=
36
 GIT_DOMAIN_NAME=
34
 GIT_CODE=
37
 GIT_CODE=
35
 GIT_ONION_PORT=8090
38
 GIT_ONION_PORT=8090
36
-GIT_DOMAIN_REPO="https://github.com/gogits/gogs"
37
 GIT_ADMIN_PASSWORD=
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
 function get_mariadb_git_admin_password {
59
 function get_mariadb_git_admin_password {
41
     if [ -f /home/$MY_USERNAME/README ]; then
60
     if [ -f /home/$MY_USERNAME/README ]; then
72
         return
91
         return
73
     fi
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
 function backup_local_gogs {
127
 function backup_local_gogs {
84
         return
129
         return
85
     fi
130
     fi
86
 
131
 
87
-    if [ ! -d /home/git/gogs-repositories ]; then
132
+    if [ ! -d /home/$GOGS_USERNAME/gogs-repositories ]; then
88
         return
133
         return
89
     fi
134
     fi
90
 
135
 
96
     backup_database_to_usb gogs
141
     backup_database_to_usb gogs
97
 
142
 
98
     function_check backup_directory_to_usb
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
     echo $"Gogs backup complete"
148
     echo $"Gogs backup complete"
104
 }
149
 }
107
     if ! grep -q "Gogs domain" $COMPLETION_FILE; then
152
     if ! grep -q "Gogs domain" $COMPLETION_FILE; then
108
         return
153
         return
109
     fi
154
     fi
110
-    if [ ! -d /home/git/gogs-repositories ]; then
155
+    if [ ! -d /home/$GOGS_USERNAME/gogs-repositories ]; then
111
         return
156
         return
112
     fi
157
     fi
113
 
158
 
114
     GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
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
     if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
161
     if [ ${#GIT_DOMAIN_NAME} -gt 2 ]; then
125
         function_check gogs_create_database
162
         function_check gogs_create_database
126
         gogs_create_database
163
         gogs_create_database
130
         temp_restore_dir=/root/tempgogs
167
         temp_restore_dir=/root/tempgogs
131
         if [ -d $USB_MOUNT/backup/gogs ]; then
168
         if [ -d $USB_MOUNT/backup/gogs ]; then
132
             echo $"Restoring Gogs settings"
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
             fi
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
             if [ ! "$?" = "0" ]; then
174
             if [ ! "$?" = "0" ]; then
138
                 function_check set_user_permissions
175
                 function_check set_user_permissions
139
                 set_user_permissions
176
                 set_user_permissions
144
             echo $"Restoring Gogs repos"
181
             echo $"Restoring Gogs repos"
145
             function_check restore_directory_from_usb
182
             function_check restore_directory_from_usb
146
             restore_directory_from_usb ${temp_restore_dir}repos gogsrepos
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
             if [ ! "$?" = "0" ]; then
185
             if [ ! "$?" = "0" ]; then
149
                 function_check set_user_permissions
186
                 function_check set_user_permissions
150
                 set_user_permissions
187
                 set_user_permissions
155
             echo $"Restoring Gogs authorized_keys"
192
             echo $"Restoring Gogs authorized_keys"
156
             function_check restore_directory_from_usb
193
             function_check restore_directory_from_usb
157
             restore_directory_from_usb ${temp_restore_dir}ssh gogsssh
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
             fi
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
             if [ ! "$?" = "0" ]; then
199
             if [ ! "$?" = "0" ]; then
163
                 function_check set_user_permissions
200
                 function_check set_user_permissions
164
                 set_user_permissions
201
                 set_user_permissions
169
             rm -rf ${temp_restore_dir}
206
             rm -rf ${temp_restore_dir}
170
             rm -rf ${temp_restore_dir}repos
207
             rm -rf ${temp_restore_dir}repos
171
             rm -rf ${temp_restore_dir}ssh
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
         fi
210
         fi
174
     fi
211
     fi
175
 }
212
 }
176
 
213
 
177
 function backup_remote_gogs {
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
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
216
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
188
         function_check suspend_site
217
         function_check suspend_site
189
         suspend_site ${GIT_DOMAIN_NAME}
218
         suspend_site ${GIT_DOMAIN_NAME}
190
 
219
 
191
         function_check backup_database_to_friend
220
         function_check backup_database_to_friend
192
-        backup_database_to_friend gogs
221
+        backup_database_to_friend $GOGS_USERNAME
193
 
222
 
194
         echo $"Obtaining Gogs settings backup"
223
         echo $"Obtaining Gogs settings backup"
195
 
224
 
196
         function_check backup_directory_to_friend
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
         echo $"Obtaining Gogs repos backup"
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
         echo $"Obtaining Gogs authorized_keys backup"
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
         function_check restart_site
237
         function_check restart_site
209
         restart_site
238
         restart_site
213
 }
242
 }
214
 
243
 
215
 function restore_remote_gogs {
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
     if grep -q "Gogs domain" $COMPLETION_FILE; then
245
     if grep -q "Gogs domain" $COMPLETION_FILE; then
225
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
246
         GIT_DOMAIN_NAME=$(cat $COMPLETION_FILE | grep "Gogs domain" | awk -F ':' '{print $2}')
226
 
247
 
230
         function_check restore_database_from_friend
251
         function_check restore_database_from_friend
231
         restore_database_from_friend gogs $GIT_DOMAIN_NAME
252
         restore_database_from_friend gogs $GIT_DOMAIN_NAME
232
         if [ -d $SERVER_DIRECTORY/backup/gogs ]; then
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
             fi
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
             if [ ! "$?" = "0" ]; then
258
             if [ ! "$?" = "0" ]; then
238
-                exit 5885
259
+                exit 58852
239
             fi
260
             fi
240
             echo $"Restoring Gogs repos"
261
             echo $"Restoring Gogs repos"
241
             restore_directory_from_friend /root/tempgogsrepos gogsrepos
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
             if [ ! "$?" = "0" ]; then
264
             if [ ! "$?" = "0" ]; then
244
                 exit 7649
265
                 exit 7649
245
             fi
266
             fi
246
             echo $"Restoring Gogs authorized_keys"
267
             echo $"Restoring Gogs authorized_keys"
247
             restore_directory_from_friend /root/tempgogsssh gogsssh
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
             fi
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
             if [ ! "$?" = "0" ]; then
273
             if [ ! "$?" = "0" ]; then
253
                 exit 74239
274
                 exit 74239
254
             fi
275
             fi
255
             rm -rf /root/tempgogs
276
             rm -rf /root/tempgogs
256
             rm -rf /root/tempgogsrepos
277
             rm -rf /root/tempgogsrepos
257
             rm -rf /root/tempgogsssh
278
             rm -rf /root/tempgogsssh
258
-            chown -R git:git /home/git
279
+            chown -R $GOGS_USERNAME:$GOGS_USERNAME /home/$GOGS_USERNAME
259
             echo $"Restore of Gogs complete"
280
             echo $"Restore of Gogs complete"
260
         fi
281
         fi
261
     fi
282
     fi
280
     function_check drop_database
301
     function_check drop_database
281
     drop_database gogs
302
     drop_database gogs
282
     rm /etc/systemd/system/gogs.service
303
     rm /etc/systemd/system/gogs.service
283
-    rm -rf $GOPATH/src/github.com/gogits
304
+    rm -rf /home/$GOGS_USERNAME/*
284
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
305
     remove_onion_service gogs ${GIT_ONION_PORT} 9418
285
     sed -i '/install_gogs/d' $COMPLETION_FILE
306
     sed -i '/install_gogs/d' $COMPLETION_FILE
286
     sed -i '/Gogs /d' $COMPLETION_FILE
307
     sed -i '/Gogs /d' $COMPLETION_FILE
295
         return
316
         return
296
     fi
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
     fi
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
     fi
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
     fi
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
     fi
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
     fi
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
     function_check install_mariadb
351
     function_check install_mariadb
377
     install_mariadb
352
     install_mariadb
382
     function_check
357
     function_check
383
     gogs_create_database
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
         echo $'MySql template for Gogs was not found'
361
         echo $'MySql template for Gogs was not found'
387
         exit 72528
362
         exit 72528
388
     fi
363
     fi
417
     fi
392
     fi
418
 
393
 
419
     function_check initialise_database
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
     echo '[Unit]' > /etc/systemd/system/gogs.service
399
     echo '[Unit]' > /etc/systemd/system/gogs.service
426
     echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service
400
     echo 'Description=Gogs (Go Git Service)' >> /etc/systemd/system/gogs.service
427
     echo 'After=syslog.target' >> /etc/systemd/system/gogs.service
401
     echo 'After=syslog.target' >> /etc/systemd/system/gogs.service
432
     echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service
406
     echo '#LimitMEMLOCK=infinity' >> /etc/systemd/system/gogs.service
433
     echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service
407
     echo '#LimitNOFILE=65535' >> /etc/systemd/system/gogs.service
434
     echo 'Type=simple' >> /etc/systemd/system/gogs.service
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
     echo 'Restart=always' >> /etc/systemd/system/gogs.service
413
     echo 'Restart=always' >> /etc/systemd/system/gogs.service
440
     echo 'RestartSec=10' >> /etc/systemd/system/gogs.service
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
     echo '' >> /etc/systemd/system/gogs.service
416
     echo '' >> /etc/systemd/system/gogs.service
444
     echo '[Install]' >> /etc/systemd/system/gogs.service
417
     echo '[Install]' >> /etc/systemd/system/gogs.service
445
     echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service
418
     echo 'WantedBy=multi-user.target' >> /etc/systemd/system/gogs.service
574
     fi
547
     fi
575
 
548
 
576
     # create the configuration
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
     if [ ! -d $GOGS_CONFIG_PATH ]; then
551
     if [ ! -d $GOGS_CONFIG_PATH ]; then
579
         mkdir -p $GOGS_CONFIG_PATH
552
         mkdir -p $GOGS_CONFIG_PATH
580
     fi
553
     fi
581
     GOGS_CONFIG_FILE=$GOGS_CONFIG_PATH/app.ini
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
     echo 'RUN_MODE = prod' >> $GOGS_CONFIG_FILE
556
     echo 'RUN_MODE = prod' >> $GOGS_CONFIG_FILE
584
     echo '' >> $GOGS_CONFIG_FILE
557
     echo '' >> $GOGS_CONFIG_FILE
585
     echo '[database]' >> $GOGS_CONFIG_FILE
558
     echo '[database]' >> $GOGS_CONFIG_FILE
592
     echo 'PATH = data/gogs.db' >> $GOGS_CONFIG_FILE
565
     echo 'PATH = data/gogs.db' >> $GOGS_CONFIG_FILE
593
     echo '' >> $GOGS_CONFIG_FILE
566
     echo '' >> $GOGS_CONFIG_FILE
594
     echo '[repository]' >> $GOGS_CONFIG_FILE
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
     echo '' >> $GOGS_CONFIG_FILE
569
     echo '' >> $GOGS_CONFIG_FILE
597
     echo '[server]' >> $GOGS_CONFIG_FILE
570
     echo '[server]' >> $GOGS_CONFIG_FILE
598
     if [[ $ONION_ONLY == 'no' ]]; then
571
     if [[ $ONION_ONLY == 'no' ]]; then
630
     echo 'SHOW_FOOTER_VERSION = false' >> $GOGS_CONFIG_FILE
603
     echo 'SHOW_FOOTER_VERSION = false' >> $GOGS_CONFIG_FILE
631
 
604
 
632
     chmod 750 $GOGS_CONFIG_FILE
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
     systemctl restart gogs
608
     systemctl restart gogs
636
 
609
 
640
 
613
 
641
     function_check configure_firewall_for_git
614
     function_check configure_firewall_for_git
642
     configure_firewall_for_git
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
     echo 'install_gogs' >> $COMPLETION_FILE
621
     echo 'install_gogs' >> $COMPLETION_FILE
644
 }
622
 }
645
 
623
 

+ 9
- 88
src/freedombone-utils-go ファイルの表示

131
 }
131
 }
132
 
132
 
133
 function mesh_upgrade_golang {
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
     GOARCH=
139
     GOARCH=
137
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
140
     if [[ $ARCHITECTURE == *"386" || $ARCHITECTURE == *"686" ]]; then
157
     if [ ! -f ${rootdir}${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz ]; then
160
     if [ ! -f ${rootdir}${INSTALL_DIR}/go${GO_VERSION}.linux-${GOARCH}.tar.gz ]; then
158
         exit 26524
161
         exit 26524
159
     fi
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
     if [ ! -d ${rootdir}/home/go/go/bin ]; then
164
     if [ ! -d ${rootdir}/home/go/go/bin ]; then
162
         echo 'Go binary not installed'
165
         echo 'Go binary not installed'
163
         exit 763562
166
         exit 763562
174
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/root/.bashrc
177
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/root/.bashrc
175
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/$MY_USERNAME/.bashrc
178
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/$MY_USERNAME/.bashrc
176
     echo 'export PATH=$PATH:$GOPATH' >> $rootdir/home/go/.bashrc
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
     cp ${rootdir}/home/go/go${GO_VERSION}/bin/* ${rootdir}/usr/bin
182
     cp ${rootdir}/home/go/go${GO_VERSION}/bin/* ${rootdir}/usr/bin
180
 }
183
 }
181
 
184
 
184
         return
187
         return
185
     fi
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
     echo 'upgrade_golang' >> $COMPLETION_FILE
193
     echo 'upgrade_golang' >> $COMPLETION_FILE
273
 }
194
 }