#!/bin/bash # ## Update grimoires from git dirs. # # These are pretty obvious. GRIM_ROOT=/var/lib/sorcery/codex GIT_ROOT=/home/yourhomedir/git # GRIM_DIR and GIT_DIR need to correspond with eachother. They exist # separately because the grimoire and git repository names aren't always # the same. Notice that these are arrays, so don't remove the # parenthesis. GRIM_DIR=($GRIM_ROOT/test $GRIM_ROOT/z-rejected $GRIM_ROOT/xorg-modular) GIT_DIR=($GIT_ROOT/grimoire $GIT_ROOT/z-rejected $GIT_ROOT/xorg-modular) # These are here for setting the correct URL in the GRIMOIRE file. That # way you can later use 'scribe update'. FROM_PATH needs to correspond # to GRIM_DIR and GIT_DIR, and is an array. FROM_SERV=http://codex.sourcemage.org FROM_PATH=(test.tar.bz2 z-rejected.tar.bz2 testing/xorg-modular.tar.bz2) # To reindex the grimoires after update. REINDEX=y n=0 ok=0 for i in ${GRIM_DIR[@]}; do if [[ ! -d "${GIT_DIR[n]}" ]]; then echo "error: ${GIT_DIR[n]} does not exist!" >&2 echo "Not updating grimoire ${GRIM_DIR[n]##*/}." >&2 ((n+=1)) continue fi if [[ -e "${GRIM_DIR[n]}" ]]; then if [[ -d "${GRIM_DIR[n]}" ]]; then echo -n "Deleting ${GRIM_DIR[n]}/* ... " rm -rf "${GRIM_DIR[n]}/*" 2>/dev/null echo done. else echo "error: ${GRIM_DIR[n]} exists but is not a directory!" >&2 echo "Not updating grimoire ${GRIM_DIR[n]##*/}." >&2 ((n+=1)) continue fi else echo -n "Creating ${GRIM_DIR[n]}/ ... " mkdir -p "${GRIM_DIR[n]}" echo done. fi echo -n "Copying files from ${GIT_DIR[n]}/ ... " for file in `ls "${GIT_DIR[n]}/"`; do cp -r "${GIT_DIR[n]}/$file" "${GRIM_DIR[n]}/" done echo done. echo -n "Creating ${GRIM_DIR[n]}/GRIMOIRE ... " echo "FROM_URL=$FROM_SERV/${FROM_PATH[n]}" > "${GRIM_DIR[n]}/GRIMOIRE" chmod +x "${GRIM_DIR[n]}/GRIMOIRE" echo done. ((ok+=1)) ((n+=1)) done if ((ok>0)); then echo "$ok grimoires updated." [[ "$REINDEX" == "y" ]] && scribe reindex ${GRIM_DIR[@]/$GRIM_ROOT\/} else echo "No grimoires updated." fi