Browse Source

Some extra safety checks when appending to crontab

Bob Mottram 7 years ago
parent
commit
d1535c71ea
1 changed files with 9 additions and 5 deletions
  1. 9
    5
      src/freedombone-client

+ 9
- 5
src/freedombone-client View File

95
     fi
95
     fi
96
     sudo cp /etc/crontab ~/temp_crontab
96
     sudo cp /etc/crontab ~/temp_crontab
97
     sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab
97
     sudo chown "$CURR_USER":"$CURR_GROUP" ~/temp_crontab
98
-    if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
99
-        echo "0            */$REFRESH_GPG_KEYS_HOURS *   *   *   $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
100
-        sudo cp ~/temp_crontab /etc/crontab
101
-        sudo chown root:root /etc/crontab
98
+    if [ -f ~/temp_crontab ]; then
99
+        if grep -q 'test' ~/temp_crontab; then
100
+            if ! grep -q 'gpg --refresh-keys' ~/temp_crontab; then
101
+                echo "0            */$REFRESH_GPG_KEYS_HOURS *   *   *   $CURR_USER /usr/bin/gpg --refresh-keys > /dev/null" >> ~/temp_crontab
102
+                sudo cp ~/temp_crontab /etc/crontab
103
+                sudo chown root:root /etc/crontab
104
+            fi
105
+        fi
106
+        rm ~/temp_crontab
102
     fi
107
     fi
103
-    rm ~/temp_crontab
104
 }
108
 }
105
 
109
 
106
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html
110
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html