bin-utils/add_mg.sh
2015-05-30 18:42:42 +02:00

42 lines
931 B
Bash
Executable File

#!/bin/sh
MG_ROOT="/usr/local/www/photos.meutel.net/mediagoblin"
ALBUMS_ROOT="/home/mediagoblin/albums"
MG_USER=meutel
add_all()
{
echo "=== TAGS $2 $3 ==="
ADD_PATH=$1
echo "== path: $ADD_PATH"
FILES=$(find $ADD_PATH -type f -maxdepth 1 -iname "*.png" -o -iname "*.mp4" -o -iname "*.jpg")
for file in $FILES
do
echo "Ajout: $file"
TITLE=$(basename $file)
$MG_ROOT/bin/gmg addmedia $MG_USER "$file" --title "$TITLE" --tags "$2,$3"
done
}
ifs=$IFS
IFS='\
'
ALBUMS=$(ls $ALBUMS_ROOT)
echo "albums: $ALBUMS"
for album in $ALBUMS
do
ALBUM_NAME=$(basename $album)
TAGALBUM=$(echo $ALBUM_NAME | sed 's/ /_/g')
echo "Album: $ALBUM_NAME"
ALBUM_PATH="${ALBUMS_ROOT}/$ALBUM_NAME"
for subalbum in $(find $ALBUM_PATH -type d)
do
echo "Sous-album: $subalbum"
SUBALBUM_NAME=$(basename $subalbum)
TAGSUBALBUM=$(echo $SUBALBUM_NAME | sed 's/ /_/g')
add_all "$subalbum" "$TAGALBUM" "$TAGSUBALBUM"
done
done
IFS=$ifs