Skip to content

Instantly share code, notes, and snippets.

@sourceperl
Created August 17, 2016 08:39
Show Gist options
  • Save sourceperl/7f6c115e98bb55dc4cc3d482b917628e to your computer and use it in GitHub Desktop.
Save sourceperl/7f6c115e98bb55dc4cc3d482b917628e to your computer and use it in GitHub Desktop.
Create a new sources list for use APT with an USB source mirror
#!/bin/bash
# create a new sources list for use APT with this USB source mirror
USB_LIST=/etc/apt/sources.list.d/usb_source.list
# check root level
if [ $EUID -ne 0 ]
then
echo "This script must be run as root" 1>&2
exit 1
fi
# auto-detect USB source directory
script_root=$(dirname `realpath $0`)
usb_root=$(realpath $script_root/..)
echo "detect USB source directory: $usb_root"
# check USB_LIST already exist
echo "check if $USB_LIST already exist..."
if [ -e "$USB_LIST" ]
then
echo "can't add $USB_LIST: the file already exist"
echo "launch sudo rm $USB_LIST to remove it"
exit 2
else
# build sources.list.raspbian for USB source
echo "create and add $USB_LIST"
echo "# auto-build APT sources list for update from a USB source" > $USB_LIST
echo "deb file:$usb_root/raspbian/mirror/mirrordirector.raspbian.org/raspbian jessie main contrib non-free rpi" >> $USB_LIST
echo "deb file:$usb_root/raspbian/mirror/archive.raspberrypi.org/debian jessie main ui" >> $USB_LIST
echo "don't forget to launch sudo apt-get update to refesh apt index"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment