]> code.citadel.org Git - citadel.git/blobdiff - citadel/migrate_aliases.sh
* add a script that tries to migrate the systems /etc/aliases file if existant.
[citadel.git] / citadel / migrate_aliases.sh
diff --git a/citadel/migrate_aliases.sh b/citadel/migrate_aliases.sh
new file mode 100755 (executable)
index 0000000..9408135
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+CITALIAS=$1
+if test -f /etc/aliases; then
+    cat /etc/aliases | \
+       sed -e "s; *;;g" \
+            -e "s;\t*;;g" | \
+       grep -v ^root: | \
+       grep -v ^# | \
+       sed -e "s;:root;,room_aide;" \
+            -e "s;:;,;" >/tmp/aliases
+
+    NLINES=`cat /tmp/aliases|wc -l`
+    
+    for ((i=1; i <= $NLINES; i++)); do 
+       ALIAS=`head -n $i /tmp/aliases |tail -n 1`
+       ORG=`echo $ALIAS|sed "s;,.*;;"`
+       if grep $ORG $CITALIAS; then
+           echo "Ignoring Alias $ORG as its alreday there"
+       else
+           echo "$ALIAS" >>$CITALIAS
+       fi
+    done
+else
+    echo "no /etc/aliases found."
+fi 
\ No newline at end of file