27. November 2010 · Comments Off on Configuring netatalk under Ubuntu. · Categories: Linux Admin · Tags: , ,
sudo su -
cd /usr/src

apt-get source netatalk
apt-get install devscripts fakeroot libssl-dev cracklib2-dev
apt-get build-dep netatalk

cd netatalk-2*
DEB_BUILD_OPTIONS=ssl debuild
dpkg -i ../netatalk*.deb
echo "netatalk hold" | sudo dpkg --set-selections

/etc/default/netatalk:

AFPD_MAX_CLIENTS=20

ATALK_NAME=`/bin/hostname --short`

ATALK_MAC_CHARSET='MAC_ROMAN'
ATALK_UNIX_CHARSET='LOCALE'

AFPD_GUEST=nobody

ATALKD_RUN=no
PAPD_RUN=no
TIMELORD_RUN=no
A2BOOT_RUN=no
CNID_METAD_RUN=yes
AFPD_RUN=yes

ATALK_BGROUND=no

export ATALK_MAC_CHARSET
export ATALK_UNIX_CHARSET

/etc/netatalk/AppleVolumes.default:

~/ "$u" allow:user1,user2 options:usedots,upriv
/var/TimeMachine TimeMachine allow:user1,user2 options:usedots,upriv

 


Configuring avahi daemon

apt-get install avahi-daemon libnss-mdns

/etc/nsswitch.conf

hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 mdns

/etc/avahi/services/afpd.service

<?xml version="1.0" standalone=no?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_afpovertcp._tcp</type>
<port>548</port>
</service>
<service>
<type>_device-info._tcp</type>
<port>0</port>
<txt-record>model=Xserve</txt-record>
</service>
</service-group>

Model Options: Xserve (same a RackMac) / PowerBook / PowerMac / Macmini / iMac / MacBook / MacBookPro / MacBookAir / MacPro / AppleTV1,1 / AirPort
Ref: /System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist


Configuring TimeMachine

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

System Restore using TimeMachine: From OSX boot dvd you will need to drop to a shell and manually mount the share in the /Volumes directory…

mount -t afp afp://username:password@hostname/TimeMachine /Volumes/TimeMachine

 


FYI: There is no direct way to quota or limit share sizes on AFS shares, you must either configure your share on a separate partition, create a loopback filesystem for the share or manually create a sparcebundle file with a limit in DiskUtility (named “<host>_<mac>.spacebundle”) and configure TimeMachine to backup to it.

dd if=/dev/zero of=/var/TimeMachine.img bs=10M count=10240
mkfs -t ext2 -b 2048 -v Timemachine.img
echo "/var/TimeMachine.img /mnt/TimeMachine auto loop,auto,rw   0       0" >> /etc/fstab
mkdir /mnt/TimeMachine
mount /mnt/TimeMachine
18. November 2010 · Comments Off on Bulk update the meta tags on all m4v files in a directory. · Categories: Linux Scripts · Tags: , , ,
#!/bin/bash
## Created by: deaves
# Bulk update the meta tags on all m4v files in a directory.
#
## Requires: mpeg4ip
 
DATA="EPISODES"
 
ls *.m4v | while read FILE; do
 
  FILE="$(echo "$FILE" | awk -F"." '{print $1}')"
  TRACKS="$(wc -l EPISODES | awk '{print $1}')"
 
  grep ^"$FILE" "${DATA}" | while IFS='|' read TRACK TITLE DIRECTOR WRITER YEAR COMMENT; do
 
        echo "$FILE < $TITLE [$TRACK of $TRACKS]"
 
        mp4tags -t "$TRACK" -T "$TRACKS" -s "$TITLE" -a "$DIRECTOR" -w "$WRITER" -y "$YEAR" -c "$COMMENT" "$FILE.m4v"
 
  done
 
done
17. November 2010 · Comments Off on Handle block devices that use the device-mapper driver. · Categories: Linux Admin, Linux Scripts, Linux Security · Tags: , ,
#!/bin/bash
## Created by: deaves
# Handle block devices that use the device-mapper driver.
#
## Requires: sha256sum, dm-mapper, aes modules loaded.
 
mntDST="$3"; mntSRC="$2"
NAME=`basename "${mntSRC}"`
 
if [ "$1" == "-m" ]; then
 
  echo "Mounting ${mntSRC} to ${mntDST}"
 
  # Generating encryption key.
  printf "Passphrase: "; read -s PASSPH
  KEY=`echo "${PASSPH}" | sha256sum | awk '{print $1}'`
 
  # Creating mapped device.
  if [ "$(echo ${KEY} | wc -c)" -eq "65" ] && [ ! -b "/dev/mapper/${NAME}" ]; then
    echo 0 `blockdev --getsize "${mntSRC}"` crypt aes-cbc-essiv:sha256 "${KEY}" 0 "${mntSRC}" 0 | dmsetup create ${NAME} > /dev/null 2> /dev/null \
      && echo -e "\n\n/dev/mapper/${NAME}: $(dmsetup status ${NAME})\n" \
      || echo -e "\nError: Unable to create mapping..."
 
    # Attempting to mount the device.
    if [ -b "/dev/mapper/${NAME}" ]; then
      mount "/dev/mapper/${NAME}" "${mntDST}" > /dev/null 2> /dev/null \
        && df -h "/dev/mapper/${NAME}" \
        || echo "Error: The device failed to mount; your passphrase may have been mistyped or the device may need to be formatted..."
    fi
  fi
 
elif [ "$1" == "-u" ]; then
 
  STATUS="Unmounting /dev/mapper/${NAME}: $(dmsetup status ${NAME})"
 
  # Unmount and remove the block device.
  umount "/dev/mapper/${NAME}" > /dev/null 2> /dev/null
  dmsetup remove "${NAME}" > /dev/null 2> /dev/null \
    && echo "${STATUS}" \
    || echo "Error: No device found or resouce busy..."
 
else
 
  printf "Usage: $0 [option]\n\n"
  printf "\t-m <device> <destination>\n"
  printf "\t-u <device>\n\n"
 
fi</device></destination></device>
16. November 2010 · Comments Off on Quickly convert a file to MP4 using ffmpeg. · Categories: Linux Scripts · Tags: , , ,
#!/bin/bash
## Created by deaves
# Quickly convert a file to MP4 using ffmpeg.
#
## Requires: ffmpeg (Ref: http://ubuntuforums.org/showthread.php?t=786095)
 
function usage () {
  ### Display the script arguments...
  printf "Convert a file to MP4 using ffmpeg (vcodec:H264 / acodec:AAC)\n\n"
  printf "Usage: $0 -K <kbps> <videofile>\n"
}
 
if [ "$1" == "-K" -a "$2" -gt "100" ]; then
  let BIT_RATE="$2 * 1024"
else
  usage && exit 1;
fi
 
if [ ! -f "$3.mp4" ]; then
 
  ### Two Pass; slow ffpreset.
  printf "$3 > 1st pass "
  ffmpeg -i "$3" -an -pass 1 -vcodec libx264 -vpre slow_firstpass -b $BIT_RATE -bt $BIT_RATE -threads 0 "$3.mp4" 2> /dev/null
  printf "> 2nd pass "
  ffmpeg -i "$3" -y -acodec libfaac -ab 128k -pass 2 -vcodec libx264 -vpre slow -b $BIT_RATE -bt $BIT_RATE -threads 0 "$3.mp4" 2> /dev/null
  printf "> $3.mp4\n Duration:"
 
 
  ### Cleanup.
  rm "ffmpeg2pass-0.log" "x264_2pass.log" "x264_2pass.log.mbtree"
  ffmpeg -i "$3.mp4" 2>&1 | grep -e Duration -e Stream | awk -F": " '{$1=""; print $0}'
 
else
 
  printf "$3\n Duration:"
  ffmpeg -i "$3.mp4" 2>&1 | grep -e Duration -e Stream | awk -F": " '{$1=""; print $0}'
 
fi</videofile></kbps>
15. November 2010 · Comments Off on Retrieves all AFD pages from the FAA’s website for your electronic flight bag. · Categories: Linux Scripts · Tags: , , ,
#!/bin/bash
### Created by: deaves
# Retrieves all AFD pages from the FAA's website.
#
## Requires: wget, pdftk
 
REGIONS="al ec nc ne nw pac se sw"
DATE="18NOV2010"
 
sAFD () {
  ### Create Directory for the region ###
  [ ! -d "${REGION}" ] && { mkdir "${REGION}"; }
 
  ## Fetch the AFD Legend ##
  if [ ! -e "${REGION}/${REGION}_front_${DATE}.pdf" ]; then
    wget -q -P "${REGION}" "http://naco.faa.gov/pdfs/${REGION}_front_${DATE}.pdf"
    printf "${REGION}/${REGION}_front_${DATE}.pdf "
  else
    printf "${REGION}/${REGION}_front_${DATE}.pdf "
  fi
 
  ## Fetch the pages for the AFD ##
  for PAGE in {1..1000}
  do
 
    if [ ! -e "${REGION}/${REGION}_${PAGE}_${DATE}.pdf" ]; then
      wget -q -P "${REGION}" "http://naco.faa.gov/pdfs/${REGION}_${PAGE}_${DATE}.pdf" || break
      printf "${REGION}/${REGION}_${PAGE}_${DATE}.pdf "
    else
      printf "${REGION}/${REGION}_${PAGE}_${DATE}.pdf "
    fi
 
  done
 
  ## Fetch the AFD Supplemental ##
  if [ ! -e "${REGION}/${REGION}_rear_${DATE}.pdf" ]; then
    wget -q -P "${REGION}" "http://naco.faa.gov/pdfs/${REGION}_rear_${DATE}.pdf"
    printf "${REGION}/${REGION}_rear_${DATE}.pdf "
  else
    printf "${REGION}/${REGION}_rear_${DATE}.pdf "
  fi
}
 
for REGION in $REGIONS; do
  echo "Building AFD: ${REGION}_${DATE}.pdf"
  pdftk `sAFD` output "${REGION}_${DATE}.pdf"
done