Browse Source

Improve upgrades from commit changes

Bob Mottram 8 years ago
parent
commit
a3f7ab9fae
3 changed files with 61 additions and 71 deletions
  1. 4
    2
      src/freedombone-app-rss
  2. 15
    0
      src/freedombone-app-tox
  3. 42
    69
      src/freedombone-utils-git

+ 4
- 2
src/freedombone-app-rss View File

@@ -94,8 +94,10 @@ function upgrade_rss {
94 94
     if [[ $(app_is_installed rss) == "1" ]]; then
95 95
         function_check set_repo_commit
96 96
         set_repo_commit $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT" $RSS_READER_REPO
97
-        function_check rss_modifications
98
-        rss_modifications
97
+        if [[ $(commit_has_changed $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT") == "1" ]]; then
98
+            function_check rss_modifications
99
+            rss_modifications
100
+        fi
99 101
     fi
100 102
 
101 103
     if [[ $(app_is_installed rss_mobile_reader) == "1" ]]; then

+ 15
- 0
src/freedombone-app-tox View File

@@ -145,9 +145,24 @@ function reconfigure_tox {
145 145
 function upgrade_tox {
146 146
     function_check set_repo_commit
147 147
     set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO
148
+    if [[ $(commit_has_changed $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then
149
+        cd $INSTALL_DIR/toxcore
150
+        sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
151
+        autoreconf -i
152
+        ./configure --enable-daemon
153
+        make
154
+        make install
155
+        systemctl daemon-reload
156
+        systemctl restart tox-bootstrapd.service
157
+    fi
148 158
 
149 159
     function_check set_repo_commit
150 160
     set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO
161
+    if [[ $(commit_has_changed $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then
162
+        cd $INSTALL_DIR/toxic
163
+        make
164
+        make install
165
+    fi
151 166
 }
152 167
 
153 168
 function backup_local_tox {

+ 42
- 69
src/freedombone-utils-git View File

@@ -32,7 +32,7 @@ function git_clone {
32 32
     repo_url="$1"
33 33
     destination_dir="$2"
34 34
 
35
-    if [[ "$repo_url" == "ssh:"* ]]; then
35
+    if [[ "$repo_url" == 'ssh:'* ]]; then
36 36
         retval=$(get_friends_servers)
37 37
         if [[ $retval == "0" ]]; then
38 38
             if [ "${FRIENDS_MIRRORS_SERVER}" ]; then
@@ -88,84 +88,57 @@ function git_pull {
88 88
     fi
89 89
 }
90 90
 
91
-# This ensures that a given repo is on a given commit
92
-# If it isn't then it attempts to upgrade
93
-function set_repo_commit {
91
+function commit_has_changed {
94 92
     repo_dir=$1
95 93
     repo_commit_name=$2
96 94
     repo_commit=$3
97
-    repo_url=$4
98 95
     if [ -d $repo_dir ]; then
99 96
         if grep -q "$repo_commit_name" $COMPLETION_FILE; then
100 97
             CURRENT_REPO_COMMIT=$(grep "$repo_commit_name" $COMPLETION_FILE | awk -F ':' '{print $2}')
101 98
             if [[ "$CURRENT_REPO_COMMIT" != "$repo_commit" ]]; then
102
-                cd $repo_dir
103
-                git_pull $repo_url $repo_commit
99
+                echo "1"
100
+            fi
101
+        fi
102
+    fi
103
+    echo "0"
104
+}
104 105
 
105
-                # application specific stuff after updating the repo
106
-                if [[ $repo_dir == *"www"* ]]; then
107
-                    chown -R www-data:www-data $repo_dir
108
-                fi
109
-                if [[ $repo_dir == *"cjdns" ]]; then
110
-                    ./do
111
-                fi
112
-                if [[ $repo_dir == *"gpgit" ]]; then
113
-                    cp gpgit.pl /usr/bin/gpgit.pl
114
-                fi
115
-                if [[ $repo_dir == *"cleanup-maildir" ]]; then
116
-                    cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
117
-                fi
118
-                if [[ $repo_dir == *"nginx_ensite" ]]; then
119
-                    make install
120
-                fi
121
-                if [[ $repo_dir == *"gogs" ]]; then
122
-                    git checkout master
123
-                    go get -u ./...
124
-                    if [ ! "$?" = "0" ]; then
125
-                        echo $'Failed to get gogs'
126
-                        exit 52792
127
-                    fi
128
-                    git checkout $repo_commit
129
-                    go build
130
-                    if [ ! "$?" = "0" ]; then
131
-                        echo $'Failed to build gogs'
132
-                        exit 36226
133
-                    fi
134
-                    systemctl restart gogs
135
-                fi
136
-                if [[ $repo_dir == *"toxcore" ]]; then
137
-                    sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service
138
-                    autoreconf -i
139
-                    ./configure --enable-daemon
140
-                    make
141
-                    make install
142
-                    systemctl daemon-reload
143
-                    systemctl restart tox-bootstrapd.service
144
-                fi
145
-                if [[ $repo_dir == *"toxic" ]]; then
146
-                    make
147
-                    make install
148
-                fi
149
-                if [[ $repo_dir == $RSS_READER_PATH ]]; then
150
-                    function_check rss_reader_modifications
151
-                    rss_reader_modifications
152
-                fi
153
-                if [[ $repo_dir == *"inadyn" ]]; then
154
-                    ./configure
155
-                    USE_OPENSSL=1 make
156
-                    make install
157
-                    systemctl restart inadyn
158
-                fi
159
-                if [[ $repo_dir == *"ipfs" ]]; then
160
-                    chown -R git:git /home/git
161
-                    systemctl restart ipfs
162
-                    systemctl daemon-reload
163
-                fi
106
+# This ensures that a given repo is on a given commit
107
+# If it isn't then it attempts to upgrade
108
+function set_repo_commit {
109
+    repo_dir=$1
110
+    repo_commit_name=$2
111
+    repo_commit=$3
112
+    repo_url=$4
164 113
 
165
-                sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE
166
-            fi
167
-        else
114
+    if [[ $(commit_has_changed $repo_dir $repo_commit_name $repo_commit) == "1" ]]; then
115
+        cd $repo_dir
116
+        git_pull $repo_url $repo_commit
117
+
118
+        # application specific stuff after updating the repo
119
+        if [[ $repo_dir == *"www"* ]]; then
120
+            chown -R www-data:www-data $repo_dir
121
+        fi
122
+        if [[ $repo_dir == *"gpgit" ]]; then
123
+            cp gpgit.pl /usr/bin/gpgit.pl
124
+        fi
125
+        if [[ $repo_dir == *"cleanup-maildir" ]]; then
126
+            cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin
127
+        fi
128
+        if [[ $repo_dir == *"nginx_ensite" ]]; then
129
+            make install
130
+        fi
131
+        if [[ $repo_dir == *"inadyn" ]]; then
132
+            ./configure
133
+            USE_OPENSSL=1 make
134
+            make install
135
+            systemctl restart inadyn
136
+        fi
137
+
138
+        if ! grep -q "${repo_commit_name}:" $COMPLETION_FILE; then
168 139
             echo "${repo_commit_name}:${repo_commit}" >> $COMPLETION_FILE
140
+        else
141
+            sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE
169 142
         fi
170 143
     fi
171 144
 }