From a9cb8eca579babc1e6b30c6e88fa5c453141e5ab Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 10 Apr 2016 18:44:59 +0100 Subject: [PATCH] Handle leading and trailing spaces --- src/freedombone-syncthing | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/freedombone-syncthing b/src/freedombone-syncthing index b92b22b6..c47fd077 100755 --- a/src/freedombone-syncthing +++ b/src/freedombone-syncthing @@ -103,11 +103,12 @@ function create_syncthing_config { if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then echo "" > $TEMP_IDS_FILE while read -r line || [[ -n "$line" ]]; do - if [[ $line != *"#"* && $line != *"*"* && $line != *'/'* && $line == *"-"* ]]; then - if [ ${#line} -gt 10 ]; then - if ! grep -q "$line" $TEMP_IDS_FILE; then - echo " " >> $SYNCTHING_CONFIG_FILE - echo "$line" >> $TEMP_IDS_FILE + line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'* && $line2 == *"-"* ]]; then + if [ ${#line2} -gt 10 ]; then + if ! grep -q "$line2" $TEMP_IDS_FILE; then + echo " " >> $SYNCTHING_CONFIG_FILE + echo "$line2" >> $TEMP_IDS_FILE fi fi fi @@ -139,11 +140,12 @@ function create_syncthing_config { if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then while read -r line || [[ -n "$line" ]]; do - if [[ $line != *"#"* && $line != *"*"* && $line != *'/'* && $line == *"-"* ]]; then - if [ ${#line} -gt 10 ]; then - if ! grep -q "$line" $TEMP_IDS_FILE; then - echo " " >> $SYNCTHING_CONFIG_FILE - echo "$line" >> $TEMP_IDS_FILE + line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'* && $line2 == *"-"* ]]; then + if [ ${#line2} -gt 10 ]; then + if ! grep -q "$line2" $TEMP_IDS_FILE; then + echo " " >> $SYNCTHING_CONFIG_FILE + echo "$line2" >> $TEMP_IDS_FILE fi fi fi @@ -178,13 +180,14 @@ function create_syncthing_config { if [[ $USERNAME != "git" && $USERNAME != "mirrors" && $USERNAME != "sync" ]]; then if [ -f /home/$USERNAME/$SYNCTHING_USER_IDS_FILE ]; then while read -r line || [[ -n "$line" ]]; do - if [[ $line != *"#"* && $line != *"*"* && $line != *'/'* && $line == *"-"* ]]; then - if [ ${#line} -gt 10 ]; then - if ! grep -q "$line" $TEMP_IDS_FILE; then - echo " " >> $SYNCTHING_CONFIG_FILE + line2="$(echo -e "${line}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" + if [[ $line2 != *"#"* && $line2 != *"*"* && $line2 != *'/'* && $line2 == *"-"* ]]; then + if [ ${#line2} -gt 10 ]; then + if ! grep -q "$line2" $TEMP_IDS_FILE; then + echo " " >> $SYNCTHING_CONFIG_FILE echo '
dynamic
' >> $SYNCTHING_CONFIG_FILE echo '
' >> $SYNCTHING_CONFIG_FILE - echo "$line" >> $TEMP_IDS_FILE + echo "$line2" >> $TEMP_IDS_FILE fi fi fi