diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-03-17 11:32:52 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-03-17 11:32:52 -0300 |
commit | 791aa5806917e4e97b8975a8b09d3cf5548bbb79 (patch) | |
tree | 32625b144b03c9f26748cceb1be67a43eaaf2a97 | |
parent | 07fc7078c1ff36e6becc0fce2338d70ae60d4881 (diff) | |
download | puppet-backup-791aa5806917e4e97b8975a8b09d3cf5548bbb79.tar.gz puppet-backup-791aa5806917e4e97b8975a8b09d3cf5548bbb79.tar.bz2 |
Cleanup sync-media
-rwxr-xr-x | files/sync-media | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/files/sync-media b/files/sync-media index d2155fe..1c312c4 100755 --- a/files/sync-media +++ b/files/sync-media @@ -26,19 +26,6 @@ function sync_media_identity { function sync_media_add { git annex add . - # Adding hidden files and symlinks, find version - #find -name '.*' -exec git annex add {} \; - #find -type l -exec git add {} \; - - # Adding hidden files and symlinks, git+for version - #for file in `git status --porcelain -u | sed -e 's/?? //'`; do - # if [ -h "$file" ]; then - # git add $file - # else - # git annex add $file - # fi - #done - # Adding hidden files and symlinks, git+while version git status --porcelain -u | sed -e 's/?? //' | while read file; do if [ -h "$file" ]; then @@ -49,6 +36,71 @@ function sync_media_add { done } +# If there is a playlists folder, make sure mpd user can write to it +function sync_media_playlist_perms { + if [ -d "playlists" ]; then + $sudo chmod 775 playlists + $sudo chown -R mpd.audio playlists + find playlists -type f -exec sudo chmod 664 {} \; + find playlists -type d -exec sudo chmod 775 {} \; + fi +} + +# Fix incoming permissions +function sync_media_incoming_perms { + if [ -d "$INCOMING" ]; then + echo "Fixing $INCOMING permissions..." + $sudo find $INCOMING -type f -exec chmod 664 {} \; + $sudo find $INCOMING -type d -exec chmod 775 {} \; + $sudo chown -R $WHOAMI.incoming $INCOMING + fi +} + +# Run fsck +function sync_media_fsck { + if [ "$FSCK" == "true" ]; then + git annex fsck --fast + fi +} + +# Run dropunused +function sync_media_dropunused { + if [ "$DROPUNUSED" == "true" ]; then + git annex unused + git annex dropunused 1-1000 + fi +} + +# Control whether the repository should have a copy of everything +function sync_media_getall { + local repo="$1" + + if [ "`git -C $repo config sync-media.getall`" == "true" ]; then + git annex get . + fi +} + +# Ensure we have a reference to the remote repository +function sync_media_ensure_remote { + local remote="$1" + local path="$2" + + if [ -z "$remote" ] || [ -z "$path" ]; then + return + fi + + # Check for local or remote repo + if [ -z "$DRIVE" ]; then + path="$REMOTE.$DOMAIN:$path" + elif [ ! -d "$path/.git/annex" ]; then + return + fi + + if ! git remote | grep -q "^$remote$"; then + echo git remote add $remote $path + fi +} + # Set sudo config if [ "$WHOAMI" != 'root' ]; then sudo="sudo" @@ -83,13 +135,7 @@ if [ -d "$CACHE" ]; then #$sudo find $CACHE -type f -exec chmod 644 {} \; #$sudo find $CACHE -type d -exec chmod 755 {} \; - # Fix incoming permissions - if [ -d "$INCOMING" ]; then - echo "Fixing $INCOMING permissions..." - $sudo find $INCOMING -type f -exec chmod 664 {} \; - $sudo find $INCOMING -type d -exec chmod 775 {} \; - $sudo chown -R $WHOAMI.incoming $INCOMING - fi + sync_media_incoming_perms # Add and update local repositories for folder in `ls $CACHE`; do @@ -107,39 +153,14 @@ if [ -d "$CACHE" ]; then cd $CACHE/$folder echo "Syncing $CACHE/$folder..." - # If there is a playlists folder, make sure mpd user can write to it - if [ -d "playlists" ]; then - $sudo chmod 775 playlists - $sudo chown -R mpd.audio playlists - find playlists -type f -exec sudo chmod 664 {} \; - find playlists -type d -exec sudo chmod 775 {} \; - fi - - # Ensure we have a reference to the remote repository - if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then - # Check remote - if ! git remote | grep -q "^$REMOTE$"; then - git remote add $REMOTE $VOLUME/$MEDIA/$folder - fi - fi - + sync_media_playlist_perms + sync_media_ensure_remote $REMOTE $VOLUME/$MEDIA/$folder sync_media_identity sync_media_add git annex sync - - # Control whether the repository should have a copy of everything - if [ "`git -C $CACHE/$folder config sync-media.getall`" == "true" ]; then - git annex get . - fi - - if [ "$FSCK" == "true" ]; then - git annex fsck --fast - fi - - if [ "$DROPUNUSED" == "true" ]; then - git annex unused - git annex dropunused 1-1000 - fi + sync_media_getall $CACHE/$folder + sync_media_fsck + sync_media_dropunused ) fi done @@ -190,33 +211,14 @@ if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then cd $VOLUME/$MEDIA/$folder echo "Syncing $VOLUME/$MEDIA/$folder..." - # Check remote - if ! git remote | grep -q "^$HOST$"; then - git remote add $HOST $CACHE/$folder - fi - - # If there is a playlists folder, make sure mpd user can write to it - if [ -d "playlists" ]; then - $sudo chmod 775 playlists - $sudo chown -R mpd.audio playlists - find playlists -type f -exec sudo chmod 664 {} \; - find playlists -type d -exec sudo chmod 775 {} \; - fi - + sync_media_ensure_remote $HOST $CACHE/$folder + sync_media_playlist_perms sync_media_identity sync_media_add git annex sync git annex get . --numcopies=3 - - if [ "$FSCK" == "true" ]; then - git annex fsck --fast - fi - - if [ "$DROPUNUSED" == "true" ]; then - git annex unused - git annex dropunused 1-1000 - fi - + sync_media_fsck + sync_media_dropunused #git annex drop --auto --numcopies=2 ) elif [ -d "$CACHE/$folder" ]; then @@ -234,15 +236,13 @@ elif [ ! -z "$REMOTE" ]; then continue fi - if git -C $CACHE/$folder remote | grep -q "^$REMOTE$"; then - ( - cd $CACHE/$folder - git annex copy . --to $REMOTE - git annex sync - ) - else - echo "No such remote $REMOTE" - fi + sync_media_ensure_remote $REMOTE $CACHE/$folder + + ( + cd $CACHE/$folder + git annex copy . --to $REMOTE + git annex sync + ) else if [ ! -e "$CACHE/$folder/.sync-media/skip" ]; then echo "Syncing $VOLUME/$MEDIA/$folder..." |