From a3f7ab9faeb7c0e048a698df671360176b3cbbdb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 13 Oct 2016 23:13:43 +0100 Subject: [PATCH] Improve upgrades from commit changes --- src/freedombone-app-rss | 6 ++- src/freedombone-app-tox | 15 ++++++ src/freedombone-utils-git | 111 +++++++++++++++----------------------- 3 files changed, 61 insertions(+), 71 deletions(-) diff --git a/src/freedombone-app-rss b/src/freedombone-app-rss index f83e23e4..7e117ace 100755 --- a/src/freedombone-app-rss +++ b/src/freedombone-app-rss @@ -94,8 +94,10 @@ function upgrade_rss { if [[ $(app_is_installed rss) == "1" ]]; then function_check set_repo_commit set_repo_commit $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT" $RSS_READER_REPO - function_check rss_modifications - rss_modifications + if [[ $(commit_has_changed $RSS_READER_PATH "rss reader commit" "$RSS_READER_COMMIT") == "1" ]]; then + function_check rss_modifications + rss_modifications + fi fi if [[ $(app_is_installed rss_mobile_reader) == "1" ]]; then diff --git a/src/freedombone-app-tox b/src/freedombone-app-tox index 1b5dff71..0b7cf005 100755 --- a/src/freedombone-app-tox +++ b/src/freedombone-app-tox @@ -145,9 +145,24 @@ function reconfigure_tox { function upgrade_tox { function_check set_repo_commit set_repo_commit $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT" $TOXCORE_REPO + if [[ $(commit_has_changed $INSTALL_DIR/toxcore "toxcore commit" "$TOXCORE_COMMIT") == "1" ]]; then + cd $INSTALL_DIR/toxcore + sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service + autoreconf -i + ./configure --enable-daemon + make + make install + systemctl daemon-reload + systemctl restart tox-bootstrapd.service + fi function_check set_repo_commit set_repo_commit $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT" $TOXIC_REPO + if [[ $(commit_has_changed $INSTALL_DIR/toxic "Toxic commit" "$TOXIC_COMMIT") == "1" ]]; then + cd $INSTALL_DIR/toxic + make + make install + fi } function backup_local_tox { diff --git a/src/freedombone-utils-git b/src/freedombone-utils-git index 54cacd2d..4c320d91 100755 --- a/src/freedombone-utils-git +++ b/src/freedombone-utils-git @@ -32,7 +32,7 @@ function git_clone { repo_url="$1" destination_dir="$2" - if [[ "$repo_url" == "ssh:"* ]]; then + if [[ "$repo_url" == 'ssh:'* ]]; then retval=$(get_friends_servers) if [[ $retval == "0" ]]; then if [ "${FRIENDS_MIRRORS_SERVER}" ]; then @@ -88,6 +88,21 @@ function git_pull { fi } +function commit_has_changed { + repo_dir=$1 + repo_commit_name=$2 + repo_commit=$3 + if [ -d $repo_dir ]; then + if grep -q "$repo_commit_name" $COMPLETION_FILE; then + CURRENT_REPO_COMMIT=$(grep "$repo_commit_name" $COMPLETION_FILE | awk -F ':' '{print $2}') + if [[ "$CURRENT_REPO_COMMIT" != "$repo_commit" ]]; then + echo "1" + fi + fi + fi + echo "0" +} + # This ensures that a given repo is on a given commit # If it isn't then it attempts to upgrade function set_repo_commit { @@ -95,77 +110,35 @@ function set_repo_commit { repo_commit_name=$2 repo_commit=$3 repo_url=$4 - if [ -d $repo_dir ]; then - if grep -q "$repo_commit_name" $COMPLETION_FILE; then - CURRENT_REPO_COMMIT=$(grep "$repo_commit_name" $COMPLETION_FILE | awk -F ':' '{print $2}') - if [[ "$CURRENT_REPO_COMMIT" != "$repo_commit" ]]; then - cd $repo_dir - git_pull $repo_url $repo_commit - # application specific stuff after updating the repo - if [[ $repo_dir == *"www"* ]]; then - chown -R www-data:www-data $repo_dir - fi - if [[ $repo_dir == *"cjdns" ]]; then - ./do - fi - if [[ $repo_dir == *"gpgit" ]]; then - cp gpgit.pl /usr/bin/gpgit.pl - fi - if [[ $repo_dir == *"cleanup-maildir" ]]; then - cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin - fi - if [[ $repo_dir == *"nginx_ensite" ]]; then - make install - fi - if [[ $repo_dir == *"gogs" ]]; then - git checkout master - go get -u ./... - if [ ! "$?" = "0" ]; then - echo $'Failed to get gogs' - exit 52792 - fi - git checkout $repo_commit - go build - if [ ! "$?" = "0" ]; then - echo $'Failed to build gogs' - exit 36226 - fi - systemctl restart gogs - fi - if [[ $repo_dir == *"toxcore" ]]; then - sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service - autoreconf -i - ./configure --enable-daemon - make - make install - systemctl daemon-reload - systemctl restart tox-bootstrapd.service - fi - if [[ $repo_dir == *"toxic" ]]; then - make - make install - fi - if [[ $repo_dir == $RSS_READER_PATH ]]; then - function_check rss_reader_modifications - rss_reader_modifications - fi - if [[ $repo_dir == *"inadyn" ]]; then - ./configure - USE_OPENSSL=1 make - make install - systemctl restart inadyn - fi - if [[ $repo_dir == *"ipfs" ]]; then - chown -R git:git /home/git - systemctl restart ipfs - systemctl daemon-reload - fi + if [[ $(commit_has_changed $repo_dir $repo_commit_name $repo_commit) == "1" ]]; then + cd $repo_dir + git_pull $repo_url $repo_commit - sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE - fi - else + # application specific stuff after updating the repo + if [[ $repo_dir == *"www"* ]]; then + chown -R www-data:www-data $repo_dir + fi + if [[ $repo_dir == *"gpgit" ]]; then + cp gpgit.pl /usr/bin/gpgit.pl + fi + if [[ $repo_dir == *"cleanup-maildir" ]]; then + cp $INSTALL_DIR/cleanup-maildir/cleanup-maildir /usr/bin + fi + if [[ $repo_dir == *"nginx_ensite" ]]; then + make install + fi + if [[ $repo_dir == *"inadyn" ]]; then + ./configure + USE_OPENSSL=1 make + make install + systemctl restart inadyn + fi + + if ! grep -q "${repo_commit_name}:" $COMPLETION_FILE; then echo "${repo_commit_name}:${repo_commit}" >> $COMPLETION_FILE + else + sed -i "s/${repo_commit_name}.*/${repo_commit_name}:$repo_commit/g" $COMPLETION_FILE fi fi }