Browse Source

Handle leading and trailing spaces

Bob Mottram 9 years ago
parent
commit
a9cb8eca57
1 changed files with 18 additions and 15 deletions
  1. 18
    15
      src/freedombone-syncthing

+ 18
- 15
src/freedombone-syncthing View File

@@ -103,11 +103,12 @@ function create_syncthing_config {
103 103
             if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
104 104
                 echo "" > $TEMP_IDS_FILE
105 105
                 while read -r line || [[ -n "$line" ]]; do
106
-                    if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
107
-                        if [ ${#line} -gt 10 ]; then
108
-                            if ! grep -q "$line" $TEMP_IDS_FILE; then
109
-                                echo "        <device id=\"$line\"></device>" >> $SYNCTHING_CONFIG_FILE
110
-                                echo "$line" >> $TEMP_IDS_FILE
106
+                    line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
107
+                    if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
108
+                        if [ ${#line2} -gt 10 ]; then
109
+                            if ! grep -q "$line2" $TEMP_IDS_FILE; then
110
+                                echo "        <device id=\"$line2\"></device>" >> $SYNCTHING_CONFIG_FILE
111
+                                echo "$line2" >> $TEMP_IDS_FILE
111 112
                             fi
112 113
                         fi
113 114
                     fi
@@ -139,11 +140,12 @@ function create_syncthing_config {
139 140
         if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
140 141
             if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
141 142
                 while read -r line || [[ -n "$line" ]]; do
142
-                    if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
143
-                        if [ ${#line} -gt 10 ]; then
144
-                            if ! grep -q "$line" $TEMP_IDS_FILE; then
145
-                                echo "        <device id=\"$line\"></device>" >> $SYNCTHING_CONFIG_FILE
146
-                                echo "$line" >> $TEMP_IDS_FILE
143
+                    line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
144
+                    if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
145
+                        if [ ${#line2} -gt 10 ]; then
146
+                            if ! grep -q "$line2" $TEMP_IDS_FILE; then
147
+                                echo "        <device id=\"$line2\"></device>" >> $SYNCTHING_CONFIG_FILE
148
+                                echo "$line2" >> $TEMP_IDS_FILE
147 149
                             fi
148 150
                         fi
149 151
                     fi
@@ -178,13 +180,14 @@ function create_syncthing_config {
178 180
         if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then
179 181
             if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then
180 182
                 while read -r line || [[ -n "$line" ]]; do
181
-                    if [[ $line != *"#"* && $line != *"*"* && $line != *'/'*  && $line == *"-"* ]]; then
182
-                        if [ ${#line} -gt 10 ]; then
183
-                            if ! grep -q "$line" $TEMP_IDS_FILE; then
184
-                                echo "    <device id=\"$line\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> $SYNCTHING_CONFIG_FILE
183
+                    line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
184
+                    if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'*  && $line2 == *"-"* ]]; then
185
+                        if [ ${#line2} -gt 10 ]; then
186
+                            if ! grep -q "$line2" $TEMP_IDS_FILE; then
187
+                                echo "    <device id=\"$line2\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> $SYNCTHING_CONFIG_FILE
185 188
                                 echo '        <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
186 189
                                 echo '    </device>' >> $SYNCTHING_CONFIG_FILE
187
-                                echo "$line" >> $TEMP_IDS_FILE
190
+                                echo "$line2" >> $TEMP_IDS_FILE
188 191
                             fi
189 192
                         fi
190 193
                     fi