ソースを参照

Better handling of xmpp upgrades

Bob Mottram 8 年 前
コミット
f24ad2cd17
共有1 個のファイルを変更した91 個の追加74 個の削除を含む
  1. 91
    74
      src/freedombone-app-xmpp

+ 91
- 74
src/freedombone-app-xmpp ファイルの表示

@@ -293,53 +293,58 @@ function upgrade_xmpp_server {
293 293
     function_check update_prosody_modules
294 294
     update_prosody_modules
295 295
 
296
-    if [ -d ${INSTALL_DIR}/${prosody_filename} ]; then
297
-        # ensure that the binaries have not been overwritten
298
-        # by an operating system upgrade
299
-        cd ${INSTALL_DIR}/${prosody_filename}
300
-        make prefix=/usr install
301
-    else
302
-        cd $INSTALL_DIR
303
-        # Try to get the source from the project repo
304
-        if [ -f /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
305
-            cp /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
296
+    curr_prosody_filename=$(cat $COMPLETION_FILE | grep "prosody_filename" | awk -F ':' '{print $2}')
297
+    if [[ "$curr_prosody_filename" != "$prosody_filename" ]]; then
298
+        if [ -d ${INSTALL_DIR}/${prosody_filename} ]; then
299
+            # ensure that the binaries have not been overwritten
300
+            # by an operating system upgrade
301
+            cd ${INSTALL_DIR}/${prosody_filename}
302
+            make prefix=/usr install
306 303
         else
307
-            if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
308
-                cp /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
304
+            cd $INSTALL_DIR
305
+            # Try to get the source from the project repo
306
+            if [ -f /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
307
+                cp /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
309 308
             else
310
-                wget $prosody_nightly_url
309
+                if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
310
+                    cp /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
311
+                else
312
+                    wget $prosody_nightly_url
313
+                fi
314
+            fi
315
+            if [ ! -f ${INSTALL_DIR}/${prosody_filename}.tar.gz ]; then
316
+                echo $"Failed to download prosody nightly $prosody_nightly_url"
317
+                return
311 318
             fi
312
-        fi
313
-        if [ ! -f ${INSTALL_DIR}/${prosody_filename}.tar.gz ]; then
314
-            echo $"Failed to download prosody nightly $prosody_nightly_url"
315
-            return
316
-        fi
317 319
 
318
-        hash_value=$(sha256sum ${INSTALL_DIR}/${prosody_filename}.tar.gz | awk -F ' ' '{print $1}')
319
-        if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
320
+            hash_value=$(sha256sum ${INSTALL_DIR}/${prosody_filename}.tar.gz | awk -F ' ' '{print $1}')
321
+            if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
322
+                rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
323
+                echo $'Unexpected hash value for prosody nightly download'
324
+                return
325
+            fi
326
+
327
+            tar -xzvf ${INSTALL_DIR}/${prosody_filename}.tar.gz
328
+            cd ${INSTALL_DIR}/${prosody_filename}
329
+            ./configure --ostype=debian --prefix=/usr
330
+            make prefix=/usr
331
+            make prefix=/usr install
332
+            if [ -f /usr/local/bin/prosody ]; then
333
+                echo $'Failed to build prosody nightly to /usr/bin'
334
+                rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
335
+                rm -rf ${INSTALL_DIR}/${prosody_filename}
336
+                return
337
+            fi
320 338
             rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
321
-            echo $'Unexpected hash value for prosody nightly download'
322
-            return
323 339
         fi
324 340
 
325
-        tar -xzvf ${INSTALL_DIR}/${prosody_filename}.tar.gz
326
-        cd ${INSTALL_DIR}/${prosody_filename}
327
-        ./configure --ostype=debian --prefix=/usr
328
-        make prefix=/usr
329
-        make prefix=/usr install
330
-        if [ -f /usr/local/bin/prosody ]; then
331
-            echo $'Failed to build prosody nightly to /usr/bin'
332
-            rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
333
-            rm -rf ${INSTALL_DIR}/${prosody_filename}
334
-            return
341
+        # add onion addresses for known servers
342
+        if ! grep -q "onions_map =" /etc/prosody/prosody.cfg.lua; then
343
+            echo '' >> /etc/prosody/prosody.cfg.lua
344
+            xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
335 345
         fi
336
-        rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
337
-    fi
338 346
 
339
-    # add onion addresses for known servers
340
-    if ! grep -q "onions_map =" /etc/prosody/prosody.cfg.lua; then
341
-        echo '' >> /etc/prosody/prosody.cfg.lua
342
-        xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
347
+        set_completion_param "prosody_filename" "${prosody_filename}"
343 348
     fi
344 349
 
345 350
     systemctl restart prosody
@@ -353,48 +358,57 @@ function upgrade_xmpp_client {
353 358
 
354 359
     rm -rf /tmp/*
355 360
 
356
-    function_check set_repo_commit
357
-    set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
358
-    cd $INSTALL_DIR/libmesode
359
-    ./bootstrap.sh
360
-    ./configure
361
-    make
362
-    make install
363
-    cp /usr/local/lib/libmesode* /usr/lib
361
+    CURR_LIBMESODE_COMMIT=$(cat $COMPLETION_FILE | grep "libmesode commit" | awk -F ':' '{print $2}')
362
+    if [[ "$CURR_LIBMESODE_COMMIT" != "$LIBMESODE_COMMIT" ]]; then
363
+        function_check set_repo_commit
364
+        set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
365
+        cd $INSTALL_DIR/libmesode
366
+        ./bootstrap.sh
367
+        ./configure
368
+        make
369
+        make install
370
+        cp /usr/local/lib/libmesode* /usr/lib
371
+    fi
364 372
 
365 373
     rm -rf /tmp/*
366 374
 
367
-    function_check set_repo_commit
368
-    set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
369
-    cd $INSTALL_DIR/profanity
370
-    ./bootstrap.sh
371
-    ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
372
-    make
373
-    make install
374
-
375
-    # upgrade omemo plugins for all users
376
-    set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
377
-    cd $INSTALL_DIR/profanity-omemo-plugin
378
-    sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
379
-    pip uninstall -y profanity-omemo-plugin
380
-    ./install.sh
381
-    for d in /home/*/ ; do
382
-        USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
383
-        if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
384
-            if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
385
-                mkdir -p /home/$USERNAME/.local/share/profanity/plugins
386
-            fi
387
-            if [ -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
388
-                rm $INSTALL_DIR/profanity-omemo-plugin/omemo.*
375
+    CURR_PROFANITY_COMMIT=$(cat $COMPLETION_FILE | grep "profanity commit" | awk -F ':' '{print $2}')
376
+    if [[ "$CURR_PROFANITY_COMMIT" != "$PROFANITY_COMMIT" ]]; then
377
+        function_check set_repo_commit
378
+        set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
379
+        cd $INSTALL_DIR/profanity
380
+        ./bootstrap.sh
381
+        ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
382
+        make
383
+        make install
384
+    fi
385
+
386
+    CURR_PROFANITY_OMEMO_PLUGIN_COMMIT=$(cat $COMPLETION_FILE | grep "profanity omemo plugin commit" | awk -F ':' '{print $2}')
387
+    if [[ "$CURR_PROFANITY_OMEMO_PLUGIN_COMMIT" != "$PROFANITY_OMEMO_PLUGIN_COMMIT" ]]; then
388
+        # upgrade omemo plugins for all users
389
+        set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
390
+        cd $INSTALL_DIR/profanity-omemo-plugin
391
+        sed -i 's|python setup.py|python2.7 setup.py|g' $INSTALL_DIR/profanity-omemo-plugin/install.sh
392
+        pip uninstall -y profanity-omemo-plugin
393
+        ./install.sh
394
+        for d in /home/*/ ; do
395
+            USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
396
+            if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
397
+                if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
398
+                    mkdir -p /home/$USERNAME/.local/share/profanity/plugins
399
+                fi
400
+                if [ -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
401
+                    rm $INSTALL_DIR/profanity-omemo-plugin/omemo.*
402
+                fi
403
+                cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$USERNAME/.local/share/profanity/plugins
404
+                chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
389 405
             fi
390
-            cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /home/$USERNAME/.local/share/profanity/plugins
391
-            chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
406
+        done
407
+        if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
408
+            rm /etc/skel/.local/share/profanity/plugins/omemo.*
392 409
         fi
393
-    done
394
-    if [ -f /etc/skel/.local/share/profanity/plugins/omemo.py ]; then
395
-        rm /etc/skel/.local/share/profanity/plugins/omemo.*
410
+        cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
396 411
     fi
397
-    cp $INSTALL_DIR/profanity-omemo-plugin/deploy/prof_omemo_plugin.py /etc/skel/.local/share/profanity/plugins
398 412
 }
399 413
 
400 414
 function upgrade_xmpp {
@@ -516,6 +530,7 @@ function remove_xmpp {
516 530
 
517 531
     remove_completion_param install_xmpp
518 532
     sed -i '/xmpp/d' $COMPLETION_FILE
533
+    sed -i '/prosody/d' $COMPLETION_FILE
519 534
 }
520 535
 
521 536
 function xmpp_email_headers {
@@ -750,6 +765,8 @@ function install_xmpp_nightly {
750 765
         exit 628732
751 766
     fi
752 767
     rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
768
+
769
+    set_completion_param "prosody_filename" "${prosody_filename}"
753 770
 }
754 771
 
755 772
 function install_xmpp_main {