warbo-utilities: 7d35af9a8bcb6f7cef6ce5d0133d965bf00347aa

     1: #!/usr/bin/env bash
     2: 
     3: set -e
     4: shopt -s nullglob
     5: 
     6: if [[ "$UID" -eq 0 ]]
     7: then
     8:     echo "Error: 'podcasts' won't work as root. Try running without sudo?" 1>&2
     9:     exit 1
    10: fi
    11: 
    12: # Mount the iPod, if it's plugged in
    13: ipod || {
    14:     echo "Failed to mount, exiting" 1>&2
    15:     exit 1
    16: }
    17: 
    18: [[ -d ~/iPod/Audio ]] || {
    19:     echo "iPod doesn't seem to be mounted" 1>&2
    20:     exit 1
    21: }
    22: 
    23: if [[ -z "$KEEP" ]]
    24: then
    25:     echo "ABOUT TO DELETE IPOD TO""DO (SET KEEP=1 TO AVOID THIS)..." 1>&2
    26:     echo "3..."
    27:     sleep 1
    28:     echo "2..."
    29:     sleep 1
    30:     echo "1..."
    31:     sleep 1
    32: 
    33:     for D in ~/iPod/Audio/TO""DO/*
    34:     do
    35:         echo "DELETING '$D'" 1>&2
    36:         rm -rf "$D"
    37:     done
    38: fi
    39: 
    40: echo "MOVING NEW TO""DOS" 1>&2
    41: 
    42: for D in ~/Audio/TO""DO/*
    43: do
    44:     cp -rv "$D" ~/iPod/Audio/TO""DO/
    45: 
    46:     NAME=$(basename "$D")
    47: 
    48:     if [[ -d "$D" ]]
    49:     then
    50:         # Look for an existing directory with the same name, move the contents
    51:         FOUND=0
    52:         for DEST in ~/Audio/Non-fiction ~/Audio/Fiction
    53:         do
    54:             if [[ -d "$DEST/$NAME" ]]
    55:             then
    56:                 for F in "$D"/*
    57:                 do
    58:                     mv -v "$F" "$DEST/$NAME"/
    59:                 done
    60:                 rmdir "$D"
    61:                 FOUND=1
    62:             fi
    63:         done
    64: 
    65:         if [[ "$FOUND" -eq 0 ]]
    66:         then
    67:             echo "No existing '$NAME' found, assuming non-fiction" 1>&2
    68:             mv -v "$D" ~/Audio/Non-fiction/
    69:         fi
    70:     else
    71:         # Looking for existing files is too tedious; assume it's standalone
    72:         echo "Standalone file '$D' found, assuming non-fiction" 1>&2
    73:         mv -v "$D" ~/Audio/Non-fiction/
    74:     fi
    75: done

Generated by git2html.