diff --git a/setup/cli/modules/deploy.php b/setup/cli/modules/deploy.php
index 9e9285479c12fa2091bf71313626a27407b3afa4..585f5314a02f8851f8814bd1bdcae561b48b29ca 100644
--- a/setup/cli/modules/deploy.php
+++ b/setup/cli/modules/deploy.php
@@ -44,10 +44,12 @@ class Deployment extends Unpacker {
         $root = $this->find_root_folder();
 
         # Unpack everything but the include/ folder
-        $this->unpackage("$root/*", $this->destination, -1,
-            array("$root/setup", "$root/include", "*.md", "*.txt"));
+        $this->unpackage("$root/{,.}*", $this->destination, -1,
+            array("$root/setup", "$root/include", "$root/.git*",
+                "*.sw[a-z]","*.md", "*.txt"));
         # Unpack the include folder
-        $this->unpackage("$root/include/*", $include, -1);
+        $this->unpackage("$root/include/{,.}*", $include, -1,
+            array("*/include/ost-config.php"));
         if (!$upgrade && $include != "{$this->destination}/include")
             $this->change_include_dir($include);
     }
diff --git a/setup/cli/modules/unpack.php b/setup/cli/modules/unpack.php
index dc184d00b14572ce36a1b6867c6426e3f1277e72..3c66703ef90e0f63d23b2e10aa26e84f6948a35a 100644
--- a/setup/cli/modules/unpack.php
+++ b/setup/cli/modules/unpack.php
@@ -115,8 +115,11 @@ class Unpacker extends Module {
             }
         }
         if ($recurse) {
-            foreach (glob(dirname($folder).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
-                if ($this->exclude($exclude, $dir))
+            foreach (glob(dirname($folder).'/'.basename($folder),
+                    GLOB_BRACE|GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
+                if (in_array(basename($dir), array('.','..')))
+                    continue;
+                elseif ($this->exclude($exclude, $dir))
                     continue;
                 $this->unpackage(
                     dirname($folder).'/'.basename($dir).'/'.basename($folder),
@@ -158,7 +161,7 @@ class Unpacker extends Module {
             # Get the current value of the INCLUDE_DIR before overwriting
             # main.inc.php
             $include = $this->get_include_dir();
-        $this->unpackage("$upload/*", $this->destination, -1, "*include");
+        $this->unpackage("$upload/{,.}*", $this->destination, -1, "*include");
 
         if (!$upgrade) {
             if ($this->getOption('include')) {
@@ -166,14 +169,14 @@ class Unpacker extends Module {
                 if (!is_dir("$location/"))
                     if (!mkdir("$location/", 0751, true))
                         die("Unable to create folder for include/ files\n");
-                $this->unpackage("$upload/include/*", $location, -1);
+                $this->unpackage("$upload/include/{,.}*", $location, -1);
                 $this->change_include_dir($location);
             }
             else
-                $this->unpackage("$upload/include/*", "{$this->destination}/include", -1);
+                $this->unpackage("$upload/include/{,.}*", "{$this->destination}/include", -1);
         }
         else {
-            $this->unpackage("$upload/include/*", $include, -1);
+            $this->unpackage("$upload/include/{,.}*", $include, -1);
             # Change the new main.inc.php to reflect the location of the
             # include/ directory
             $this->change_include_dir($include);