Handle leading and trailing spaces

This commit is contained in:
Bob Mottram 2016-04-10 18:44:59 +01:00
parent 167acecca9
commit a9cb8eca57
1 changed files with 18 additions and 15 deletions

View File

@ -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 " <device id=\"$line\"></device>" >> $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 " <device id=\"$line2\"></device>" >> $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 " <device id=\"$line\"></device>" >> $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 " <device id=\"$line2\"></device>" >> $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 " <device id=\"$line\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> $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 " <device id=\"$line2\" name=\"${USERNAME}\" compression=\"metadata\" introducer=\"false\">" >> $SYNCTHING_CONFIG_FILE
echo ' <address>dynamic</address>' >> $SYNCTHING_CONFIG_FILE
echo ' </device>' >> $SYNCTHING_CONFIG_FILE
echo "$line" >> $TEMP_IDS_FILE
echo "$line2" >> $TEMP_IDS_FILE
fi
fi
fi