[
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2019 JetsonHacksNano\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# installSwapfile\n<b><em>Note: While you can still use this method to add a swap file, note that </b>newer versions of L4T/JetPack have swap memory as part of the default distribution, implemented through zram. You may choose to use both a swapfile, as implemented here, and the zram swap memory at the same time.</em>\n\nOriginal article on JetsonHacks: https://wp.me/p7ZgI9-1ac\n\nInstall a swap file on the NVIDIA Jetson Nano Developer Kit. This should help with memory pressure issues.\n\n### Setup Swap File\n> installSwapFile.sh - Create a swap file ; Use on external media like USB drive or SSD\n\n> usage: installSwapFile.sh [[[-d directory ] [-s size] -a] | [-h]]\n>\n> -d | --dir [directoryname]   Directory to place swapfile (defaults to /mnt)\n>\n> -s | --size [gigabytes] (defaults to 6 )\n>\n> -a | --auto  Enable swap on boot in /etc/fstab (default: \"Y\")\n>\n> -h | --help  This message\n>\n> Defaults to creating a 6GB Swapfile in the current directory\n>\n> Note: If you enable swap on boot, you should also automount the drive that you're using\n\n### Automount\nAutomount a device given the label\n> autoMount.sh - Automount a device, useful for external media like USB drives\n\n> usage: autoMount.sh [ [-l label] | [-h]]\n>\n> -l | --label  [labelname]   Label to lookup\n>\n> -h | --help  This message\n>\n> Example usage:\n>\n> $ ./shellScript.sh -l RaceUSB\n>\n> where RaceUSB is the label of the device mounted at /media/jetsonhacks/RaceUSB\n>\n> Tool to help automount the device given from the label\n> The script looks up the device, mounting point and UUID for the given label\n> Optionally add it to /etc/fstab\n\n<h2>Release Notes</h2>\n\nv0.7 April 2019\n* Add Automount Support\n* L4T 32.1.0 (JetPack 4.2)\n* Tested on Jetson Nano\n\nInitial Release April, 2019\n* L4T 32.1.0 (JetPack 4.2)\n* Tested on Jetson Nano\n\n"
  },
  {
    "path": "autoMount.sh",
    "content": "#!/bin/bash\n# \nDRIVE_LABEL=\"\"\nfunction usage\n{\n    echo \"usage: autoMount.sh [ [-l label] | [-h]]\"\n    echo \"  -l | --label  <labelname>   Label to lookup\"\n    echo \"  -h | --help  This message\"\n}\n\nif [ $# -eq 0 ]\n  then\n    echo \"No arguments supplied\"\n    usage\n    exit 1\nfi\n\nwhile [ \"$1\" != \"\" ]; do\n    case $1 in\n        -l | --label | -L )     shift\n                                DRIVE_LABEL=$1\n                                ;;\n        -h | --help )           usage\n                                exit\n                                ;;\n        * )                     usage\n                                exit 1\n    esac\n    shift\ndone\n\necho 'Looking up UUID from the Label:' \"$DRIVE_LABEL\"\n\nDEVICE_NAME=\"\"\nUUID_STRING=\"\"\nif [ \"$DRIVE_LABEL\" != \"\" ] ; then\n   DEVICE_NAME=$(findfs LABEL=\"$DRIVE_LABEL\")\n   if [ \"$DEVICE_NAME\" != \"\" ] ; then\n      echo \"Device: \" $DEVICE_NAME\n      # Lookup UUID\n      UUID_STRING=$(findmnt $DEVICE_NAME -o UUID)\n      if [ \"$UUID_STRING\" != \"\" ] ; then\n         UUID_STRING=`echo \"$UUID_STRING\" | sed -n '1!p'`\n         echo \"UUID: \"\"$UUID_STRING\"\n         # Get the target name (mount path)\n         TARGET_STRING=$(findmnt $DEVICE_NAME -o TARGET)\n         if [ \"$TARGET_STRING\" != \"\" ] ; then\n            echo $TARGET_STRING\n            TARGET_STRING=`echo \"$TARGET_STRING\" | sed -n '1!p'`\n            echo \"Mount Path: \"\"$TARGET_STRING\"\n            echo \"\"\n            FSTAB_STRING=`echo \"UUID=\"\"$UUID_STRING\" \"$TARGET_STRING\"\" auto nosuid,nodev,nofail 0 0\"`\n            echo \"Proposed entry to add to /etc/fstab:\"\n            echo \"$FSTAB_STRING\"\n            echo \"\"\n            echo \"Adding this entry will automate the process of mounting the partion at boot:\"\n            echo \"Device: \"$DEVICE_NAME\n            echo \"UUID: \"\"$UUID_STRING\"\n            echo \"Path: \"\"$TARGET_STRING\"\n            read -p \"Would you like to add this entry to /etc/fstab (y/n)? \" answer\n            case ${answer:0:1} in\n               y|Y )\n                  echo \"\"\n                  echo \"Appending to /etc/fstab\"\n                  echo \"$FSTAB_STRING\" | sudo tee -a /etc/fstab\n                  # Mount for changes to take effect\n                  sudo mount -a\n              ;;\n               * )\n                  echo \"\"\n                  echo \"No action taken\"\n               ;;\n            esac\n         else\n            echo \"Unable to locate target mount point\"\n         fi\n      else\n         echo \"Unable to match \" $DEVICE_NAME \" with UUID\"\n         exit 1\n      fi\n   else\n      echo \"Unable to match drive label with a currently mounted device. Exiting\"\n      exit 1\n   fi\nelse\n   echo \"Please enter a label\"\n   usage\n   exit 1\nfi\n"
  },
  {
    "path": "installSwapfile.sh",
    "content": "#!/bin/bash\n# Copyright 2017-2019 JetsonHacks\n# MIT License\n# Create a swap file and set up permissions\n# If a parameter is passed, it should be the place to create the swapfile\nset -e\nSWAPDIRECTORY=\"/mnt\"\n# Ubuntu recommends 6GB for 4GB of memory when using suspend\n# You can use 1 or 2 if need be\nSWAPSIZE=6\nAUTOMOUNT=\"Y\"\nfunction usage\n{\n    echo \"usage: installSwapFile [[[-d directory ] [-s size] -a] | [-h]]\"\n    echo \"  -d | --dir <directoryname>   Directory to place swapfile ( default: /mnt)\"\n    echo \"  -s | --size <gigabytes> (default: 6)\"\n    echo \"  -a | --auto  Enable swap on boot in /etc/fstab (default: Y)\"\n    echo \"  -h | --help  This message\"\n}\n\nwhile [ \"$1\" != \"\" ]; do\n    case $1 in\n        -d | --dir )            shift\n                                SWAPDIRECTORY=$1\n                                ;;\n        -s | --size )           shift \n\t\t\t\tSWAPSIZE=$1\n                                ;;\n        -a | --auto )           shift\n\t\t\t\tAUTOMOUNT=$1\n\t\t\t\t;;\n        -h | --help )           usage\n                                exit\n                                ;;\n        * )                     usage\n                                exit 1\n    esac\n    shift\ndone\n\necho \"Creating Swapfile at: \" $SWAPDIRECTORY\necho \"Swapfile Size: \" $SWAPSIZE\"G\"\necho \"Automount: \" $AUTOMOUNT\n\n#Create a swapfile for Ubuntu at the current directory location\nsudo fallocate -l $SWAPSIZE\"G\" $SWAPDIRECTORY\"/swapfile\"\ncd $SWAPDIRECTORY\n#List out the file\nls -lh swapfile\n# Change permissions so that only root can use it\nsudo chmod 600 swapfile\n#List out the file\nls -lh swapfile\n#Set up the Linux swap area\nsudo mkswap swapfile\n#Now start using the swapfile\nsudo swapon swapfile\n#Show that it's now being used\nswapon -s\n\nif [ \"$AUTOMOUNT\" = \"Y\" ]; then\n\techo \"Modifying /etc/fstab to enable on boot\"\n        SWAPLOCATION=$SWAPDIRECTORY\"/swapfile\"\n        echo $SWAPLOCATION\n\tsudo sh -c 'echo \"'$SWAPLOCATION' swap swap defaults 0 0\" >> /etc/fstab'\nfi\n\necho \"Swap file has been created\"\necho \"Reboot to make sure changes are in effect\"\n\n"
  }
]