#!/bin/bash

dir="${1}"
liste="${2}"

mkdir ${dir}/SUJETS+mdp;

i=1;
for f in ${dir}/*.pdf; do
	i=$((i+1));
	ligne=`head -${i} ${liste} | tail -1`;
	nom=`echo ${ligne} | cut -d, -f2`;
	prenom=`echo ${ligne} | cut -d, -f3`; 
	mdp=`echo ${ligne} | cut -d, -f4`;
	Renom=`echo ${nom}-${prenom}_Maths.pdf`;
	pdftk "${f}" output ${dir}/SUJETS+mdp/${Renom} owner_pw 123 user_pw ${mdp};	
	echo "copie de ${prenom} traitée";
	done

