Code Sample |
#!/bin/bash # dsl2unc v0.2 # Just automates Robert's instructions for making a unc extension from a dsl. # WDef Sept 2006 # Changelog v0.2 # Handles symlinks, opt and empty directories in user.tar.gz. # Current working directory is assumed if path to argument extension is not given. # Runs in batch mode: converts all argument .dsls to .uncs #- eg to process somedirectory full of extensions, if dsl2unc is in PATH: #- cd somedirectory; dsl2unc * # Directory $DIR for $WORK and output is now settable. # More lurid coloring :=) #==========================// USER SETTING//=============================== # Put DIR on a hard drive partition if insufficient room in /ramdisk/home/dsl DIR=/home/dsl #==========================// FNS //======================================== help(){ cat <<"EOF" dsl2unc v0.2 - convert .dsl extension to .unc Usage: dsl2unc </path/to/ext1.dsl /path/to/ext2.dsl ..> Creates a work dir in $DIR New unc(s) is output in $DIR Default DIR=/home/dsl EOF exit } dir_filter(){ # Filter out non-empty dir lines from stdin while read LM; do if [ -d "${WORK}/$LM" ]; then if [ $(ls -1A ${WORK}/$LM| wc -l) -eq 0 ]; then # empty dir - ok echo ${LM} fi else # files, symlinks - ok echo ${LM} fi done } #====================================================================== . /etc/init.d/dsl-functions # for ANSI colors results=/tmp/dsl2unc_results rm -f ${results} if [ "${1}" = -h ] || [ "${1}" = --help ] || [ $# -eq 0 ]; then help; fi CURRENTD="${PWD}" APP="" for APP in $*; do # If no path supplied, assume current working dir [ $(echo ${APP} | tr '/' ' '| wc -w) -eq 1 ] && APP="${CURRENTD}/${APP}" if [ ! -e "${APP}" ]; then echo "${RED}Can't find ${APP}${NORMAL}" >>${results} continue fi if [ ${APP##*.} != dsl ]; then echo "${RED}${APP} is not a .dsl extension.${NORMAL}" >>${results}; continue; fi NAME=$(basename ${APP} .dsl) WORK=${DIR}/$NAME if [ -e "${WORK}" ]; then echo "${RED}${WORK} already exists.${NORMAL}" >>${results}; continue; fi mkdir ${WORK} echo echo "${WHITE}Making ${GREEN}$NAME.unc${WHITE} from ${YELLOW}$NAME.dsl ..${NORMAL}" echo cd ${WORK} tar -zxvf ${APP} find home opt tmp 2>/dev/null | dir_filter | xargs tar -czvf user.tar.gz 2>/dev/null rm -rf home opt tmp cd .. mkisofs -R -hide-rr-moved -cache-inodes -pad ${WORK} | create_compressed_fs - 65536 >$NAME.unc if [ $? -ne 0 ]; then echo "${RED}Error making $NAME.unc" >>${results}; continue; fi echo echo "${GREEN}Now test your new ${YELLOW}$NAME.unc!${NORMAL}" echo "${YELLOW}$NAME.dsl${WHITE} --> ${GREEN}$NAME.unc${NORMAL}" >>${results} done echo echo "======================================================================" echo echo "${WHITE}DSL2UNC ${WHITE}RESULTS:${NORMAL}" echo cat ${results} echo echo "======================================================================" echo "${GREEN}Finished.${NORMAL}" exit 0 |