diff --git a/bin/install_module b/bin/install_module
index 89824b4cd80315a64f3ade9cef18d89c118344fe..d5b9a8b491e3c8834bb4144ee8b9cac6e0732709 100755
--- a/bin/install_module
+++ b/bin/install_module
@@ -17,11 +17,8 @@ do
     *.pmod)
       if [ -d "$DIR" ]; then
          break
-      else
-         :
       fi
 
-
       if [ -f "$DIR" ]; then
         mv "$DIR" "$DIR-foo"
         mkdir $DIR
@@ -53,10 +50,23 @@ else
   :
 fi
 
-if [ -d "$BASE.pmod" ]; then
-  EXT=`echo $TO | sed -e 's@(\.[^.]$)@\1@/'`
-  TO="$BASE.pmod/module.$EXT"
+if [ -d "$BASE.pmod" -a -d "$FROM" ]; then
+# we are copying a dir module into a dir module.
+  FROM="$FROM/."
+elif [ -d "$BASE.pmod" ]; then
+  EXT=`echo $TO | sed -e 's@^.*\.\(.[^\.]*\)$@\1@'`
+	  TO="$BASE.pmod/module.$EXT"
+fi
+
+# Add proper flag to copy recursively if FROM is a directory module
+
+CPFLAGS=""
+
+if [ -d "$FROM" ]; then
+  CPFLAGS="-r"
 fi
 
+pwd
+ cp $CPFLAGS "$FROM" "$TO"
 
-exec cp "$FROM" "$TO"
+exit $?