Pārlūkot izejas kodu

Some extra safety checks when appending to crontab

Bob Mottram 7 gadus atpakaļ
vecāks
revīzija
d1535c71ea
1 mainītis faili ar 9 papildinājumiem un 5 dzēšanām
  1. 9
    5
      src/freedombone-client

+ 9
- 5
src/freedombone-client Parādīt failu

@@ -95,12 +95,16 @@ function refresh_gpg_keys {
95 95
     fi
96 96
     sudo cp /etc/crontab ~/temp_crontab
97 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 107
     fi
103
-    rm ~/temp_crontab
104 108
 }
105 109
 
106 110
 # see https://stribika.github.io/2015/01/04/secure-secure-shell.html