Compare commits
57 Commits
97a95c9a91
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ee669d8b | ||
|
|
abecd1843d | ||
|
|
7754459ae3 | ||
|
|
41edbfc11e | ||
|
|
e518229940 | ||
|
|
39121427db | ||
|
|
4949790bd0 | ||
|
|
bde024adf3 | ||
|
|
4078149eec | ||
|
|
e69f505873 | ||
|
|
cc720a3799 | ||
|
|
28d2bff3ef | ||
|
|
b085828350 | ||
|
|
8d55c06c2b | ||
|
|
a9e7024830 | ||
|
|
20361ed80d | ||
|
|
cc2ad0a6a7 | ||
|
|
3de9e74331 | ||
|
|
2847ed5514 | ||
|
|
61ef28108d | ||
|
|
8abff0fb6c | ||
|
|
0936b690ec | ||
|
|
b82a71b9e7 | ||
|
|
0ea759b490 | ||
|
|
914a81aded | ||
|
|
21b4b513c0 | ||
|
|
5d686e5ce7 | ||
|
|
2d1275ba85 | ||
|
|
9e13cb5ecc | ||
|
|
a8f301f649 | ||
|
|
2da84289f1 | ||
|
|
cb43cb75b7 | ||
|
|
8e66036550 | ||
|
|
d4e0e34d32 | ||
|
|
eec9bfe67d | ||
|
|
cf556c8b0d | ||
|
|
9a700c614a | ||
|
|
04e9d8d372 | ||
|
|
01c2f2d35e | ||
|
|
d916f33b91 | ||
|
|
3980c82d2e | ||
|
|
1dd75eb2ba | ||
|
|
67780d5b7c | ||
|
|
dfde73183e | ||
|
|
5003e5174e | ||
|
|
5fac3f9b37 | ||
|
|
d550a98418 | ||
|
|
8681a360d1 | ||
|
|
9c1a3c8ded | ||
|
|
0decab4064 | ||
|
|
f4d9dd7a91 | ||
|
|
ff974bd43c | ||
|
|
e87da06111 | ||
|
|
c6c92bf1ef | ||
|
|
abc64501e2 | ||
|
|
69aef9fb9f | ||
|
|
e38d98b1a1 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.specstory
|
||||||
@@ -9,6 +9,8 @@ DOSSIER_LOGS="/home/$USER/autopost/logs/"
|
|||||||
DOSSIER_NZB_ATTENTE="/home/$USER/autopost/ATTENTE/"
|
DOSSIER_NZB_ATTENTE="/home/$USER/autopost/ATTENTE/"
|
||||||
DOSSIER_NZB_FINAL="/home/$USER/autopost/FINIS/"
|
DOSSIER_NZB_FINAL="/home/$USER/autopost/FINIS/"
|
||||||
|
|
||||||
|
MOVE_CMD="cp -rl" # cp -rl, cp -rs, ln -s, mv, cp
|
||||||
|
|
||||||
#CONFIG FOURNISSEUR USENET DE POST
|
#CONFIG FOURNISSEUR USENET DE POST
|
||||||
NG_HOST=""
|
NG_HOST=""
|
||||||
NG_PORT=""
|
NG_PORT=""
|
||||||
@@ -25,5 +27,9 @@ MYSQL_USER=""
|
|||||||
MYSQL_PASS=""
|
MYSQL_PASS=""
|
||||||
MYSQL_DB=""
|
MYSQL_DB=""
|
||||||
|
|
||||||
|
#CMD_parpar
|
||||||
|
|
||||||
|
CMD_PARPAR="-s10M -S -m4096M -t16 -r20%"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,12 @@ module.exports = {
|
|||||||
// Port sur lequel le serveur écoute
|
// Port sur lequel le serveur écoute
|
||||||
// Attention si vous êtes sur une seedbox de bien choisir un port laisser libre par votre hébergeur
|
// Attention si vous êtes sur une seedbox de bien choisir un port laisser libre par votre hébergeur
|
||||||
// chez ultracc par exemple la commande est app-ports free
|
// chez ultracc par exemple la commande est app-ports free
|
||||||
port: Voir indications ci dessus,
|
port: , //Voir indications ci dessus,
|
||||||
|
name: 'Nom', //Choisir un nom
|
||||||
|
background_color: 'slate-900', // à choisir ici https://tailwindcss.com/docs/colors
|
||||||
|
|
||||||
|
// choisir mysql ou sqlite
|
||||||
|
dbtype: 'sqlite',
|
||||||
// Chemin vers le fichier de base de données SQLite
|
// Chemin vers le fichier de base de données SQLite
|
||||||
dbFile: path.join(__dirname, 'base_autopost.db'),
|
dbFile: path.join(__dirname, 'base_autopost.db'),
|
||||||
|
|
||||||
@@ -24,10 +28,17 @@ module.exports = {
|
|||||||
|
|
||||||
// Secret pour la configuration des sessions "curl -L pw.vdx.sh/w/32"
|
// Secret pour la configuration des sessions "curl -L pw.vdx.sh/w/32"
|
||||||
sessionSecret: 'Voir commande ci dessus',
|
sessionSecret: 'Voir commande ci dessus',
|
||||||
|
trustProxy: 0, // 0=pas de proxy, 1=Nginx, 2=Cloudflare->Nginx, etc.
|
||||||
|
cookieSecure: false, // true si HTTPS de bout en bout
|
||||||
|
sessionStorePath: './sessions',
|
||||||
|
|
||||||
// Informations d'authentification
|
// Informations d'authentification
|
||||||
auth: {
|
auth: {
|
||||||
username: 'user',
|
username: 'user',
|
||||||
password: 'pass'
|
password: 'pass'
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// Configuration pour le renvoi vers le site principal
|
||||||
|
apiUrl: 'A NOUS DEMANDER SUR DISCORD',
|
||||||
|
apiKey: 'A RETROUVER DANS VOTRE PROFIL'
|
||||||
};
|
};
|
||||||
@@ -19,14 +19,12 @@ attente() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkusenet(){
|
checkusenet(){
|
||||||
SERVICE="nyuu"
|
SERVICE="nyuu"
|
||||||
if pgrep -x "$SERVICE" >/dev/null
|
while pgrep -x "$SERVICE" >/dev/null; do
|
||||||
then
|
echo "$SERVICE EN COURS"
|
||||||
echo "$SERVICE EN COURS"
|
sleep 16
|
||||||
sleep 16
|
done
|
||||||
else
|
echo "$SERVICE OK"
|
||||||
echo "$SERVICE OK"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cd "${DOSSIER_GLOBAL}"
|
cd "${DOSSIER_GLOBAL}"
|
||||||
@@ -45,8 +43,13 @@ while true; do
|
|||||||
LOG="${DOSSIER_LOGS}${FILESANSEXT}.log"
|
LOG="${DOSSIER_LOGS}${FILESANSEXT}.log"
|
||||||
|
|
||||||
echo -e "${VERT}DEBUT DE TRAITEMENT DE ${FILESANSEXT}${NORMAL}" | tee -a "$LOG"
|
echo -e "${VERT}DEBUT DE TRAITEMENT DE ${FILESANSEXT}${NORMAL}" | tee -a "$LOG"
|
||||||
|
if [ "$dbtype" = "mysql" ]; then
|
||||||
|
db_query "UPDATE \`$MYSQL_TABLE\` SET status = 4 WHERE id = ${id};"
|
||||||
|
fi
|
||||||
echo -e "${CYAN}CREATION DES PAR2${NORMAL}" | tee -a "$LOG"
|
echo -e "${CYAN}CREATION DES PAR2${NORMAL}" | tee -a "$LOG"
|
||||||
parpar -s10M -S -m4096M -t16 -r20% -O -o "${FILESANSEXT}.par2" "${name}" \
|
# Utilise CMD_PARPAR si défini, sinon valeurs par défaut
|
||||||
|
PARPAR_OPTS="${CMD_PARPAR:--s10M -S -m4096M -t16 -r20%}"
|
||||||
|
parpar $PARPAR_OPTS -O -o "${FILESANSEXT}.par2" "${name}" \
|
||||||
> >(tee -a "$LOG") 2> >(tee -a "$LOG" >&2)
|
> >(tee -a "$LOG") 2> >(tee -a "$LOG" >&2)
|
||||||
ret=$?
|
ret=$?
|
||||||
if [ $ret -ne 0 ]; then
|
if [ $ret -ne 0 ]; then
|
||||||
@@ -58,22 +61,43 @@ while true; do
|
|||||||
|
|
||||||
{
|
{
|
||||||
echo -e "${VERT}UPLOAD SUR USENET${NORMAL}"
|
echo -e "${VERT}UPLOAD SUR USENET${NORMAL}"
|
||||||
|
files=( ${FILESANSEXT}.* )
|
||||||
checkusenet
|
checkusenet
|
||||||
nyuu -h ${NG_HOST} -P ${NG_PORT} -S -u ${NG_USER} -p ${NG_PASS} -n ${NG_NBR_CONN} \
|
script -q -c \
|
||||||
-g alt.binaries.boneless -o "${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb" \
|
"nyuu -h ${NG_HOST} -P ${NG_PORT} -S -u ${NG_USER} -p ${NG_PASS} -n ${NG_NBR_CONN} \
|
||||||
--nzb-title "${FILESANSEXT}" -f "{rand(14)} {rand(14)}@{rand(5)}.{rand(3)}" \
|
-g alt.binaries.boneless -o '${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb' \
|
||||||
--message-id "{rand(32)}@{rand(8)}.{rand(3)}" \
|
--nzb-title '${FILESANSEXT}' \
|
||||||
--subject "{rand(32)}" --nzb-subject "{filename}" --obfuscate-articles ${FILESANSEXT}.*
|
-f '{rand(14)} {rand(14)}@{rand(5)}.{rand(3)}' \
|
||||||
|
--message-id '{rand(32)}@{rand(8)}.{rand(3)}' \
|
||||||
|
--subject '{rand(32)}' \
|
||||||
|
--nzb-subject '[{0filenum}/{files}] - \"{filename}\" yEnc ({part}/{parts})' \
|
||||||
|
--obfuscate-articles ${files[*]} \
|
||||||
|
--progress=stderr" \
|
||||||
|
/dev/null
|
||||||
|
|
||||||
if [ -e "${DOSSIER_NFO}${FILESANSEXT}.json" ] || [ -e "${DOSSIER_NFO}${FILESANSEXT}.txt" ]; then
|
if [ -e "${DOSSIER_NFO}${FILESANSEXT}.json" ] || [ -e "${DOSSIER_NFO}${FILESANSEXT}.txt" ]; then
|
||||||
echo -e "${JAUNE}VERIF DU NZB${NORMAL}"
|
echo -e "${JAUNE}VERIF DU NZB${NORMAL}"
|
||||||
nzbsizebit=$(bash ${ANALYZER} "${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb" | jq '.Taillebit')
|
nzbsizebit=$(bash ${ANALYZER} "${DOSSIER_NZB_ATTENTE}${FILESANSEXT}.nzb" | jq '.Taillebit')
|
||||||
echo -e "NZB_SIZE : ${nzbsizebit}"
|
echo -e "NZB_SIZE : ${nzbsizebit}"
|
||||||
|
# Détermine si on est en mode "symlink" selon la conf
|
||||||
|
symlink_mode=0
|
||||||
|
case "${MOVE_CMD:-}" in
|
||||||
|
"cp -rs"|"ln -s") symlink_mode=1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [[ "${name}" =~ \.(iso)$ ]]; then
|
if [[ "${name}" =~ \.(iso)$ ]]; then
|
||||||
jsonsizebit=$(du -b -c "${name}" | grep total | awk '{ print $1 }')
|
if (( symlink_mode )); then
|
||||||
|
# Suivre le lien symbolique pour obtenir la taille réelle
|
||||||
|
jsonsizebit=$(du -Lb -c -- "${name}" | awk '/total/ {print $1}')
|
||||||
|
else
|
||||||
|
# Comportement inchangé
|
||||||
|
jsonsizebit=$(du -b -c -- "${name}" | awk '/total/ {print $1}')
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
# Comportement inchangé
|
||||||
jsonsizebit=$(jq -r '.media.track[] | select(."@type" == "General") | .FileSize' "${DOSSIER_NFO}${FILESANSEXT}.json")
|
jsonsizebit=$(jq -r '.media.track[] | select(."@type" == "General") | .FileSize' "${DOSSIER_NFO}${FILESANSEXT}.json")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "MEDIAINFO_SIZE : ${jsonsizebit}"
|
echo -e "MEDIAINFO_SIZE : ${jsonsizebit}"
|
||||||
|
|
||||||
if [[ ${nzbsizebit} -le ${jsonsizebit} ]] || [[ ${nzbsizebit} = "NAN" ]]; then
|
if [[ ${nzbsizebit} -le ${jsonsizebit} ]] || [[ ${nzbsizebit} = "NAN" ]]; then
|
||||||
@@ -110,7 +134,7 @@ while true; do
|
|||||||
else
|
else
|
||||||
echo -e "${ROUGE}ENVOI SUR LE SITE IMPOSSIBLE NFO MANQUANT${NORMAL}"
|
echo -e "${ROUGE}ENVOI SUR LE SITE IMPOSSIBLE NFO MANQUANT${NORMAL}"
|
||||||
fi
|
fi
|
||||||
} > >(tee -a "$LOG") 2>&1
|
} 2>&1 | tee -a "$LOG"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}PROBLEME DE PROPAGATION POST EN PAUSE${NORMAL}"
|
echo -e "${ROUGE}PROBLEME DE PROPAGATION POST EN PAUSE${NORMAL}"
|
||||||
|
|||||||
718
autopost/public/autopost.js
Normal file
718
autopost/public/autopost.js
Normal file
@@ -0,0 +1,718 @@
|
|||||||
|
// === Autopost client script ===
|
||||||
|
|
||||||
|
// --- CSRF global ---
|
||||||
|
(function () {
|
||||||
|
const meta = document.querySelector('meta[name="csrf-token"]');
|
||||||
|
const CSRF_TOKEN = meta ? meta.content : (window.__BOOTSTRAP__ && window.__BOOTSTRAP__.csrf) || '';
|
||||||
|
if (window.jQuery) {
|
||||||
|
$.ajaxSetup({ headers: { 'x-csrf-token': CSRF_TOKEN } });
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// --- XSS escape côté client ---
|
||||||
|
function esc(s) {
|
||||||
|
// ATTENTION: backtick échappé dans la classe de caractères: \`
|
||||||
|
return String(s).replace(/[&<>"'\`=]/g, c => ({
|
||||||
|
'&': '&', '<': '<', '>': '>',
|
||||||
|
'"': '"', "'": ''', '\`': '`', '=': '='
|
||||||
|
}[c]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Bootstrap values ---
|
||||||
|
const INITIAL_PAGE = (window.__BOOTSTRAP__ && window.__BOOTSTRAP__.page) || 1;
|
||||||
|
const INITIAL_TOTAL_PAGES= (window.__BOOTSTRAP__ && window.__BOOTSTRAP__.totalPages) || 1;
|
||||||
|
const PAGE_LIMIT = (window.__BOOTSTRAP__ && window.__BOOTSTRAP__.limit) || 100;
|
||||||
|
|
||||||
|
let currentPage = INITIAL_PAGE;
|
||||||
|
let currentTotalPages = INITIAL_TOTAL_PAGES;
|
||||||
|
let activeFilter = null; // number | null
|
||||||
|
let activeQuery = ''; // string
|
||||||
|
|
||||||
|
// --- Rendering: table ---
|
||||||
|
function updateTable(rows) {
|
||||||
|
var tbody = $('table tbody');
|
||||||
|
tbody.empty();
|
||||||
|
|
||||||
|
rows.forEach(function(row) {
|
||||||
|
var statusText = '';
|
||||||
|
var statusClass = '';
|
||||||
|
|
||||||
|
switch (parseInt(row.status)) {
|
||||||
|
case 0: statusText = 'EN ATTENTE'; statusClass = 'bg-cyan-500 text-black font-bold'; break;
|
||||||
|
case 1: statusText = 'ENVOI TERMINÉ'; statusClass = 'bg-green-300 text-black font-bold'; break;
|
||||||
|
case 2: statusText = 'ERREUR'; statusClass = 'bg-red-300 text-black font-bold'; break;
|
||||||
|
case 3: statusText = 'DEJA DISPONIBLE';statusClass = 'bg-pink-300 text-black font-bold'; break;
|
||||||
|
case 4: statusText = 'EN COURS'; statusClass = 'bg-yellow-300 text-black font-bold'; break;
|
||||||
|
default: statusText = 'INCONNU';
|
||||||
|
}
|
||||||
|
|
||||||
|
var logLink = (parseInt(row.status) === 1 || parseInt(row.status) === 2 || parseInt(row.status) === 4)
|
||||||
|
? ' | <a href="#" class="log-link text-blue-400 hover:underline" data-filename="' + esc(row.nom) + '">Log</a>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var mediainfoLink = (parseInt(row.status) === 0 || parseInt(row.status) === 1 || parseInt(row.status) === 2)
|
||||||
|
? ' | <a href="#" class="mediainfo-link text-blue-400 hover:underline" data-filename="' + esc(row.nom) + '">Mediainfo</a>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var dlLink = (parseInt(row.status) === 1)
|
||||||
|
? ' | <a href="/autopost/dl?name=' + encodeURIComponent(row.nom) + '" class="dl-link text-blue-400 hover:underline">DL</a>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var resendLink = (parseInt(row.status) === 1)
|
||||||
|
? ' | <a href="#" class="resend-link text-green-400 hover:underline" data-id="' + row.id + '" data-filename="' + esc(row.nom) + '">Renvoyer</a>'
|
||||||
|
: '';
|
||||||
|
|
||||||
|
var tr =
|
||||||
|
'<tr id="row-' + row.id + '" data-status="' + row.status + '" class="odd:bg-gray-800 even:bg-gray-700">' +
|
||||||
|
'<td class="px-4 py-2 border border-gray-700 text-center">' +
|
||||||
|
'<input type="checkbox" class="row-checkbox checkbox-custom" data-id="' + row.id + '" data-name="' + esc(row.nom) + '">' +
|
||||||
|
'</td>' +
|
||||||
|
'<td class="px-4 py-2 border border-gray-700 whitespace-nowrap">' + esc(row.nom) + '</td>' +
|
||||||
|
'<td class="px-4 py-2 border border-gray-700 status-text whitespace-nowrap ' + statusClass + '">' + statusText + '</td>' +
|
||||||
|
'<td class="px-4 py-2 border border-gray-700">' + row.id + '</td>' +
|
||||||
|
'<td class="px-4 py-2 border border-gray-700">' +
|
||||||
|
'<a href="#" class="edit-link text-blue-400 hover:underline" data-id="' + row.id + '" data-status="' + row.status + '">Editer</a> | ' +
|
||||||
|
'<a href="#" class="delete-link text-blue-400 hover:underline" data-id="' + row.id + '">Supprimer</a>' +
|
||||||
|
logLink + mediainfoLink + dlLink + resendLink +
|
||||||
|
'</td>' +
|
||||||
|
'</tr>';
|
||||||
|
|
||||||
|
tbody.append(tr);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Rendering: pagination ---
|
||||||
|
function renderPaginationHTML(page, totalPages) {
|
||||||
|
var prevDisabled = page <= 1;
|
||||||
|
var nextDisabled = page >= totalPages;
|
||||||
|
|
||||||
|
var h = '';
|
||||||
|
h += '<ul class="inline-flex items-center -space-x-px">';
|
||||||
|
h += '<li>';
|
||||||
|
if (prevDisabled) {
|
||||||
|
h += '<span class="px-3 py-2 ml-0 leading-tight text-gray-500 bg-gray-200 border border-gray-300 rounded-l-lg">Précédent</span>';
|
||||||
|
} else {
|
||||||
|
h += '<a href="/autopost/?page=' + (page - 1) + '" data-page="' + (page - 1) + '" class="px-3 py-2 ml-0 leading-tight text-gray-500 bg-white border border-gray-300 rounded-l-lg hover:bg-gray-100 hover:text-gray-700">Précédent</a>';
|
||||||
|
}
|
||||||
|
h += '</li>';
|
||||||
|
h += '<li><span class="px-4 py-2 leading-tight text-gray-700 bg-white border border-gray-300">Page ' + page + ' sur ' + totalPages + '</span></li>';
|
||||||
|
h += '<li>';
|
||||||
|
if (nextDisabled) {
|
||||||
|
h += '<span class="px-3 py-2 leading-tight text-gray-500 bg-gray-200 border border-gray-300 rounded-r-lg">Suivant</span>';
|
||||||
|
} else {
|
||||||
|
h += '<a href="/autopost/?page=' + (page + 1) + '" data-page="' + (page + 1) + '" class="px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 rounded-r-lg hover:bg-gray-100 hover:text-gray-700">Suivant</a>';
|
||||||
|
}
|
||||||
|
h += '</li>';
|
||||||
|
h += '</ul>';
|
||||||
|
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
function updatePagination(page, totalPages) {
|
||||||
|
$('#pagination').html(renderPaginationHTML(page, totalPages));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Data loading ---
|
||||||
|
function loadPage(p) {
|
||||||
|
const targetPage = Math.max(1, parseInt(p, 10) || 1);
|
||||||
|
|
||||||
|
const isFilter = activeFilter !== null;
|
||||||
|
const url = isFilter ? '/autopost/filter' : '/autopost/search';
|
||||||
|
const data = isFilter
|
||||||
|
? { status: activeFilter, page: targetPage, limit: PAGE_LIMIT }
|
||||||
|
: { q: activeQuery || '', page: targetPage, limit: PAGE_LIMIT };
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'GET',
|
||||||
|
data: data,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(resp) {
|
||||||
|
updateTable(resp.rows);
|
||||||
|
currentPage = resp.page;
|
||||||
|
currentTotalPages = resp.totalPages;
|
||||||
|
updatePagination(currentPage, currentTotalPages);
|
||||||
|
// Mettre à jour les actions en lot après le chargement des nouvelles données
|
||||||
|
updateBulkActions();
|
||||||
|
},
|
||||||
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
|
if (textStatus !== 'abort') {
|
||||||
|
console.error('Erreur AJAX :', textStatus, errorThrown);
|
||||||
|
alert('Erreur lors du chargement de la page.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Long polling: refresh table when new mediainfo/log apparaît ---
|
||||||
|
(function () {
|
||||||
|
var lastVersion = null;
|
||||||
|
|
||||||
|
function poll() {
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/updates',
|
||||||
|
type: 'GET',
|
||||||
|
data: { since: lastVersion || 0 },
|
||||||
|
timeout: 30000,
|
||||||
|
success: function (resp) {
|
||||||
|
if (resp && typeof resp.version === 'number') {
|
||||||
|
if (lastVersion === null) {
|
||||||
|
lastVersion = resp.version; // 1ère synchro: on se cale
|
||||||
|
} else if (resp.version > lastVersion) {
|
||||||
|
lastVersion = resp.version;
|
||||||
|
if (typeof loadPage === 'function') loadPage(currentPage || 1);
|
||||||
|
if (typeof updateStatsUI === 'function') {
|
||||||
|
$.getJSON('/autopost/stats', function (s) { if (s) updateStatsUI(s); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTimeout(poll, 100);
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
setTimeout(poll, 2000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(poll);
|
||||||
|
})();
|
||||||
|
|
||||||
|
function updateStatsUI(s) {
|
||||||
|
$('.filter-card[data-status="0"] .tabular-nums').text(s.attente || 0);
|
||||||
|
$('.filter-card[data-status="1"] .tabular-nums').text(s.termine || 0);
|
||||||
|
$('.filter-card[data-status="2"] .tabular-nums').text(s.erreur || 0);
|
||||||
|
$('.filter-card[data-status="3"] .tabular-nums').text(s.deja || 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshAfterChange() {
|
||||||
|
loadPage(currentPage || 1);
|
||||||
|
$.getJSON('/autopost/stats', function(s) { updateStatsUI(s); });
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- DOM bindings ---
|
||||||
|
$(document).ready(function() {
|
||||||
|
// Recherche
|
||||||
|
let searchTimer = null;
|
||||||
|
$('#searchInput').on('keyup', function() {
|
||||||
|
clearTimeout(searchTimer);
|
||||||
|
let q = $(this).val();
|
||||||
|
|
||||||
|
searchTimer = setTimeout(function() {
|
||||||
|
activeQuery = q || '';
|
||||||
|
activeFilter = null; // on sort du mode filtre
|
||||||
|
$('.filter-card').removeClass('ring-4 ring-white/40');
|
||||||
|
loadPage(1); // charge page 1 avec pagination AJAX
|
||||||
|
toggleShowAllButton();
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pagination: intercepter et paginer en AJAX
|
||||||
|
$(document).on('click', '#pagination a[data-page]', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const p = parseInt($(this).data('page'), 10);
|
||||||
|
if (!isNaN(p)) loadPage(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Affichage/masquage du bouton "Tout afficher"
|
||||||
|
function toggleShowAllButton() {
|
||||||
|
if ($('.filter-card.ring-4').length === 0) {
|
||||||
|
$('#showAll').addClass('hidden');
|
||||||
|
} else {
|
||||||
|
$('#showAll').removeClass('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtrage par clic sur une card
|
||||||
|
$(document).on('click', '.filter-card', function() {
|
||||||
|
const status = parseInt($(this).data('status'), 10);
|
||||||
|
|
||||||
|
$('.filter-card').removeClass('ring-4 ring-white/40');
|
||||||
|
$(this).addClass('ring-4 ring-white/40');
|
||||||
|
|
||||||
|
activeFilter = status;
|
||||||
|
activeQuery = ''; // on sort du mode recherche
|
||||||
|
loadPage(1); // page 1 du filtre
|
||||||
|
toggleShowAllButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bouton tout afficher
|
||||||
|
$(document).on('click', '#showAll', function() {
|
||||||
|
$('.filter-card').removeClass('ring-4 ring-white/40');
|
||||||
|
activeFilter = null;
|
||||||
|
activeQuery = $('#searchInput').val() || '';
|
||||||
|
loadPage(1);
|
||||||
|
toggleShowAllButton();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edition (ouvrir modale)
|
||||||
|
$(document).on('click', '.edit-link', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var releaseId = $(this).data('id');
|
||||||
|
var currentStatus = $(this).data('status');
|
||||||
|
$('#releaseId').val(releaseId);
|
||||||
|
$('#modalReleaseId').text(releaseId);
|
||||||
|
$('#statusSelect').val(currentStatus);
|
||||||
|
$('#editModal').removeClass('hidden').fadeIn();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------- Confirmation de suppression (modale) ----------
|
||||||
|
var pendingDeleteId = null;
|
||||||
|
|
||||||
|
function openConfirmModal(id, name) {
|
||||||
|
pendingDeleteId = id;
|
||||||
|
$('#confirmItemName').text(name || ('ID ' + id));
|
||||||
|
$('#confirmDeleteModal').removeClass('hidden').fadeIn(120);
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeConfirmModal() {
|
||||||
|
$('#confirmDeleteModal').fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
pendingDeleteId = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonctions pour la modal de renvoi
|
||||||
|
var pendingResendId = null;
|
||||||
|
var pendingResendFilename = null;
|
||||||
|
|
||||||
|
function openConfirmResendModal(id, filename) {
|
||||||
|
pendingResendId = id;
|
||||||
|
pendingResendFilename = filename;
|
||||||
|
$('#confirmResendItemName').text(filename || ('ID ' + id));
|
||||||
|
$('#confirmResendModal').removeClass('hidden').fadeIn(120);
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeConfirmResendModal() {
|
||||||
|
$('#confirmResendModal').fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
pendingResendId = null;
|
||||||
|
pendingResendFilename = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showToast(msg) {
|
||||||
|
$('#toastMsg').text(msg || 'Opération effectuée');
|
||||||
|
$('#toast').removeClass('hidden').fadeIn(120);
|
||||||
|
setTimeout(function() {
|
||||||
|
$('#toast').fadeOut(150, function() { $(this).addClass('hidden'); });
|
||||||
|
}, 1800);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ouvrir la modale au clic sur "Supprimer"
|
||||||
|
$(document).on('click', '.delete-link', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var releaseId = $(this).data('id');
|
||||||
|
var name = $(this).closest('tr').find('td:first').text().trim();
|
||||||
|
openConfirmModal(releaseId, name);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Boutons de la modale
|
||||||
|
$('#cancelDeleteBtn, #confirmDeleteClose').on('click', function() {
|
||||||
|
closeConfirmModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clic sur l'overlay pour fermer
|
||||||
|
$('#confirmDeleteModal').on('click', function(e) {
|
||||||
|
if (e.target === this) { closeConfirmModal(); }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Gestionnaires pour la modal de renvoi
|
||||||
|
$('#cancelResendBtn, #confirmResendClose').on('click', function() {
|
||||||
|
closeConfirmResendModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clic sur l'overlay pour fermer la modal de renvoi
|
||||||
|
$('#confirmResendModal').on('click', function(e) {
|
||||||
|
if (e.target === this) { closeConfirmResendModal(); }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Accessibilité clavier: Esc = fermer, Enter = confirmer
|
||||||
|
$(document).on('keydown', function(e) {
|
||||||
|
var deleteModalVisible = !$('#confirmDeleteModal').hasClass('hidden');
|
||||||
|
var resendModalVisible = !$('#confirmResendModal').hasClass('hidden');
|
||||||
|
|
||||||
|
if (deleteModalVisible) {
|
||||||
|
if (e.key === 'Escape') { closeConfirmModal(); }
|
||||||
|
if (e.key === 'Enter') { $('#confirmDeleteBtn').click(); }
|
||||||
|
} else if (resendModalVisible) {
|
||||||
|
if (e.key === 'Escape') { closeConfirmResendModal(); }
|
||||||
|
if (e.key === 'Enter') { $('#confirmResendBtn').click(); }
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Confirmer et supprimer via AJAX
|
||||||
|
$('#confirmDeleteBtn').on('click', function() {
|
||||||
|
if (!pendingDeleteId) return;
|
||||||
|
var releaseId = pendingDeleteId;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/delete/' + releaseId,
|
||||||
|
type: 'POST',
|
||||||
|
success: function() {
|
||||||
|
$('#row-' + releaseId)
|
||||||
|
.css('outline', '2px solid rgba(239,68,68,0.6)')
|
||||||
|
.fadeOut('300', function(){ $(this).remove(); });
|
||||||
|
showToast('Enregistrement supprimé');
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Erreur lors de la suppression.');
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
closeConfirmModal();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Confirmer et renvoyer via AJAX
|
||||||
|
$('#confirmResendBtn').on('click', function() {
|
||||||
|
if (!pendingResendId) return;
|
||||||
|
var releaseId = pendingResendId;
|
||||||
|
var filename = pendingResendFilename;
|
||||||
|
|
||||||
|
var $button = $(this);
|
||||||
|
var originalText = $button.text();
|
||||||
|
$button.text('Envoi...');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/resend/' + releaseId,
|
||||||
|
type: 'POST',
|
||||||
|
success: function(data) {
|
||||||
|
showToast(data.message || 'Renvoi effectué avec succès');
|
||||||
|
console.log('Renvoi réussi pour', filename);
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
var errorMsg = 'Erreur lors du renvoi';
|
||||||
|
if (xhr.responseJSON && xhr.responseJSON.error) {
|
||||||
|
errorMsg = xhr.responseJSON.error;
|
||||||
|
}
|
||||||
|
alert(errorMsg);
|
||||||
|
console.error('Erreur renvoi:', xhr.responseJSON);
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$button.text(originalText);
|
||||||
|
closeConfirmResendModal();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Affichage log
|
||||||
|
$(document).on('click', '.log-link', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var filename = $(this).data('filename');
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/log',
|
||||||
|
type: 'GET',
|
||||||
|
data: { name: filename },
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
$('#logContent').html(data.content);
|
||||||
|
$('#logModal').removeClass('hidden').fadeIn();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Erreur lors du chargement du fichier log.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Affichage mediainfo
|
||||||
|
$(document).on('click', '.mediainfo-link', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var filename = $(this).data('filename');
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/mediainfo',
|
||||||
|
type: 'GET',
|
||||||
|
data: { name: filename },
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
$('#mediainfoContent').text(data.content);
|
||||||
|
$('#mediainfoModal').removeClass('hidden').fadeIn();
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Erreur lors du chargement du fichier mediainfo.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fermeture modales (croix + clic overlay)
|
||||||
|
$('.close').click(function() {
|
||||||
|
$(this).closest('.fixed').fadeOut(function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.fixed').click(function(e) {
|
||||||
|
if (e.target === this) {
|
||||||
|
$(this).fadeOut(function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Edition: submit
|
||||||
|
$('#editForm').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var releaseId = $('#releaseId').val();
|
||||||
|
var newStatus = $('#statusSelect').val();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/edit/' + releaseId,
|
||||||
|
type: 'POST',
|
||||||
|
data: { status: newStatus },
|
||||||
|
success: function() {
|
||||||
|
var statusText = '';
|
||||||
|
var statusClass = '';
|
||||||
|
switch (parseInt(newStatus)) {
|
||||||
|
case 0: statusText = 'EN ATTENTE'; statusClass = 'bg-cyan-500 text-black font-bold'; break;
|
||||||
|
case 1: statusText = 'ENVOI TERMINÉ'; statusClass = 'bg-green-300 text-black font-bold'; break;
|
||||||
|
case 2: statusText = 'ERREUR'; statusClass = 'bg-red-300 text-black font-bold'; break;
|
||||||
|
case 3: statusText = 'DEJA DISPONIBLE';statusClass = 'bg-pink-300 text-black font-bold'; break;
|
||||||
|
case 4: statusText = 'EN COURS'; statusClass = 'bg-yellow-300 text-black font-bold'; break;
|
||||||
|
default: statusText = 'INCONNU';
|
||||||
|
}
|
||||||
|
|
||||||
|
var row = $('#row-' + releaseId);
|
||||||
|
row.find('.status-text')
|
||||||
|
.removeClass('bg-cyan-500 bg-green-300 bg-red-300 bg-pink-300 bg-yellow-300')
|
||||||
|
.addClass(statusClass)
|
||||||
|
.text(statusText);
|
||||||
|
|
||||||
|
$('#editModal').fadeOut(function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
alert('Erreur lors de la mise à jour.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bouton copier Mediainfo
|
||||||
|
$('#copyMediainfoBtn').on('click', function() {
|
||||||
|
const content = document.getElementById('mediainfoContent').textContent;
|
||||||
|
navigator.clipboard.writeText(content).then(() => {
|
||||||
|
this.textContent = '✅ Copié !';
|
||||||
|
setTimeout(() => this.textContent = '📋 Copier JSON', 2000);
|
||||||
|
}).catch(function(err) {
|
||||||
|
alert('Erreur lors de la copie : ' + err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Renvoi vers le site principal
|
||||||
|
$(document).on('click', '.resend-link', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var releaseId = $(this).data('id');
|
||||||
|
var filename = $(this).data('filename');
|
||||||
|
openConfirmResendModal(releaseId, filename);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ==================== GESTION SÉLECTION MULTIPLE ====================
|
||||||
|
|
||||||
|
function updateBulkActions() {
|
||||||
|
const selectedCheckboxes = $('.row-checkbox:checked');
|
||||||
|
const count = selectedCheckboxes.length;
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
$('#bulkActions').removeClass('hidden');
|
||||||
|
$('#selectedCount').text(count + ' élément' + (count > 1 ? 's' : '') + ' sélectionné' + (count > 1 ? 's' : ''));
|
||||||
|
} else {
|
||||||
|
$('#bulkActions').addClass('hidden');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mettre à jour la checkbox "Tout sélectionner"
|
||||||
|
const totalCheckboxes = $('.row-checkbox').length;
|
||||||
|
const allChecked = count === totalCheckboxes && totalCheckboxes > 0;
|
||||||
|
const someChecked = count > 0 && count < totalCheckboxes;
|
||||||
|
|
||||||
|
$('#selectAll').prop('checked', allChecked);
|
||||||
|
$('#selectAll').prop('indeterminate', someChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checkbox "Tout sélectionner"
|
||||||
|
$(document).on('click', '#selectAll', function() {
|
||||||
|
const isChecked = $(this).is(':checked');
|
||||||
|
$('.row-checkbox').prop('checked', isChecked);
|
||||||
|
updateBulkActions();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Checkboxes individuelles
|
||||||
|
$(document).on('click', '.row-checkbox', function() {
|
||||||
|
updateBulkActions();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bouton "Éditer la sélection"
|
||||||
|
$(document).on('click', '#bulkEditBtn', function() {
|
||||||
|
const selectedCheckboxes = $('.row-checkbox:checked');
|
||||||
|
const count = selectedCheckboxes.length;
|
||||||
|
|
||||||
|
if (count === 0) return;
|
||||||
|
|
||||||
|
$('#bulkEditCount').text(count);
|
||||||
|
$('#bulkEditModal').removeClass('hidden').fadeIn(120);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bouton "Supprimer la sélection"
|
||||||
|
$(document).on('click', '#bulkDeleteBtn', function() {
|
||||||
|
const selectedCheckboxes = $('.row-checkbox:checked');
|
||||||
|
const count = selectedCheckboxes.length;
|
||||||
|
|
||||||
|
if (count === 0) return;
|
||||||
|
|
||||||
|
// Construire la liste des éléments à supprimer
|
||||||
|
let listHTML = '';
|
||||||
|
selectedCheckboxes.each(function() {
|
||||||
|
const name = $(this).data('name');
|
||||||
|
const id = $(this).data('id');
|
||||||
|
listHTML += `<div class="text-sm text-gray-300 mb-1">• ${name} (ID: ${id})</div>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#bulkDeleteCount').text(count);
|
||||||
|
$('#bulkDeleteList').html(listHTML);
|
||||||
|
$('#bulkDeleteModal').removeClass('hidden').fadeIn(120);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fermeture des modals en lot
|
||||||
|
$('#bulkEditClose, #bulkDeleteClose, #cancelBulkDeleteBtn').on('click', function() {
|
||||||
|
$('#bulkEditModal, #bulkDeleteModal').fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Clic sur l'overlay pour fermer les modals en lot
|
||||||
|
$('#bulkEditModal, #bulkDeleteModal').on('click', function(e) {
|
||||||
|
if (e.target === this) {
|
||||||
|
$(this).fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Soumission du formulaire d'édition en lot
|
||||||
|
$('#bulkEditForm').on('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const selectedCheckboxes = $('.row-checkbox:checked');
|
||||||
|
const newStatus = $('#bulkStatusSelect').val();
|
||||||
|
const ids = [];
|
||||||
|
|
||||||
|
selectedCheckboxes.each(function() {
|
||||||
|
ids.push($(this).data('id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ids.length === 0) return;
|
||||||
|
|
||||||
|
const $submitBtn = $('#bulkEditForm button[type="submit"]');
|
||||||
|
const originalText = $submitBtn.text();
|
||||||
|
$submitBtn.text('Mise à jour...').prop('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/bulk-edit',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
ids: ids,
|
||||||
|
status: newStatus,
|
||||||
|
_csrf: window.__BOOTSTRAP__.csrf
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
// Mettre à jour l'interface pour chaque ligne modifiée
|
||||||
|
ids.forEach(function(id) {
|
||||||
|
updateRowStatus(id, newStatus);
|
||||||
|
});
|
||||||
|
|
||||||
|
showToast(`${ids.length} élément(s) mis à jour`);
|
||||||
|
|
||||||
|
// Fermer la modal et désélectionner
|
||||||
|
$('#bulkEditModal').fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
$('.row-checkbox').prop('checked', false);
|
||||||
|
updateBulkActions();
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
let errorMsg = 'Erreur lors de la mise à jour en lot';
|
||||||
|
if (xhr.responseJSON && xhr.responseJSON.error) {
|
||||||
|
errorMsg = xhr.responseJSON.error;
|
||||||
|
}
|
||||||
|
alert(errorMsg);
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$submitBtn.text(originalText).prop('disabled', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Confirmation de suppression en lot
|
||||||
|
$('#confirmBulkDeleteBtn').on('click', function() {
|
||||||
|
const selectedCheckboxes = $('.row-checkbox:checked');
|
||||||
|
const ids = [];
|
||||||
|
|
||||||
|
selectedCheckboxes.each(function() {
|
||||||
|
ids.push($(this).data('id'));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ids.length === 0) return;
|
||||||
|
|
||||||
|
const $button = $(this);
|
||||||
|
const originalText = $button.text();
|
||||||
|
$button.text('Suppression...').prop('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '/autopost/bulk-delete',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
ids: ids,
|
||||||
|
_csrf: window.__BOOTSTRAP__.csrf
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
showToast(`${ids.length} élément(s) supprimé(s)`);
|
||||||
|
|
||||||
|
// Fermer la modal
|
||||||
|
$('#bulkDeleteModal').fadeOut(120, function() {
|
||||||
|
$(this).addClass('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Décocher toutes les checkboxes AVANT de recharger
|
||||||
|
$('.row-checkbox').prop('checked', false);
|
||||||
|
$('#selectAll').prop('checked', false).prop('indeterminate', false);
|
||||||
|
$('#bulkActions').addClass('hidden');
|
||||||
|
|
||||||
|
// Recharger les données de la page courante
|
||||||
|
loadPage(currentPage || 1);
|
||||||
|
|
||||||
|
// Mettre à jour les statistiques
|
||||||
|
$.getJSON('/autopost/stats', function(s) {
|
||||||
|
if (s) updateStatsUI(s);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error: function(xhr) {
|
||||||
|
let errorMsg = 'Erreur lors de la suppression en lot';
|
||||||
|
if (xhr.responseJSON && xhr.responseJSON.error) {
|
||||||
|
errorMsg = xhr.responseJSON.error;
|
||||||
|
}
|
||||||
|
alert(errorMsg);
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
$button.text(originalText).prop('disabled', false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fonction utilitaire pour mettre à jour le statut d'une ligne
|
||||||
|
function updateRowStatus(id, newStatus) {
|
||||||
|
const $row = $('#row-' + id);
|
||||||
|
const $statusCell = $row.find('.status-text');
|
||||||
|
|
||||||
|
let statusText = '';
|
||||||
|
let statusClass = '';
|
||||||
|
switch (parseInt(newStatus)) {
|
||||||
|
case 0: statusText = 'EN ATTENTE'; statusClass = 'bg-cyan-500 text-black font-bold'; break;
|
||||||
|
case 1: statusText = 'ENVOI TERMINÉ'; statusClass = 'bg-green-300 text-black font-bold'; break;
|
||||||
|
case 2: statusText = 'ERREUR'; statusClass = 'bg-red-300 text-black font-bold'; break;
|
||||||
|
case 3: statusText = 'DEJA DISPONIBLE'; statusClass = 'bg-pink-300 text-black font-bold'; break;
|
||||||
|
case 4: statusText = 'EN COURS'; statusClass = 'bg-yellow-300 text-black font-bold'; break;
|
||||||
|
default: statusText = 'INCONNU';
|
||||||
|
}
|
||||||
|
|
||||||
|
$statusCell.removeClass().addClass('px-4 py-2 border border-gray-700 status-text whitespace-nowrap ' + statusClass);
|
||||||
|
$statusCell.text(statusText);
|
||||||
|
$row.attr('data-status', newStatus);
|
||||||
|
}
|
||||||
|
});
|
||||||
141
autopost/public/checkboxes.css
Normal file
141
autopost/public/checkboxes.css
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
/* Checkboxes personnalisées modernes */
|
||||||
|
|
||||||
|
/* Style de base pour toutes les checkboxes */
|
||||||
|
.checkbox-custom {
|
||||||
|
appearance: none;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
border: 2px solid #4b5563;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: #1f2937;
|
||||||
|
position: relative;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
|
outline: none;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* État hover */
|
||||||
|
.checkbox-custom:hover {
|
||||||
|
border-color: #6b7280;
|
||||||
|
background: #374151;
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* État focus */
|
||||||
|
.checkbox-custom:focus {
|
||||||
|
border-color: #3b82f6;
|
||||||
|
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* État checked */
|
||||||
|
.checkbox-custom:checked {
|
||||||
|
background: linear-gradient(135deg, #3b82f6, #1d4ed8);
|
||||||
|
border-color: #3b82f6;
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Icône de validation */
|
||||||
|
.checkbox-custom:checked::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
width: 10px;
|
||||||
|
height: 6px;
|
||||||
|
border: 2px solid white;
|
||||||
|
border-top: none;
|
||||||
|
border-right: none;
|
||||||
|
transform: rotate(-45deg);
|
||||||
|
top: 3px;
|
||||||
|
left: 3px;
|
||||||
|
animation: checkmark 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation de la coche */
|
||||||
|
@keyframes checkmark {
|
||||||
|
0% {
|
||||||
|
transform: rotate(-45deg) scale(0);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: rotate(-45deg) scale(1.2);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(-45deg) scale(1);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* État indéterminé pour "Tout sélectionner" */
|
||||||
|
.checkbox-custom:indeterminate {
|
||||||
|
background: linear-gradient(135deg, #f59e0b, #d97706);
|
||||||
|
border-color: #f59e0b;
|
||||||
|
transform: scale(1.05);
|
||||||
|
box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-custom:indeterminate::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
width: 8px;
|
||||||
|
height: 2px;
|
||||||
|
background: white;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
border-radius: 1px;
|
||||||
|
animation: indeterminate 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation de l'état indéterminé */
|
||||||
|
@keyframes indeterminate {
|
||||||
|
0% {
|
||||||
|
width: 0;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
width: 8px;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Effet de selection pour les lignes avec checkbox cochée */
|
||||||
|
tr:has(.checkbox-custom:checked) {
|
||||||
|
background-color: rgba(59, 130, 246, 0.05) !important;
|
||||||
|
border-left: 3px solid #3b82f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animation d'apparition lors du chargement */
|
||||||
|
.checkbox-custom {
|
||||||
|
animation: fadeIn 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.8);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Amélioration pour les écrans tactiles */
|
||||||
|
@media (hover: none) {
|
||||||
|
.checkbox-custom:hover {
|
||||||
|
transform: none;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox-custom:active {
|
||||||
|
transform: scale(0.95);
|
||||||
|
}
|
||||||
|
}
|
||||||
1275
autopost/server.js
1275
autopost/server.js
File diff suppressed because it is too large
Load Diff
269
autopost/views/autopost.html
Normal file
269
autopost/views/autopost.html
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>{{TITLE}}</title>
|
||||||
|
<meta name="csrf-token" content="{{CSRF_TOKEN}}">
|
||||||
|
<link rel="icon" href="/autopost/favicon.ico" type="image/svg+xml">
|
||||||
|
<link rel="stylesheet" href="checkboxes.css" type="text/css">
|
||||||
|
<script src="js/index.global.js" type="application/javascript"></script>
|
||||||
|
<script src="jquery/jquery.min.js" type="application/javascript"></script>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body class="bg-{{BACKGROUND_CLASS}} text-white font-sans p-4">
|
||||||
|
<div class="w-full px-4">
|
||||||
|
<!-- Header -->
|
||||||
|
<div class="mb-6">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<h1 class="text-2xl md:text-3xl font-extrabold tracking-tight bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-cyan-300">
|
||||||
|
Suivi Autopost {{APP_NAME}}
|
||||||
|
</h1>
|
||||||
|
<a href="/autopost/logout"
|
||||||
|
class="inline-flex items-center gap-2 px-3 py-2 rounded-xl bg-red-600/90 hover:bg-red-600 text-white shadow-lg shadow-red-900/20 transition">
|
||||||
|
<svg class="w-4 h-4" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a2 2 0 01-2 2H6a2 2 0 01-2-2V7a2 2 0 012-2h5a2 2 0 012 2v1"/>
|
||||||
|
</svg>
|
||||||
|
Déconnexion
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-sm text-gray-400">Vue d’ensemble des traitements en cours et de l’état des envois.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Stat cards -->
|
||||||
|
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||||
|
<!-- En attente -->
|
||||||
|
<div class="group rounded-2xl p-3 md:p-5 bg-gradient-to-br from-cyan-500 to-cyan-400 text-black shadow-xl ring-1 ring-white/10 transition transform hover:-translate-y-0.5 hover:shadow-2xl cursor-pointer filter-card" data-status="0">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="rounded-xl bg-black/10 p-2">
|
||||||
|
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 6v6l4 2"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="text-sm/5 font-medium">En attente</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 text-3xl font-extrabold tabular-nums">{{STAT_ATTENTE}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Terminé -->
|
||||||
|
<div class="group rounded-2xl p-4 md:p-5 bg-gradient-to-br from-green-300 to-emerald-300 text-black shadow-xl ring-1 ring-white/10 transition transform hover:-translate-y-0.5 hover:shadow-2xl cursor-pointer filter-card" data-status="1">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="rounded-xl bg-black/10 p-2">
|
||||||
|
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M5 13l4 4L19 7"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="text-sm/5 font-medium">Terminé</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 text-3xl font-extrabold tabular-nums">{{STAT_TERMINE}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Erreur -->
|
||||||
|
<div class="group rounded-2xl p-4 md:p-5 bg-gradient-to-br from-rose-300 to-red-300 text-black shadow-xl ring-1 ring-white/10 transition transform hover:-translate-y-0.5 hover:shadow-2xl cursor-pointer filter-card" data-status="2">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="rounded-xl bg-black/10 p-2">
|
||||||
|
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M12 9v3m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="text-sm/5 font-medium">Erreur</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 text-3xl font-extrabold tabular-nums">{{STAT_ERREUR}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Déjà dispo -->
|
||||||
|
<div class="group rounded-2xl p-4 md:p-5 bg-gradient-to-br from-pink-300 to-fuchsia-300 text-black shadow-xl ring-1 ring-white/10 transition transform hover:-translate-y-0.5 hover:shadow-2xl cursor-pointer filter-card" data-status="3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div class="rounded-xl bg-black/10 p-2">
|
||||||
|
<svg class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M8 7h8M8 11h8M8 15h6"/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="text-sm/5 font-medium">Déjà dispo</div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 text-3xl font-extrabold tabular-nums">{{STAT_DEJA}}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bouton réinitialiser -->
|
||||||
|
<div class="mb-4 text-center">
|
||||||
|
<button id="showAll"
|
||||||
|
class="hidden px-5 py-2 rounded-xl bg-gradient-to-br from-gray-600 to-gray-800 text-white font-semibold shadow-lg hover:from-gray-500 hover:to-gray-700 transition transform hover:-translate-y-0.5">
|
||||||
|
Tout afficher
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Search -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<label for="searchInput" class="sr-only">Rechercher</label>
|
||||||
|
<div class="relative">
|
||||||
|
<span class="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
|
||||||
|
<svg class="w-5 h-5 text-gray-400" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
||||||
|
d="M21 21l-4.35-4.35M10 18a8 8 0 1 1 0-16 8 8 0 0 1 0 16z"/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
<input id="searchInput" type="text" placeholder="Rechercher…"
|
||||||
|
class="w-full pl-10 pr-3 py-2 rounded-xl bg-gray-800/80 border border-gray-700 focus:border-blue-500 focus:ring-4 focus:ring-blue-500/20 outline-none transition placeholder:text-gray-400" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<nav id="pagination" aria-label="Page navigation" class="mb-4">
|
||||||
|
{{PAGINATION_HTML}}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<!-- Boutons d'actions en lot -->
|
||||||
|
<div id="bulkActions" class="hidden mb-4 p-4 bg-gray-800 rounded-lg border border-gray-600">
|
||||||
|
<div class="flex items-center justify-between flex-wrap gap-3">
|
||||||
|
<span id="selectedCount" class="text-gray-300 font-medium">0 élément sélectionné</span>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<button id="bulkEditBtn" class="px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-semibold transition">
|
||||||
|
✏️ Éditer la sélection
|
||||||
|
</button>
|
||||||
|
<button id="bulkDeleteBtn" class="px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg font-semibold transition">
|
||||||
|
🗑️ Supprimer la sélection
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="min-w-full border border-gray-700 shadow-lg rounded-lg overflow-hidden">
|
||||||
|
<thead class="bg-gray-900 text-gray-300 uppercase text-sm">
|
||||||
|
<tr>
|
||||||
|
<th class="px-4 py-2">
|
||||||
|
<input type="checkbox" id="selectAll" class="checkbox-custom">
|
||||||
|
</th>
|
||||||
|
<th class="px-4 py-2">Name</th>
|
||||||
|
<th class="px-4 py-2">Status</th>
|
||||||
|
<th class="px-4 py-2">ID</th>
|
||||||
|
<th class="px-4 py-2">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-700">
|
||||||
|
{{TABLE_ROWS}}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modales + Toast (inchangés) -->
|
||||||
|
<!-- Modale d'édition -->
|
||||||
|
<div id="editModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-md transform transition-all scale-95">
|
||||||
|
<button type="button" class="absolute top-4 right-4 text-gray-400 hover:text-white text-2xl font-bold close">×</button>
|
||||||
|
<h2 class="text-2xl font-bold mb-6 text-center text-white">✏️ Éditer Release <span id="modalReleaseId" class="text-blue-400"></span></h2>
|
||||||
|
<form id="editForm">
|
||||||
|
<label for="statusSelect" class="block mb-2 text-gray-300 font-medium">Status :</label>
|
||||||
|
<select id="statusSelect" name="status"
|
||||||
|
class="w-full p-3 mb-6 rounded-lg border border-gray-700 bg-gray-800 text-white focus:ring-2 focus:ring-blue-500 focus:outline-none">
|
||||||
|
<option value="0" class="text-cyan-400">EN ATTENTE</option>
|
||||||
|
<option value="1" class="text-green-400">ENVOI TERMINÉ</option>
|
||||||
|
<option value="2" class="text-red-400">ERREUR</option>
|
||||||
|
<option value="3" class="text-pink-400">DEJA DISPONIBLE</option>
|
||||||
|
<option value="4" class="text-yellow-400">EN COURS</option>
|
||||||
|
</select>
|
||||||
|
<input type="hidden" id="releaseId" name="id" value=""/>
|
||||||
|
<button type="submit" class="w-full p-3 bg-gradient-to-r from-blue-600 to-blue-500 text-white font-semibold rounded-lg shadow hover:from-blue-500 hover:to-blue-400 transform hover:-translate-y-0.5 transition">💾 Mettre à jour</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale log -->
|
||||||
|
<div id="logModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-7xl relative">
|
||||||
|
<button type="button" class="absolute top-4 right-4 text-gray-400 hover:text-white text-2xl font-bold close log-close">×</button>
|
||||||
|
<h2 class="text-2xl font-bold mb-6 text-center text-white">📄 Contenu du log</h2>
|
||||||
|
<pre id="logContent" class="max-h-[90vh] overflow-y-auto p-6 rounded-lg bg-gray-800 text-green-400 font-mono text-sm leading-relaxed border border-gray-700 shadow-inner whitespace-pre-wrap"></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale mediainfo -->
|
||||||
|
<div id="mediainfoModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-6xl relative">
|
||||||
|
<button type="button" class="absolute top-4 right-4 text-gray-400 hover:text-white text-2xl font-bold close mediainfo-close" title="Fermer">×</button>
|
||||||
|
<h2 class="text-2xl font-bold text-white mb-4 pr-16">📄 Contenu du mediainfo</h2>
|
||||||
|
<div class="mb-6">
|
||||||
|
<button id="copyMediainfoBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg text-sm font-semibold shadow-md transition">📋 Copier JSON</button>
|
||||||
|
</div>
|
||||||
|
<pre id="mediainfoContent" class="max-h-[80vh] overflow-y-auto p-4 rounded-lg bg-gray-800 text-yellow-300 font-mono text-sm leading-relaxed border border-gray-700 shadow-inner whitespace-pre-wrap"></pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modale confirmation suppression -->
|
||||||
|
<div id="confirmDeleteModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-3xl md:max-w-4xl relative">
|
||||||
|
<button type="button" class="absolute top-3 right-3 text-gray-400 hover:text-white text-xl font-bold" id="confirmDeleteClose" aria-label="Fermer">×</button>
|
||||||
|
<h3 class="text-xl font-bold text-white mb-2">Supprimer cet enregistrement ?</h3>
|
||||||
|
<p class="text-gray-300 text-sm mb-6">Vous êtes sur le point de supprimer <span id="confirmItemName" class="text-white font-semibold"></span>. Cette action est irréversible.</p>
|
||||||
|
<div class="flex justify-end gap-3">
|
||||||
|
<button type="button" id="cancelDeleteBtn" class="px-4 py-2 rounded-lg bg-gray-700 hover:bg-gray-600 text-white">Annuler</button>
|
||||||
|
<button type="button" id="confirmDeleteBtn" class="px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-white font-semibold">Supprimer</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation de renvoi -->
|
||||||
|
<div id="confirmResendModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-3xl md:max-w-4xl relative">
|
||||||
|
<button type="button" class="absolute top-3 right-3 text-gray-400 hover:text-white text-xl font-bold" id="confirmResendClose" aria-label="Fermer">×</button>
|
||||||
|
<h3 class="text-xl font-bold text-white mb-2">Renvoyer cet enregistrement ?</h3>
|
||||||
|
<p class="text-gray-300 text-sm mb-6">Vous êtes sur le point de renvoyer <span id="confirmResendItemName" class="text-white font-semibold"></span> vers le site principal.</p>
|
||||||
|
<div class="flex justify-end gap-3">
|
||||||
|
<button type="button" id="cancelResendBtn" class="px-4 py-2 rounded-lg bg-gray-700 hover:bg-gray-600 text-white">Annuler</button>
|
||||||
|
<button type="button" id="confirmResendBtn" class="px-4 py-2 rounded-lg bg-green-600 hover:bg-green-700 text-white font-semibold">Renvoyer</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal d'édition en lot -->
|
||||||
|
<div id="bulkEditModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-md relative">
|
||||||
|
<button type="button" class="absolute top-4 right-4 text-gray-400 hover:text-white text-2xl font-bold" id="bulkEditClose">×</button>
|
||||||
|
<h2 class="text-2xl font-bold mb-6 text-center text-white">✏️ Éditer la sélection</h2>
|
||||||
|
<p class="text-gray-300 text-sm mb-4">Modifier le statut de <span id="bulkEditCount" class="text-white font-semibold">0</span> élément(s) sélectionné(s).</p>
|
||||||
|
<form id="bulkEditForm">
|
||||||
|
<label for="bulkStatusSelect" class="block mb-2 text-gray-300 font-medium">Nouveau statut :</label>
|
||||||
|
<select id="bulkStatusSelect" name="status"
|
||||||
|
class="w-full p-3 mb-6 rounded-lg border border-gray-700 bg-gray-800 text-white focus:ring-2 focus:ring-blue-500 focus:outline-none">
|
||||||
|
<option value="0" class="text-cyan-400">EN ATTENTE</option>
|
||||||
|
<option value="1" class="text-green-400">ENVOI TERMINÉ</option>
|
||||||
|
<option value="2" class="text-red-400">ERREUR</option>
|
||||||
|
<option value="3" class="text-pink-400">DEJA DISPONIBLE</option>
|
||||||
|
<option value="4" class="text-yellow-400">EN COURS</option>
|
||||||
|
</select>
|
||||||
|
<button type="submit" class="w-full p-3 bg-gradient-to-r from-blue-600 to-blue-500 text-white font-semibold rounded-lg shadow hover:from-blue-500 hover:to-blue-400 transform hover:-translate-y-0.5 transition">💾 Mettre à jour la sélection</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation de suppression en lot -->
|
||||||
|
<div id="bulkDeleteModal" class="hidden fixed inset-0 bg-black bg-opacity-60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||||
|
<div class="bg-gray-900 p-6 rounded-2xl shadow-2xl w-full max-w-3xl md:max-w-4xl relative">
|
||||||
|
<button type="button" class="absolute top-3 right-3 text-gray-400 hover:text-white text-xl font-bold" id="bulkDeleteClose" aria-label="Fermer">×</button>
|
||||||
|
<h3 class="text-xl font-bold text-white mb-2">Supprimer ces enregistrements ?</h3>
|
||||||
|
<p class="text-gray-300 text-sm mb-4">Vous êtes sur le point de supprimer <span id="bulkDeleteCount" class="text-white font-semibold">0</span> élément(s) sélectionné(s).</p>
|
||||||
|
<div id="bulkDeleteList" class="max-h-40 overflow-y-auto mb-6 p-3 bg-gray-800 rounded-lg border border-gray-700">
|
||||||
|
<!-- Liste des éléments à supprimer -->
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-3">
|
||||||
|
<button type="button" id="cancelBulkDeleteBtn" class="px-4 py-2 rounded-lg bg-gray-700 hover:bg-gray-600 text-white">Annuler</button>
|
||||||
|
<button type="button" id="confirmBulkDeleteBtn" class="px-4 py-2 rounded-lg bg-red-600 hover:bg-red-700 text-white font-semibold">Supprimer tout</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Toast -->
|
||||||
|
<div id="toast" class="hidden fixed bottom-6 left-1/2 -translate-x-1/2 px-4 py-2 rounded-lg bg-gray-900/95 text-white shadow-lg z-[60]">
|
||||||
|
<span id="toastMsg">Supprimé.</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Bootstrap côté client (données initiales) -->
|
||||||
|
<script>window.__BOOTSTRAP__ = {{BOOTSTRAP_JSON}};</script>
|
||||||
|
<script src="autopost.js" defer></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
53
bin/postauto
53
bin/postauto
@@ -5,19 +5,25 @@ source /home/$USER/autopost/common.sh
|
|||||||
# ========== FONCTIONS SCRIPT ==========
|
# ========== FONCTIONS SCRIPT ==========
|
||||||
|
|
||||||
checkdb() {
|
checkdb() {
|
||||||
if [ "$dbtype" = "sqlite" ]; then
|
if [ "$dbtype" = "sqlite" ]; then
|
||||||
if [ ! -f "$DB_FILE" ]; then
|
if [ ! -f "$DB_FILE" ]; then
|
||||||
echo "La base de données n'existe pas. Création..."
|
echo "La base de données SQLite n'existe pas. Création…"
|
||||||
do_createdb
|
do_createdb
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Vérifie si la table existe, sinon crée-la
|
|
||||||
exists=$(db_query "SHOW TABLES LIKE \`$MYSQL_TABLE\`;")
|
|
||||||
if [ -z "$exists" ]; then
|
|
||||||
echo "La table 'release' n'existe pas. Création..."
|
|
||||||
do_createdb
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
# Échapper _ et % pour LIKE
|
||||||
|
local pattern=${MYSQL_TABLE//_/\\_}
|
||||||
|
pattern=${pattern//%/\\%}
|
||||||
|
|
||||||
|
# Assure-toi que db_query utilise `mysql -N -B` pour ne pas avoir d'entêtes
|
||||||
|
local exists
|
||||||
|
exists=$(db_query "SHOW TABLES LIKE '${pattern}';" | tr -d '[:space:]')
|
||||||
|
|
||||||
|
if [ -z "$exists" ]; then
|
||||||
|
echo "La table '${MYSQL_TABLE}' n'existe pas. Création…"
|
||||||
|
do_createdb
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
do_start() {
|
do_start() {
|
||||||
@@ -80,28 +86,32 @@ do_add() {
|
|||||||
|
|
||||||
if [ "$code" = "2" ]; then
|
if [ "$code" = "2" ]; then
|
||||||
echo -e "$ROUGE""$explain""$NORMAL"
|
echo -e "$ROUGE""$explain""$NORMAL"
|
||||||
db_query "INSERT INTO \`release\` (nom, status) VALUES ('${release_name}', 3);"
|
db_query "INSERT INTO \`$MYSQL_TABLE\` (nom, status) VALUES ('${release_name}', 3);"
|
||||||
|
if [ -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
||||||
|
rm "${DOSSIER_GLOBAL}""${release_name}"
|
||||||
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
|
MOVE_CMD="${MOVE_CMD:-cp -rl}"
|
||||||
echo -e "$VERT""DEPLACEMENT DE LA RELEASE ${release_name} DANS LE REPERTOIRE DE TRAVAIL""$NORMAL"
|
echo -e "$VERT""DEPLACEMENT DE LA RELEASE ${release_name} DANS LE REPERTOIRE DE TRAVAIL""$NORMAL"
|
||||||
if [[ "${release_name}" =~ \.(mkv|mp4)$ ]]; then
|
if [[ "${release_name}" =~ \.(mkv|mp4)$ ]]; then
|
||||||
if [ ! -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
if [ ! -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
||||||
cp -rl "${release_path}" "${DOSSIER_GLOBAL}"
|
${MOVE_CMD} "${release_path}" "${DOSSIER_GLOBAL}"
|
||||||
fi
|
fi
|
||||||
echo -e "$ROUGE""CREATION MEDIAINFO""$NORMAL"
|
echo -e "$ROUGE""CREATION MEDIAINFO""$NORMAL"
|
||||||
mediainfo --output=JSON --full "${DOSSIER_GLOBAL}${release_name}" > "${DOSSIER_NFO}${release_without_ext}.json"
|
mediainfo --output=JSON --full "${DOSSIER_GLOBAL}${release_name}" > "${DOSSIER_NFO}${release_without_ext}.json"
|
||||||
echo -e "$CYAN""AJOUT DE LA RELEASE ${release_name} DANS LA DATABASE""$NORMAL"
|
echo -e "$CYAN""AJOUT DE LA RELEASE ${release_name} DANS LA DATABASE""$NORMAL"
|
||||||
db_query "INSERT INTO \`release\` (nom, status) VALUES ('${release_name}', 0);"
|
db_query "INSERT INTO \`$MYSQL_TABLE\` (nom, status) VALUES ('${release_name}', 0);"
|
||||||
elif [[ "${release_name}" =~ \.(iso)$ ]]; then
|
elif [[ "${release_name}" =~ \.(iso)$ ]]; then
|
||||||
if [ ! -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
if [ ! -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
||||||
cp -rl "${release_path}" "${DOSSIER_GLOBAL}"
|
${MOVE_CMD} "${release_path}" "${DOSSIER_GLOBAL}"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
echo -e "$ROUGE""CREATION BDINFO""$NORMAL"
|
echo -e "$ROUGE""CREATION BDINFO""$NORMAL"
|
||||||
BDInfo -p "${DOSSIER_GLOBAL}${release_name}" -o "${DOSSIER_NFO}${release_without_ext}.txt"
|
BDInfo -p "${DOSSIER_GLOBAL}${release_name}" -o "${DOSSIER_NFO}${release_without_ext}.txt"
|
||||||
BDInfoDataSubstractor "${DOSSIER_NFO}${release_without_ext}.txt"
|
BDInfoDataSubstractor "${DOSSIER_NFO}${release_without_ext}.txt"
|
||||||
echo -e "$CYAN""AJOUT DE LA RELEASE ${release_name} DANS LA DATABASE""$NORMAL"
|
echo -e "$CYAN""AJOUT DE LA RELEASE ${release_name} DANS LA DATABASE""$NORMAL"
|
||||||
db_query "INSERT INTO \`release\` (nom, status) VALUES ('${release_name}', 0);"
|
db_query "INSERT INTO \`$MYSQL_TABLE\` (nom, status) VALUES ('${release_name}', 0);"
|
||||||
else
|
else
|
||||||
echo "il ne s'agit pas d'un fichier mkv ou mp4"
|
echo "il ne s'agit pas d'un fichier mkv ou mp4"
|
||||||
fi
|
fi
|
||||||
@@ -110,9 +120,11 @@ do_add() {
|
|||||||
do_check() {
|
do_check() {
|
||||||
release_path="$2"
|
release_path="$2"
|
||||||
release_name=$(basename "$release_path")
|
release_name=$(basename "$release_path")
|
||||||
release_without_ext="${release_name%.*}"
|
if [[ "${release_name}" =~ \.(mkv|mp4|iso)$ ]]; then
|
||||||
|
release_name="${release_name%.*}"
|
||||||
|
fi
|
||||||
|
|
||||||
response=$(curl -s "${URL_API}${APIKEY}&check=${release_without_ext}")
|
response=$(curl -s "${URL_API}${APIKEY}&check=${release_name}")
|
||||||
code=$(echo "$response" | jq -r '.code')
|
code=$(echo "$response" | jq -r '.code')
|
||||||
explain=$(echo "$response" | jq -r '.Explain')
|
explain=$(echo "$response" | jq -r '.Explain')
|
||||||
|
|
||||||
@@ -120,6 +132,9 @@ do_check() {
|
|||||||
echo -e "${release_name}" "$ROUGE""$explain""$NORMAL"
|
echo -e "${release_name}" "$ROUGE""$explain""$NORMAL"
|
||||||
else
|
else
|
||||||
echo -e "${release_name}" "$BLEU""$explain""$NORMAL"
|
echo -e "${release_name}" "$BLEU""$explain""$NORMAL"
|
||||||
|
if [ -e "${DOSSIER_GLOBAL}${release_name}" ]; then
|
||||||
|
rm "${DOSSIER_GLOBAL}""${release_name}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
638
install.sh
638
install.sh
@@ -1,412 +1,396 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Couleurs de texte
|
set -Eeuo pipefail
|
||||||
NOIR='\e[30m'
|
|
||||||
ROUGE='\e[31m'
|
|
||||||
VERT='\e[32m'
|
|
||||||
JAUNE='\e[33m'
|
|
||||||
BLEU='\e[34m'
|
|
||||||
ROSE='\e[35m'
|
|
||||||
CYAN='\e[36m'
|
|
||||||
BLANC='\e[37m'
|
|
||||||
|
|
||||||
# Couleurs de fond
|
# ========= Colors (safe if no TTY) =========
|
||||||
FOND_NOIR='\e[40m'
|
if [ -t 1 ]; then
|
||||||
FOND_ROUGE='\e[41m'
|
NOIR='\e[30m'; ROUGE='\e[31m'; VERT='\e[32m'; JAUNE='\e[33m'; BLEU='\e[34m'; ROSE='\e[35m'; CYAN='\e[36m'; BLANC='\e[37m'
|
||||||
FOND_VERT='\e[42m'
|
GRAS='\e[1m'; SOULIGNE='\e[4m'; NORMAL='\e[0m'
|
||||||
FOND_JAUNE='\e[43m'
|
|
||||||
FOND_BLEU='\e[44m'
|
|
||||||
FOND_ROSE='\e[45m'
|
|
||||||
FOND_CYAN='\e[46m'
|
|
||||||
FOND_BLANC='\e[47m'
|
|
||||||
|
|
||||||
# Effets
|
|
||||||
GRAS='\e[1m'
|
|
||||||
SOULIGNE='\e[4m'
|
|
||||||
CLIGNOTANT='\e[5m'
|
|
||||||
INVERSE='\e[7m'
|
|
||||||
NORMAL='\e[0m'
|
|
||||||
|
|
||||||
|
|
||||||
# Initialisation
|
|
||||||
sudook=false
|
|
||||||
|
|
||||||
if sudo -n true 2>/dev/null; then
|
|
||||||
# On peut faire sudo sans mot de passe
|
|
||||||
sudook=true
|
|
||||||
else
|
else
|
||||||
# Ni root ni sudo dispo
|
NOIR=''; ROUGE=''; VERT=''; JAUNE=''; BLEU=''; ROSE=''; CYAN=''; BLANC=''
|
||||||
sudook=false
|
GRAS=''; SOULIGNE=''; NORMAL=''
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Vérification des prérequis
|
# ========= Paths =========
|
||||||
echo -e "$BLEU""Vérification si les prérequis sont disponibles""$NORMAL"
|
|
||||||
BIN_DIR="$HOME/bin"
|
BIN_DIR="$HOME/bin"
|
||||||
AUTOPOST_DIR="$HOME/autopost"
|
AUTOPOST_DIR="$HOME/autopost"
|
||||||
|
BASHRC_FILE="$HOME/.bashrc"
|
||||||
|
BASH_COMPLETION_DIR="$HOME/.bash_completion.d"
|
||||||
|
TMP_DIR="$(mktemp -d)"
|
||||||
|
cleanup() { rm -rf "$TMP_DIR"; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Vérifier si le dossier bin existe, sinon le créer
|
# ========= Helpers =========
|
||||||
echo -e "$BLEU""Vérification de la présence du dossier bin""$NORMAL"
|
log() { printf "${BLEU}%s${NORMAL}\n" "$*"; }
|
||||||
if [ ! -d "$BIN_DIR" ]; then
|
ok() { printf "${VERT}%s${NORMAL}\n" "$*"; }
|
||||||
mkdir -p "$BIN_DIR"
|
warn() { printf "${JAUNE}%s${NORMAL}\n" "$*"; }
|
||||||
fi
|
err() { printf "${ROUGE}%s${NORMAL}\n" "$*"; }
|
||||||
|
die() { err "$*"; exit 1; }
|
||||||
|
|
||||||
LISTE_APPLIS=()
|
is_root() { [ "${EUID:-$(id -u)}" -eq 0 ]; }
|
||||||
LISTE_APPLIS+=("curl basename php screen")
|
has_cmd() { command -v "$1" >/dev/null 2>&1; }
|
||||||
|
|
||||||
# Vérifier et installer mediainfo si manquant
|
# sudo wrapper: use sudo if available and needed
|
||||||
if command -v mediainfo > /dev/null 2>&1; then
|
run_root() {
|
||||||
LISTE_APPLIS+=("mediainfo")
|
if is_root; then
|
||||||
else
|
"$@"
|
||||||
echo -e "${ROUGE}mediainfo est manquant. Installation en cours...${NORMAL}"
|
elif has_cmd sudo; then
|
||||||
if $sudook; then
|
sudo "$@"
|
||||||
sudo apt install libmms0
|
|
||||||
# URLs dans l’ordre souhaité
|
|
||||||
urls=(
|
|
||||||
"https://mediaarea.net/download/binary/libzen0/0.4.41/libzen0v5_0.4.41-1_amd64.Debian_12.deb"
|
|
||||||
"https://mediaarea.net/download/binary/libmediainfo0/25.04/libmediainfo0v5_25.04-1_amd64.Debian_12.deb"
|
|
||||||
"https://mediaarea.net/download/binary/mediainfo/25.04/mediainfo_25.04-1_amd64.Debian_12.deb"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Télécharger
|
|
||||||
for url in "${urls[@]}"; do
|
|
||||||
wget -q "$url"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Extraire les noms de fichiers, dans le même ordre
|
|
||||||
files=("${urls[@]##*/}")
|
|
||||||
|
|
||||||
# Installer dans l’ordre défini
|
|
||||||
for pkg in "${files[@]}"; do
|
|
||||||
sudo dpkg -i "$pkg"
|
|
||||||
done
|
|
||||||
|
|
||||||
# Nettoyer
|
|
||||||
rm -f "${files[@]}"
|
|
||||||
LISTE_APPLIS+=("mediainfo")
|
|
||||||
echo -e "${VERT}mediainfo installé${NORMAL}"
|
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}mediainfo est manquant. Installation en cours...${NORMAL}"
|
die "Cette action nécessite les privilèges root (sudo non disponible)."
|
||||||
curl -L -o "$BIN_DIR/mediainfo" "https://mediaarea.net/download/binary/mediainfo/20.09/mediainfo-20.09.glibc2.3-x86_64.AppImage"
|
fi
|
||||||
chmod 777 "$BIN_DIR/mediainfo"
|
}
|
||||||
LISTE_APPLIS+=("$BIN_DIR/mediainfo")
|
|
||||||
echo -e "${VERT}mediainfo installé dans $BIN_DIR${NORMAL}"
|
ensure_dir() { mkdir -p "$1"; }
|
||||||
|
|
||||||
|
# safer install than chmod 777
|
||||||
|
install_bin() { # install_bin <src> <dst>
|
||||||
|
install -m 755 "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ========= Downloader (curl→wget fallback) =========
|
||||||
|
download() {
|
||||||
|
local url="$1" out="$2"
|
||||||
|
[ -z "$url" ] || [ -z "$out" ] && { echo "download: usage: download <url> <outfile>" >&2; return 2; }
|
||||||
|
mkdir -p -- "$(dirname -- "$out")"
|
||||||
|
local tmp="${out}.dl.$$"
|
||||||
|
local curl_opts=(--fail --silent --show-error --location --retry 5 --retry-all-errors --retry-delay 2 --connect-timeout 15)
|
||||||
|
local wget_opts=(--quiet --https-only --tries=5 --waitretry=2 --retry-connrefused)
|
||||||
|
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
if curl --http1.1 -4 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if env -u http_proxy -u https_proxy -u all_proxy \
|
||||||
|
curl --http1.1 -4 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if curl --http1.1 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
fi
|
||||||
|
if command -v wget >/dev/null 2>&1; then
|
||||||
|
if wget --inet4-only "${wget_opts[@]}" -O "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if wget "${wget_opts[@]}" -O "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
fi
|
||||||
|
rm -f -- "$tmp" 2>/dev/null || true
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ========= Start =========
|
||||||
|
log "Initialisation des dossiers"
|
||||||
|
ensure_dir "$BIN_DIR"
|
||||||
|
ensure_dir "$AUTOPOST_DIR"
|
||||||
|
ensure_dir "$AUTOPOST_DIR"/public
|
||||||
|
ensure_dir "$AUTOPOST_DIR"/views
|
||||||
|
ensure_dir "$BASH_COMPLETION_DIR"
|
||||||
|
|
||||||
|
# Ensure PATH contains $HOME/bin for this session & future shells
|
||||||
|
if ! printf '%s' "$PATH" | grep -q "$HOME/bin"; then
|
||||||
|
export PATH="$HOME/bin:$PATH"
|
||||||
|
if ! grep -q 'export PATH="$HOME/bin:$PATH"' "$BASHRC_FILE" 2>/dev/null; then
|
||||||
|
echo 'export PATH="$HOME/bin:$PATH"' >> "$BASHRC_FILE"
|
||||||
|
ok "Ajout de \$HOME/bin au PATH dans $BASHRC_FILE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Demande à l'utilisateur
|
# ========= Pre-reqs used by the script itself =========
|
||||||
|
log "Vérification des prérequis (wget, curl, tar, xz, unzip, jq éventuellement)…"
|
||||||
|
MISSING=()
|
||||||
|
for c in wget curl tar xz; do
|
||||||
|
has_cmd "$c" || MISSING+=("$c")
|
||||||
|
done
|
||||||
|
has_cmd unzip || MISSING+=("unzip")
|
||||||
|
if [ "${#MISSING[@]}" -gt 0 ]; then
|
||||||
|
warn "Installation des prérequis manquants: ${MISSING[*]}"
|
||||||
|
if has_cmd apt-get; then
|
||||||
|
run_root apt-get update -y
|
||||||
|
run_root apt-get install -y "${MISSING[@]}"
|
||||||
|
else
|
||||||
|
die "Gestionnaire de paquets non géré (apt-get). Installe manuellement: ${MISSING[*]}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ========= Packages list check (array usage) =========
|
||||||
|
REQUIRED_CMDS=(curl basename screen)
|
||||||
|
|
||||||
|
# ========= mediainfo =========
|
||||||
|
if has_cmd mediainfo; then
|
||||||
|
ok "mediainfo déjà présent"
|
||||||
|
else
|
||||||
|
warn "mediainfo manquant → tentative via apt (puis fallback)"
|
||||||
|
if has_cmd apt-get; then
|
||||||
|
if run_root apt-get install -y mediainfo; then
|
||||||
|
ok "mediainfo installé par apt"
|
||||||
|
else
|
||||||
|
warn "apt mediainfo indisponible, tentative via .deb officiels"
|
||||||
|
DEBS=(
|
||||||
|
"https://mediaarea.net/download/binary/libzen0/0.4.41/libzen0v5_0.4.41-1_amd64.Debian_12.deb"
|
||||||
|
"https://mediaarea.net/download/binary/libmediainfo0/25.04/libmediainfo0v5_25.04-1_amd64.Debian_12.deb"
|
||||||
|
"https://mediaarea.net/download/binary/mediainfo/25.04/mediainfo_25.04-1_amd64.Debian_12.deb"
|
||||||
|
)
|
||||||
|
pushd "$TMP_DIR" >/dev/null
|
||||||
|
for u in "${DEBS[@]}"; do
|
||||||
|
f="$(basename "$u")"
|
||||||
|
download "$u" "$f" || die "Téléchargement échoué: $u"
|
||||||
|
done
|
||||||
|
run_root dpkg -i ./*.deb || run_root apt-get -f -y install
|
||||||
|
popd >/dev/null
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# AppImage fallback
|
||||||
|
APP="$BIN_DIR/mediainfo"
|
||||||
|
download "https://mediaarea.net/download/binary/mediainfo/20.09/mediainfo-20.09.glibc2.3-x86_64.AppImage" "$APP" \
|
||||||
|
|| die "Téléchargement mediainfo AppImage"
|
||||||
|
install -m 755 "$APP" "$APP"
|
||||||
|
ok "mediainfo AppImage installé dans $BIN_DIR"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
REQUIRED_CMDS+=(mediainfo)
|
||||||
|
|
||||||
|
# ========= Choix BDD (SQLite / MySQL) =========
|
||||||
echo "Quel système de base de données voulez-vous utiliser ?"
|
echo "Quel système de base de données voulez-vous utiliser ?"
|
||||||
select BDD in "SQLite" "MySQL"; do
|
select BDD in "SQLite" "MySQL"; do
|
||||||
case $BDD in
|
case $BDD in
|
||||||
"SQLite")
|
"SQLite")
|
||||||
echo "Vous avez choisi SQLite."
|
log "SQLite sélectionné"
|
||||||
# Bloc vérification/install sqlite3
|
if has_cmd sqlite3; then
|
||||||
if command -v sqlite3 > /dev/null 2>&1; then
|
ok "sqlite3 déjà présent"
|
||||||
LISTE_APPLIS+=("sqlite3")
|
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}sqlite3 est manquant. Installation en cours...${NORMAL}"
|
if has_cmd apt-get; then
|
||||||
if $sudook; then
|
run_root apt-get install -y sqlite3
|
||||||
sudo apt install -y sqlite3
|
|
||||||
LISTE_APPLIS+=("sqlite3")
|
|
||||||
echo -e "${VERT}sqlite3 installé${NORMAL}"
|
|
||||||
else
|
else
|
||||||
curl -L -o sqlite-tools.zip "https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip"
|
warn "apt absent → installation binaire sqlite3"
|
||||||
unzip sqlite-tools.zip -d "$BIN_DIR"
|
pushd "$TMP_DIR" >/dev/null
|
||||||
chmod 777 "$BIN_DIR/sqlite3"
|
download "https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip" "$TMP_DIR/sqlite-tools.zip" \
|
||||||
# Nettoyage
|
|| die "Téléchargement sqlite-tools"
|
||||||
rm -rf sqlite-tools.zip "$BIN_DIR/sqlite-tools-linux-x64-3480000" "$BIN_DIR/sqldiff" "$BIN_DIR/sqlite3_analyzer" "$BIN_DIR/sqlite3_rsync"
|
unzip -q "$TMP_DIR/sqlite-tools.zip"
|
||||||
LISTE_APPLIS+=("$BIN_DIR/sqlite3")
|
SQLITE_BIN="$(find . -type f -name sqlite3 -perm -u+x | head -n1)"
|
||||||
echo -e "${VERT}sqlite3 installé dans $BIN_DIR${NORMAL}"
|
[ -n "$SQLITE_BIN" ] || die "sqlite3 introuvable dans l’archive"
|
||||||
|
install_bin "$SQLITE_BIN" "$BIN_DIR/sqlite3"
|
||||||
|
popd >/dev/null
|
||||||
|
ok "sqlite3 installé dans $BIN_DIR"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
REQUIRED_CMDS+=(sqlite3)
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
"MySQL")
|
"MySQL")
|
||||||
echo "Vous avez choisi MySQL."
|
log "MySQL sélectionné"
|
||||||
if command -v mysql > /dev/null 2>&1; then
|
if has_cmd mysql; then
|
||||||
LISTE_APPLIS+=("mysql")
|
ok "mysql client disponible"
|
||||||
echo -e "${VERT}MySQL est disponible${NORMAL}"
|
REQUIRED_CMDS+=(mysql)
|
||||||
# Place ici le code MySQL à exécuter
|
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}MySQL n'est pas installé. Bascule automatique sur SQLite.${NORMAL}"
|
warn "mysql client indisponible → bascule automatique sur SQLite"
|
||||||
# Bloc vérification/install sqlite3 (copié plus haut)
|
if has_cmd apt-get; then
|
||||||
if command -v sqlite3 > /dev/null 2>&1; then
|
run_root apt-get install -y sqlite3
|
||||||
LISTE_APPLIS+=("sqlite3")
|
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}sqlite3 est manquant. Installation en cours...${NORMAL}"
|
pushd "$TMP_DIR" >/dev/null
|
||||||
if $sudook; then
|
download "https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip" "$TMP_DIR/sqlite-tools.zip" \
|
||||||
sudo apt install -y sqlite3
|
|| die "Téléchargement sqlite-tools"
|
||||||
LISTE_APPLIS+=("sqlite3")
|
unzip -q "$TMP_DIR/sqlite-tools.zip"
|
||||||
echo -e "${VERT}sqlite3 installé${NORMAL}"
|
SQLITE_BIN="$(find . -type f -name sqlite3 -perm -u+x | head -n1)"
|
||||||
else
|
[ -n "$SQLITE_BIN" ] || die "sqlite3 introuvable dans l’archive"
|
||||||
curl -L -o sqlite-tools.zip "https://www.sqlite.org/2024/sqlite-tools-linux-x64-3470000.zip"
|
install_bin "$SQLITE_BIN" "$BIN_DIR/sqlite3"
|
||||||
unzip sqlite-tools.zip -d "$BIN_DIR"
|
popd >/dev/null
|
||||||
chmod 777 "$BIN_DIR/sqlite3"
|
|
||||||
rm -rf sqlite-tools.zip "$BIN_DIR/sqlite-tools-linux-x64-3480000" "$BIN_DIR/sqldiff" "$BIN_DIR/sqlite3_analyzer" "$BIN_DIR/sqlite3_rsync"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/sqlite3")
|
|
||||||
echo -e "${VERT}sqlite3 installé dans $BIN_DIR${NORMAL}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
REQUIRED_CMDS+=(sqlite3)
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*) echo "Choix invalide.";;
|
||||||
echo "Choix invalide."
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Vérifier et installer jq si manquant
|
# ========= jq =========
|
||||||
if command -v jq > /dev/null 2>&1; then
|
if has_cmd jq; then
|
||||||
LISTE_APPLIS+=("jq")
|
ok "jq déjà présent"
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}jq est manquant. Installation en cours...${NORMAL}"
|
log "Installation de jq"
|
||||||
curl -L -o "$BIN_DIR/jq" "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64"
|
if has_cmd apt-get; then
|
||||||
chmod 777 "$BIN_DIR/jq"
|
run_root apt-get install -y jq
|
||||||
LISTE_APPLIS+=("$BIN_DIR/jq")
|
else
|
||||||
echo -e "${VERT}jq installé dans $BIN_DIR${NORMAL}"
|
download "https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-amd64" "$TMP_DIR/jq" \
|
||||||
|
|| die "Téléchargement jq"
|
||||||
|
install_bin "$TMP_DIR/jq" "$BIN_DIR/jq"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
REQUIRED_CMDS+=(jq)
|
||||||
|
|
||||||
# Vérifier et installer 7z si manquant
|
# ========= 7z =========
|
||||||
if command -v 7z > /dev/null 2>&1; then
|
if has_cmd 7z; then
|
||||||
LISTE_APPLIS+=("7z")
|
ok "7z déjà présent"
|
||||||
else
|
else
|
||||||
echo -e "${ROUGE}7z est manquant. Installation en cours...${NORMAL}"
|
log "Installation de 7z (binaire standalone)"
|
||||||
|
pushd "$TMP_DIR" >/dev/null
|
||||||
Z_URL="https://7-zip.org/a/7z2409-linux-x64.tar.xz"
|
Z_URL="https://7-zip.org/a/7z2409-linux-x64.tar.xz"
|
||||||
Z_TAR="7z2409-linux-x64.tar.xz"
|
download "$Z_URL" "$TMP_DIR/7z.tar.xz" || die "Téléchargement 7z"
|
||||||
Z_DIR="7z2409-linux-x64"
|
tar -xJf "$TMP_DIR/7z.tar.xz"
|
||||||
Z_EXE="7zzs"
|
Z_BIN="$(find . -maxdepth 1 -type f -name '7zz*' -perm -u+x | head -n1)"
|
||||||
wget -q -O "$Z_TAR" "$Z_URL"
|
[ -n "$Z_BIN" ] || die "binaire 7z introuvable"
|
||||||
tar -xJf "$Z_TAR" > /dev/null 2>&1
|
install_bin "$Z_BIN" "$BIN_DIR/7z"
|
||||||
mv "$Z_EXE" "$BIN_DIR/7z"
|
popd >/dev/null
|
||||||
rm "$Z_TAR" 7zz
|
|
||||||
chmod 777 "$BIN_DIR/7z"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/7z")
|
|
||||||
fi
|
fi
|
||||||
|
REQUIRED_CMDS+=(7z)
|
||||||
|
|
||||||
#Téléchargement et installation de bdinfo
|
# ========= BDInfo & Substractor =========
|
||||||
echo -e "$BLEU""Téléchargement et installation de BDInfo""$NORMAL"
|
log "Installation BDInfo"
|
||||||
curl -L -o bdinfo_linux_v2.0.6.zip "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfo_linux_v2.0.6.zip"
|
pushd "$TMP_DIR" >/dev/null
|
||||||
unzip bdinfo_linux_v2.0.6.zip -d "$BIN_DIR"
|
download "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfo_linux_v2.0.6.zip" "$TMP_DIR/bdinfo.zip" \
|
||||||
chmod 777 "$BIN_DIR/BDInfo"
|
|| die "Téléchargement BDInfo"
|
||||||
curl -L -o bdinfodatasubstractor_linux_v2.0.6.zip "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfodatasubstractor_linux_v2.0.6.zip"
|
unzip -q "$TMP_DIR/bdinfo.zip"
|
||||||
unzip bdinfodatasubstractor_linux_v2.0.6.zip -d "$BIN_DIR"
|
BDINFO_BIN="$(find . -type f -name BDInfo -perm -u+x | head -n1)"
|
||||||
chmod 777 "$BIN_DIR/BDInfoDataSubstractor"
|
[ -n "$BDINFO_BIN" ] || die "BDInfo introuvable"
|
||||||
|
install_bin "$BDINFO_BIN" "$BIN_DIR/BDInfo"
|
||||||
|
|
||||||
|
download "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfodatasubstractor_linux_v2.0.6.zip" "$TMP_DIR/substractor.zip" \
|
||||||
|
|| die "Téléchargement BDInfoDataSubstractor"
|
||||||
|
unzip -q "$TMP_DIR/substractor.zip"
|
||||||
|
SUB_BIN="$(find . -type f -name BDInfoDataSubstractor -perm -u+x | head -n1)"
|
||||||
|
[ -n "$SUB_BIN" ] || die "BDInfoDataSubstractor introuvable"
|
||||||
|
install_bin "$SUB_BIN" "$BIN_DIR/BDInfoDataSubstractor"
|
||||||
|
popd >/dev/null
|
||||||
|
REQUIRED_CMDS+=(BDInfo BDInfoDataSubstractor)
|
||||||
|
|
||||||
# Télécharger et extraire Nyuu
|
# ========= Nyuu =========
|
||||||
echo -e "$BLEU""Téléchargement et installation de nyuu""$NORMAL"
|
log "Installation Nyuu"
|
||||||
|
pushd "$TMP_DIR" >/dev/null
|
||||||
NYUU_URL="https://github.com/Antidote2151/Nyuu-Obfuscation/releases/download/v0.4.2-Obfuscate1.3/nyuu-v0.4.2-Obfuscate1.3-linux-amd64.tar.xz"
|
NYUU_URL="https://github.com/Antidote2151/Nyuu-Obfuscation/releases/download/v0.4.2-Obfuscate1.3/nyuu-v0.4.2-Obfuscate1.3-linux-amd64.tar.xz"
|
||||||
NYUU_TAR="nyuu.tar.xz"
|
download "$NYUU_URL" "$TMP_DIR/nyuu.tar.xz" || die "Téléchargement nyuu"
|
||||||
NYUU_EXE="nyuu"
|
tar -xJf "$TMP_DIR/nyuu.tar.xz"
|
||||||
|
NYUU_BIN="$(find . -type f -name nyuu -perm -u+x | head -n1)"
|
||||||
|
[ -n "$NYUU_BIN" ] || die "nyuu introuvable dans l’archive"
|
||||||
|
install_bin "$NYUU_BIN" "$BIN_DIR/nyuu"
|
||||||
|
popd >/dev/null
|
||||||
|
REQUIRED_CMDS+=(nyuu)
|
||||||
|
|
||||||
wget -q -O "$NYUU_TAR" "$NYUU_URL"
|
# ========= ParPar =========
|
||||||
tar -xJf "$NYUU_TAR" > /dev/null 2>&1
|
log "Installation ParPar"
|
||||||
mv "$NYUU_EXE" "$BIN_DIR/nyuu"
|
pushd "$TMP_DIR" >/dev/null
|
||||||
rm config-sample.json
|
|
||||||
rm "$NYUU_TAR"
|
|
||||||
chmod 777 "$BIN_DIR/nyuu"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/nyuu")
|
|
||||||
|
|
||||||
# Télécharger et extraire ParPar
|
|
||||||
echo -e "$BLEU""Téléchargement et installation de parpar""$NORMAL"
|
|
||||||
PARPAR_URL="https://github.com/animetosho/ParPar/releases/download/v0.4.5/parpar-v0.4.5-linux-static-amd64.xz"
|
PARPAR_URL="https://github.com/animetosho/ParPar/releases/download/v0.4.5/parpar-v0.4.5-linux-static-amd64.xz"
|
||||||
PARPAR_XZ="parpar-v0.4.5-linux-static-amd64.xz"
|
download "$PARPAR_URL" "$TMP_DIR/parpar-v0.4.5-linux-static-amd64.xz" || die "Téléchargement parpar"
|
||||||
|
xz -d "$TMP_DIR/parpar-v0.4.5-linux-static-amd64.xz"
|
||||||
|
PARPAR_BIN="$(find . -maxdepth 1 -type f -name 'parpar-*' | head -n1)"
|
||||||
|
[ -n "$PARPAR_BIN" ] || die "parpar introuvable"
|
||||||
|
install_bin "$PARPAR_BIN" "$BIN_DIR/parpar"
|
||||||
|
popd >/dev/null
|
||||||
|
REQUIRED_CMDS+=(parpar)
|
||||||
|
|
||||||
wget -q -O "$PARPAR_XZ" "$PARPAR_URL"
|
# ========= Téléchargement scripts autopost =========
|
||||||
xz -d "$PARPAR_XZ" > /dev/null 2>&1
|
log "Téléchargement des scripts autopost"
|
||||||
chmod 777 "parpar-v0.4.5-linux-static-amd64"
|
download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh" "$AUTOPOST_DIR/analyzer.sh" || die "analyzer.sh"
|
||||||
mv "parpar-v0.4.5-linux-static-amd64" "$BIN_DIR/parpar"
|
download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh" "$AUTOPOST_DIR/common.sh" || die "common.sh"
|
||||||
LISTE_APPLIS+=("$BIN_DIR/parpar")
|
download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh" "$AUTOPOST_DIR/posteur.sh" || die "posteur.sh"
|
||||||
|
download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto" "$BIN_DIR/postauto" || die "postauto"
|
||||||
|
[ -f "$AUTOPOST_DIR/conf.sh" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/conf.sh" "$AUTOPOST_DIR/conf.sh"
|
||||||
|
|
||||||
# Téléchargement et installation du script de post
|
chmod 755 "$BIN_DIR/postauto"
|
||||||
echo -e "$BLEU""Téléchargement de autopost""$NORMAL"
|
|
||||||
|
|
||||||
# Création des répertoires si inexistants
|
|
||||||
mkdir -p "$AUTOPOST_DIR"
|
|
||||||
|
|
||||||
# Télécharger les fichiers dans autopost
|
|
||||||
wget -q -O "$AUTOPOST_DIR/analyzer.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh"
|
|
||||||
wget -q -O "$AUTOPOST_DIR/common.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh"
|
|
||||||
wget -q -O "$AUTOPOST_DIR/posteur.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh"
|
|
||||||
|
|
||||||
# Télécharger le fichier dans bin
|
|
||||||
wget -q -O "$BIN_DIR/postauto" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto"
|
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/conf.sh" ]; then
|
|
||||||
wget -q -O "$AUTOPOST_DIR/conf.sh" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/conf.sh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Donner les permissions d'exécution si nécessaire
|
|
||||||
chmod 777 "$BIN_DIR/postauto"
|
|
||||||
chmod -R 755 "$AUTOPOST_DIR"
|
chmod -R 755 "$AUTOPOST_DIR"
|
||||||
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/postauto")
|
# ========= Bash completion (fichier dédié) =========
|
||||||
|
COMP_FILE="$BASH_COMPLETION_DIR/postauto"
|
||||||
# Définir le chemin du fichier bashrc
|
if [ ! -s "$COMP_FILE" ]; then
|
||||||
BASHRC_FILE="$HOME/.bashrc"
|
cat > "$COMP_FILE" <<'EOF'
|
||||||
|
# completion postauto
|
||||||
source $BASHRC_FILE
|
|
||||||
|
|
||||||
manquants=()
|
|
||||||
|
|
||||||
for i in $LISTE_APPLIS; do
|
|
||||||
if ! command -v "$i" > /dev/null 2>&1; then
|
|
||||||
manquants+=("$i")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ${#manquants[@]} -gt 0 ]; then
|
|
||||||
echo -e "${ROUGE}Programme(s) manquant(s) : ${manquants[*]}${NORMAL}"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo -e "${VERT}Toutes les dépendances sont disponibles.${NORMAL}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Marqueurs pour identifier la section ajoutée
|
|
||||||
DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO"
|
|
||||||
FIN_MARKER="# FIN COMPLETION POSTAUTO"
|
|
||||||
|
|
||||||
# Le code de complétion à ajouter, encadré par les marqueurs
|
|
||||||
read -r -d '' COMPLETION_CODE << 'EOF'
|
|
||||||
# DEBUT COMPLETION POSTAUTO
|
|
||||||
# Fonction de complétion pour ton script
|
|
||||||
_autopost_completion() {
|
_autopost_completion() {
|
||||||
local cur prev opts
|
local cur prev opts
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
# Liste des commandes disponibles
|
|
||||||
opts="start stop restart show status createdb add log check update"
|
opts="start stop restart show status createdb add log check update"
|
||||||
|
|
||||||
# Si l'utilisateur est en train de taper le premier argument, proposer les commandes
|
|
||||||
if [ $COMP_CWORD -eq 1 ]; then
|
if [ $COMP_CWORD -eq 1 ]; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# (Optionnel) Pour la sous-commande "add", proposer des fichiers en complétion
|
|
||||||
if [ $COMP_CWORD -eq 2 ] && [ "${COMP_WORDS[1]}" = "add" ]; then
|
if [ $COMP_CWORD -eq 2 ] && [ "${COMP_WORDS[1]}" = "add" ]; then
|
||||||
COMPREPLY=( $(compgen -f -- "${cur}") )
|
COMPREPLY=( $(compgen -f -- "${cur}") )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Associer la fonction de complétion à ton script (ici, 'postauto' est le nom de la commande)
|
|
||||||
complete -F _autopost_completion postauto
|
complete -F _autopost_completion postauto
|
||||||
# FIN COMPLETION POSTAUTO
|
|
||||||
EOF
|
EOF
|
||||||
|
ok "Completion bash installée dans $COMP_FILE"
|
||||||
# Vérifier si le code est déjà présent dans le fichier bashrc
|
if ! grep -q 'bash_completion.d' "$BASHRC_FILE" 2>/dev/null; then
|
||||||
if grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then
|
echo '[ -f "$HOME/.bash_completion.d/postauto" ] && . "$HOME/.bash_completion.d/postauto"' >> "$BASHRC_FILE"
|
||||||
echo "La configuration de complétion pour 'postauto' est déjà présente dans $BASHRC_FILE."
|
fi
|
||||||
else
|
else
|
||||||
echo "Ajout de la configuration de complétion dans $BASHRC_FILE..."
|
ok "Completion déjà présente"
|
||||||
# Ajouter une ligne vide pour séparer (optionnel)
|
|
||||||
echo "" >> "$BASHRC_FILE"
|
|
||||||
# Ajouter le code de complétion
|
|
||||||
echo "$COMPLETION_CODE" >> "$BASHRC_FILE"
|
|
||||||
echo "Mise à jour effectuée."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ========= Environnement page de suivi (Node/NPM) =========
|
||||||
echo "Vérification de l'environnement pour la page de suivi..."
|
log "Vérification environnement Node.js"
|
||||||
|
|
||||||
# Fonction pour afficher les messages en vert
|
|
||||||
log() {
|
|
||||||
echo -e "\033[1;32m$1\033[0m"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Définir le répertoire NVM
|
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
|
||||||
# Vérifier si nvm est déjà chargé dans la session actuelle
|
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
||||||
log "nvm est déjà installé. Chargement de nvm..."
|
. "$NVM_DIR/nvm.sh"
|
||||||
\. "$NVM_DIR/nvm.sh"
|
|
||||||
else
|
else
|
||||||
log "nvm non trouvé, installation de nvm..."
|
log "Installation de nvm"
|
||||||
# Installer nvm
|
tmp_nvm="$TMP_DIR/install_nvm.sh"
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
|
download "https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh" "$tmp_nvm" \
|
||||||
|
|| die "Téléchargement nvm install.sh"
|
||||||
# Après l'installation, sourcer nvm pour la session courante
|
bash "$tmp_nvm"
|
||||||
export NVM_DIR="$HOME/.nvm"
|
. "$NVM_DIR/nvm.sh"
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
|
||||||
\. "$NVM_DIR/nvm.sh"
|
|
||||||
log "NVM installé et chargé."
|
|
||||||
else
|
|
||||||
log "Erreur : nvm n'a pas pu être chargé."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Vérification de Node.js
|
REQ_NODE_MAJOR=22
|
||||||
if command -v node &> /dev/null; then
|
if has_cmd node; then
|
||||||
current_version=$(node -v | sed 's/^v//')
|
cur="$(node -v | sed 's/^v//; s/\..*//')"
|
||||||
major_version=$(echo "$current_version" | cut -d. -f1)
|
if [ "$cur" -lt "$REQ_NODE_MAJOR" ]; then
|
||||||
if [ "$major_version" -lt 22 ]; then
|
log "Node < $REQ_NODE_MAJOR → installation"
|
||||||
log "Node.js version $current_version détectée (inférieure à 22). Mise à jour en cours..."
|
nvm install "$REQ_NODE_MAJOR"
|
||||||
nvm install 22
|
nvm use "$REQ_NODE_MAJOR"
|
||||||
nvm use 22
|
else
|
||||||
else
|
ok "Node $(node -v) OK"
|
||||||
log "Node.js version $current_version détectée, compatible."
|
fi
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
log "Node.js non trouvé, installation de Node.js 22..."
|
log "Installation Node $REQ_NODE_MAJOR"
|
||||||
nvm install 22
|
nvm install "$REQ_NODE_MAJOR"
|
||||||
nvm use 22
|
nvm use "$REQ_NODE_MAJOR"
|
||||||
updated="1"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Charger nvm après installation
|
# Modules npm locaux dans $AUTOPOST_DIR
|
||||||
export NVM_DIR="$HOME/.nvm"
|
log "Vérification modules npm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
pushd "$AUTOPOST_DIR" >/dev/null
|
||||||
|
[ -f package.json ] || npm init -y >/dev/null 2>&1 || true
|
||||||
|
modules=(express express-session sqlite3 ansi-to-html @tailwindcss/browser autoprefixer jquery mysql2 session-file-store chokidar argon2)
|
||||||
|
missing=()
|
||||||
|
for m in "${modules[@]}"; do
|
||||||
|
npm list "$m" --depth=0 >/dev/null 2>&1 || missing+=("$m")
|
||||||
|
done
|
||||||
|
if [ "${#missing[@]}" -gt 0 ]; then
|
||||||
|
log "Installation modules: ${missing[*]}"
|
||||||
|
npm install "${missing[@]}"
|
||||||
|
else
|
||||||
|
ok "Tous les modules npm sont présents"
|
||||||
|
fi
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
# Vérification des modules npm nécessaires
|
# ========= Fichiers Node (server.js, db.js, config.js) =========
|
||||||
log "Vérification des modules npm requis..."
|
log "Vérification fichiers Node"
|
||||||
|
[ -f "$AUTOPOST_DIR/server.js" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js" "$AUTOPOST_DIR/server.js"
|
||||||
|
[ -f "$AUTOPOST_DIR/db.js" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/db.js" "$AUTOPOST_DIR/db.js"
|
||||||
|
[ -f "$AUTOPOST_DIR/public/autopost.js" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/public/autopost.js" "$AUTOPOST_DIR/public/autopost.js"
|
||||||
|
[ -f "$AUTOPOST_DIR/public/checkboxes.css" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/public/checkboxes.css" "$AUTOPOST_DIR/public/checkboxes.css"
|
||||||
|
[ -f "$AUTOPOST_DIR/views/autopost.html" ] || download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/views/autopost.html" "$AUTOPOST_DIR/views/autopost.html"
|
||||||
|
if [ ! -f "$AUTOPOST_DIR/config.js" ]; then
|
||||||
|
download "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/config.js" "$AUTOPOST_DIR/config.js"
|
||||||
|
ok "Installation terminée. Configurez $AUTOPOST_DIR/config.js."
|
||||||
|
fi
|
||||||
|
|
||||||
modules=("express" "express-session" "sqlite3" "ansi-to-html" "@tailwindcss/browser" "autoprefixer" "jquery" "mysql2")
|
# ========= Vérification finale des commandes =========
|
||||||
missing_modules=()
|
log "Vérification finale des binaires requis"
|
||||||
|
missing_final=()
|
||||||
for module in "${modules[@]}"; do
|
for cmd in "${REQUIRED_CMDS[@]}"; do
|
||||||
if ! npm list "$module" &> /dev/null; then
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||||
missing_modules+=("$module")
|
if [[ "$cmd" == */* ]]; then
|
||||||
fi
|
[ -x "$cmd" ] || missing_final+=("$cmd")
|
||||||
|
else
|
||||||
|
missing_final+=("$cmd")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ${#missing_modules[@]} -gt 0 ]; then
|
if [ "${#missing_final[@]}" -gt 0 ]; then
|
||||||
log "Modules manquants détectés : ${missing_modules[*]}"
|
die "Programmes manquants: ${missing_final[*]}"
|
||||||
npm install "${missing_modules[@]}"
|
|
||||||
else
|
else
|
||||||
log "Tous les modules requis sont déjà installés."
|
ok "Toutes les dépendances sont disponibles."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Vérification et téléchargement des fichiers de configuration
|
# ========= Chown ciblé (si sudo utilisé) =========
|
||||||
log "Vérification des fichiers de configuration..."
|
if ! is_root && [ -n "${SUDO_USER:-}" ]; then
|
||||||
|
run_root chown -R "$SUDO_USER":"$SUDO_USER" "$BIN_DIR" "$AUTOPOST_DIR" "$BASH_COMPLETION_DIR" || true
|
||||||
if [ ! -f "$AUTOPOST_DIR/server.js" ]; then
|
|
||||||
log "Téléchargement de server.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/server.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js"
|
|
||||||
updated="1"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/db.js" ]; then
|
ok "Installation terminée."
|
||||||
log "Téléchargement de db.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/db.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/db.js"
|
|
||||||
updated="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/config.js" ]; then
|
|
||||||
log "Téléchargement de config.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/config.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/config.js"
|
|
||||||
echo -e "${BLEU}Installation terminée. Vous pouvez maintenant configurer $AUTOPOST_DIR/config.js.${NORMAL}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Suppression du script après exécution..."
|
|
||||||
rm -- "$0"
|
|
||||||
|
|
||||||
if $sudook; then
|
|
||||||
# change propriétaire/group récursivement
|
|
||||||
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d: -f6)
|
|
||||||
sudo chown -R "$SUDO_USER":"$SUDO_USER" "$USER_HOME"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
312
readme.md
312
readme.md
@@ -1,83 +1,90 @@
|
|||||||
## Postauto
|
# Postauto
|
||||||
### Pour poster automatiquement avec une simple commande depuis un VPS , serveur dédié ou seedbox.
|
### Poster automatiquement via une simple commande depuis un VPS, dédié ou seedbox
|
||||||
|
|
||||||
Postauto est un script permettant via une simple commande d'ajouter un fichier à traiter dans une base de données.
|
**Postauto** est un ensemble de scripts (bash + une petite UI web Node.js) qui :
|
||||||
Une fois votre fichier ajouté il sera traité automatiquement.
|
- génèrent les **PAR2**
|
||||||
|
- postent via **Nyuu** (avec **obfuscation**)
|
||||||
|
- envoient automatiquement sur le site (MediaInfo/BDInfo inclus)
|
||||||
|
- proposent un **suivi sur une page web**
|
||||||
|
|
||||||
#### Possibilités.
|
## Sommaire
|
||||||
|
- [Prérequis](#prérequis)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Configuration (bash)](#configuration-bash--homeuserautopostconfsh)
|
||||||
|
- [Configuration (UI web)](#configuration-ui-web--homeuserautopostconfigjs)
|
||||||
|
- [Création de la base](#création-de-la-base)
|
||||||
|
- [Commandes CLI](#commandes-cli)
|
||||||
|
- [Interface web](#interface-web)
|
||||||
|
- [Configuration Nginx](#configuration-nginx)
|
||||||
|
- [Mise à jour](#mise-à-jour)
|
||||||
|
- [Automatique](#automatique)
|
||||||
|
- [Manuellement](#manuellement)
|
||||||
|
- [Désinstallation](#désinstallation)
|
||||||
|
- [Limitations](#limitations)
|
||||||
|
- [Dépannage](#dépannage)
|
||||||
|
|
||||||
- Création des PAR2
|
## Prérequis
|
||||||
- Post via NYUU ( obfuscation totale)
|
- Linux (script bash)
|
||||||
- ✨Envoi automatique sur le site✨ (avec MediaInfo/BDInfo directement ajouté)
|
- Accès **SSH** (sur `/home/$USER`)
|
||||||
- Suivi sur une page web
|
- Outils de base : `basename`, `curl`, `screen`, `nginx` (pour l’UI web)
|
||||||
|
- Testé avec :
|
||||||
|
- VPS / dédiés ✅
|
||||||
|
- Seedbox : Ultra.cc ✅, Whatbox ✅, Dediseedbox ❌ (limitations)
|
||||||
|
|
||||||
#### Limitations.
|
> L’installateur installe/emballe tout le reste (mediainfo, sqlite3 si besoin, 7z, BDInfo, Nyuu, ParPar, Node v22, modules npm…).
|
||||||
|
|
||||||
- [ ] Le script est écrit en bash il ne tourne donc que sous linux.
|
## Installation
|
||||||
- [ ] Il faut impérativement un accès SSH sur /home/$USER
|
|
||||||
- VPS et Dédié pas de souci de ce coté.
|
|
||||||
- Seedbox nous avons testé via ultracc whatbox et dediseedbox ( ultracc et whatbox ok, dediseedbox pas ok).
|
|
||||||
- [ ] Il faut avoir les applications suivantes de disponibles.
|
|
||||||
|
|
||||||
| Commande | README |
|
### Avec droits sudo (recommandé)
|
||||||
| ------ | ------ |
|
Installe mediainfo/sqlite via paquets Debian (meilleure compatibilité) :
|
||||||
| basename | Normalement installé par défaut |
|
```bash
|
||||||
| curl | à installer si nécessaire |
|
wget -qO install.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/install.sh \
|
||||||
| screen | à installer si nécessaire |
|
&& chmod +x install.sh \
|
||||||
| nginx | à installer si vous désirez utiliser l'interface de suivi |
|
&& sudo --preserve-env=HOME ./install.sh
|
||||||
|
|
||||||
#### Installation.
|
|
||||||
##### 2 solutions possible
|
|
||||||
|
|
||||||
- vous disposez des droits sudo :
|
|
||||||
|
|
||||||
```sh
|
|
||||||
wget -qO install.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/install.sh && chmod +x install.sh && sudo --preserve-env=HOME ./install.sh
|
|
||||||
```
|
|
||||||
> Cela installera via les paquets debian sqlite et mediinfo (meilleur compatibilité)
|
|
||||||
|
|
||||||
- vous ne disposez pas des droits sudo :
|
|
||||||
|
|
||||||
```sh
|
|
||||||
wget -qO install.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/install.sh && chmod +x install.sh && ./install.sh
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Update
|
### Sans sudo
|
||||||
|
Utilise des binaires « standalone » dans `~/bin` :
|
||||||
```sh
|
```bash
|
||||||
postauto stop && wget -qO update.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/update.sh && chmod +x update.sh && ./update.sh
|
wget -qO install.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/install.sh \
|
||||||
|
&& chmod +x install.sh \
|
||||||
|
&& ./install.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Update passage EN 7z (12/03/2024)
|
## Configuration (bash) — `/home/$USER/autopost/conf.sh`
|
||||||
|
|
||||||
```sh
|
> Variables **obligatoires** (placeholders à remplacer), + règles **sqlite/mysql**.
|
||||||
cd autopost
|
|
||||||
wget -qO compress.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/compress.sh && chmod +x compress.sh && ./compress.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Configuration.
|
```bash
|
||||||
Éditer le fichier /home/$USER/autopost/conf.sh
|
|
||||||
```sh
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#CONFIG A MODIF
|
# CONFIG À MODIFIER
|
||||||
URL_API="A NOUS DEMANDER SUR DISCORD"
|
URL_API="A NOUS DEMANDER SUR DISCORD"
|
||||||
APIKEY="A RETROUVER DANS VOTRE PROFIL"
|
APIKEY="A RETROUVER DANS VOTRE PROFIL"
|
||||||
DB_FILE="/home/$USER/autopost/base_autopost.db"
|
|
||||||
DOSSIER_GLOBAL="/home/$USER/"
|
DOSSIER_GLOBAL="/home/$USER/"
|
||||||
DOSSIER_NFO="/home/$USER/autopost/mediainfo/"
|
DOSSIER_NFO="/home/$USER/autopost/mediainfo/"
|
||||||
DOSSIER_LOGS="/home/$USER/autopost/logs/"
|
DOSSIER_LOGS="/home/$USER/autopost/logs/"
|
||||||
DOSSIER_NZB_ATTENTE="/home/$USER/ATTENTE/"
|
DOSSIER_NZB_ATTENTE="/home/$USER/autopost/ATTENTE/"
|
||||||
DOSSIER_NZB_FINAL="/home/$USER/FINIS/"
|
DOSSIER_NZB_FINAL="/home/$USER/autopost/FINIS/"
|
||||||
|
|
||||||
#CONFIG FOURNISSEUR USENET DE POST
|
# cp -rl | cp -rs | ln -s | mv | cp
|
||||||
|
MOVE_CMD="cp -rl"
|
||||||
|
|
||||||
|
# CONFIG FOURNISSEUR USENET DE POST (requis)
|
||||||
NG_HOST=""
|
NG_HOST=""
|
||||||
NG_PORT=""
|
NG_PORT=""
|
||||||
NG_USER=""
|
NG_USER=""
|
||||||
NG_PASS=""
|
NG_PASS=""
|
||||||
NG_NBR_CONN=""
|
NG_NBR_CONN=""
|
||||||
|
|
||||||
dbtype="sqlite" # ou "mysql"
|
# Base de données
|
||||||
|
dbtype="sqlite" # ou "mysql"
|
||||||
|
MYSQL_TABLE="release" # OBLIGATOIRE
|
||||||
|
|
||||||
|
# sqlite -> DB_FILE requis, champs MySQL facultatifs
|
||||||
DB_FILE="/home/$USER/autopost/base_autopost.db"
|
DB_FILE="/home/$USER/autopost/base_autopost.db"
|
||||||
|
|
||||||
|
# mysql -> champs MySQL requis, DB_FILE facultatif
|
||||||
MYSQL_HOST=""
|
MYSQL_HOST=""
|
||||||
MYSQL_PORT=
|
MYSQL_PORT=
|
||||||
MYSQL_USER=""
|
MYSQL_USER=""
|
||||||
@@ -85,61 +92,50 @@ MYSQL_PASS=""
|
|||||||
MYSQL_DB=""
|
MYSQL_DB=""
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Création du fichier de base de données.
|
**Rappels :**
|
||||||
```sh
|
- Si `dbtype="sqlite"` → **`DB_FILE` requis** ; `MYSQL_*` facultatifs.
|
||||||
postauto createdb
|
- Si `dbtype="mysql"` → **`MYSQL_HOST/PORT/USER/PASS/DB` requis** ; `DB_FILE` facultatif.
|
||||||
```
|
- Les dossiers `DOSSIER_*` doivent **exister**.
|
||||||
|
|
||||||
#### Commande
|
## Configuration (UI web) — `/home/$USER/autopost/config.js`
|
||||||
|
|
||||||
| commande | README |
|
> Champs **obligatoires** + règles **sqlite/mysql** + proxy/HTTPS.
|
||||||
| ------ | ------ |
|
|
||||||
| start | Permet de démarrer le script. |
|
|
||||||
| stop | Permet d'arrêter le script. |
|
|
||||||
| restart | Permet de redémarrer le script. |
|
|
||||||
| show | Permet de rentrer dans la fenêtre d'exécution du script (ctrl a+d pour en sortir). |
|
|
||||||
| status | Voir les 500 derniers enregistrements du fichier DB avec leur status (Attente, Echec, Succès) (Attente, Echec, Succès). |
|
|
||||||
| add | Ajouté un fichier MKV à traiter dans la base (doit être suivi du chemin complet de votre fichier). |
|
|
||||||
| createdb | Permet de créer la DB (si vous souhaitez écraser la DB une confirmation vous sera demandé). |
|
|
||||||
| log | Permet de voir le log de ppost d'un fichier précis. |
|
|
||||||
| check | Permet de vérifier la présence d'un fichier sur le site. |
|
|
||||||
| update | Permet d'updater le script. |
|
|
||||||
|
|
||||||
|
|
||||||
#### interface web
|
|
||||||
|
|
||||||
Une interface est disponible, il vous faut nginx pour que celle-ci fonctionne
|
|
||||||
|
|
||||||
#### Configuration de l'interface web.
|
|
||||||
Éditer le fichier /home/$USER/autopost/config.js
|
|
||||||
```js
|
```js
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// Port sur lequel le serveur écoute
|
// Réseau
|
||||||
// Attention si vous êtes sur une seedbox de bien choisir un port laisser libre par votre hébergeur
|
port: 3000, // ⚠️ Choisissez un port autorisé par votre hébergeur (Ultra.cc: `app-ports free`)
|
||||||
// chez ultracc par exemple la commande est app-ports free
|
name: 'NomDuNoeud', // Nom affiché dans l’UI
|
||||||
port: Voir indications ci dessus,
|
background_color: 'slate-900', // Tailwind color: https://tailwindcss.com/docs/colors
|
||||||
|
|
||||||
// Chemin vers le fichier de base de données SQLite
|
// Base de données
|
||||||
|
dbtype: 'sqlite', // 'sqlite' ou 'mysql'
|
||||||
|
|
||||||
|
// sqlite -> dbFile requis
|
||||||
dbFile: path.join(__dirname, 'base_autopost.db'),
|
dbFile: path.join(__dirname, 'base_autopost.db'),
|
||||||
|
|
||||||
//MySQL
|
// mysql -> champs requis
|
||||||
DB_HOST: '',
|
DB_HOST: '',
|
||||||
DB_PORT: ,
|
DB_PORT: 3306,
|
||||||
DB_USER: '',
|
DB_USER: '',
|
||||||
DB_PASSWORD: '',
|
DB_PASSWORD: '',
|
||||||
DB_DATABASE: '',
|
DB_DATABASE: '',
|
||||||
|
DB_TABLE: 'release',
|
||||||
|
|
||||||
// Chemins personnalisables pour les dossiers
|
// Dossiers
|
||||||
finishdirectory: path.join(__dirname, 'FINIS'),
|
finishdirectory: path.join(__dirname, 'FINIS'),
|
||||||
logdirectory: path.join(__dirname, 'logs'),
|
logdirectory: path.join(__dirname, 'logs'),
|
||||||
infodirectory: path.join(__dirname, 'mediainfo'),
|
infodirectory: path.join(__dirname, 'mediainfo'),
|
||||||
|
|
||||||
// Secret pour la configuration des sessions "curl -L pw.vdx.sh/w/32"
|
// Sessions (générer un secret : `curl -L pw.vdx.sh/w/32`)
|
||||||
sessionSecret: 'Voir commande ci dessus',
|
sessionSecret: 'collez-ici-le-secret-généré',
|
||||||
|
trustProxy: 0, // 0 = pas de proxy, 1 = Nginx, 2 = Cloudflare->Nginx, etc.
|
||||||
|
cookieSecure: false, // true si HTTPS bout-à-bout (reverse proxy compris)
|
||||||
|
sessionStorePath: './sessions',
|
||||||
|
|
||||||
// Informations d'authentification
|
// Auth UI (à changer !)
|
||||||
auth: {
|
auth: {
|
||||||
username: 'user',
|
username: 'user',
|
||||||
password: 'pass'
|
password: 'pass'
|
||||||
@@ -147,27 +143,133 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Configuration de nginx
|
**Rappels :**
|
||||||
|
- `dbtype: 'sqlite'` → **`dbFile` requis** ; `DB_*` facultatifs.
|
||||||
|
- `dbtype: 'mysql'` → **`DB_HOST/PORT/USER/PASSWORD/DATABASE` requis** ; `dbFile` facultatif.
|
||||||
|
- Si vous êtes derrière Nginx/Cloudflare, ajustez **`trustProxy`** et **`cookieSecure`**.
|
||||||
|
- Les dossiers `finishdirectory`, `logdirectory`, `infodirectory` doivent **exister**.
|
||||||
|
|
||||||
Ajouter ce bloc dans la configuration de votre nom de domaine
|
## Création de la base
|
||||||
|
```bash
|
||||||
|
postauto createdb
|
||||||
|
```
|
||||||
|
|
||||||
|
## Commandes CLI
|
||||||
|
|
||||||
|
| Commande | Description |
|
||||||
|
|-----------|-------------|
|
||||||
|
| `start` | Démarre le script principal. |
|
||||||
|
| `stop` | Arrête le script. |
|
||||||
|
| `restart` | Redémarre le script. |
|
||||||
|
| `show` | Entre dans la session `screen` (Ctrl+A puis D pour détacher). |
|
||||||
|
| `status` | Affiche les 500 derniers enregistrements avec leur statut (Attente / Échec / Succès). |
|
||||||
|
| `add` | Ajoute un **fichier MKV** à traiter (chemin complet requis). |
|
||||||
|
| `createdb`| Crée (ou recrée, avec confirmation) la base de données. |
|
||||||
|
| `log` | Affiche le log de post pour un fichier donné. |
|
||||||
|
| `check` | Vérifie la présence d’un fichier sur le site. |
|
||||||
|
| `update` | Met à jour les scripts. |
|
||||||
|
|
||||||
|
> Autocomplétion bash fournie (install/update l’activent automatiquement).
|
||||||
|
|
||||||
|
## Interface web
|
||||||
|
|
||||||
|
- L’installateur installe **Node v22** (via `nvm`) et tous les modules requis.
|
||||||
|
- Lancer l’UI (ex. en arrière-plan) :
|
||||||
|
```bash
|
||||||
|
postauto restart
|
||||||
|
```
|
||||||
|
(ou configurez un service systemd / `pm2` selon vos préférences)
|
||||||
|
|
||||||
|
### Configuration Nginx
|
||||||
|
|
||||||
|
> **Important :** les routes statiques sont servies sous **`/autopost`**.
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
|
# Remplacez 127.0.0.1:3000 par le host:port de votre UI (voir config.js: port)
|
||||||
location /autopost/ {
|
location /autopost/ {
|
||||||
proxy_pass http://127.0.0.1:XXXXX;
|
proxy_pass http://127.0.0.1:3000;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header X-Forwarded-Host $http_host;
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /js/ {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /jquery/ {
|
||||||
|
proxy_pass http://127.0.0.1:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Host $host;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> Pensez à bien remplacer XXXXX par le port que vous avez mis dans votre config.js
|
> Réglez **`trustProxy`** (1 pour Nginx, 2 pour Cloudflare→Nginx) et mettez **`cookieSecure: true`** si le site est servi en **HTTPS**.
|
||||||
|
|
||||||
|
## Mise à jour
|
||||||
#### Désinstallation.
|
### Automatique
|
||||||
|
```bash
|
||||||
```sh
|
postauto restart
|
||||||
wget -qO uninstall.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/uninstall.sh && chmod +x uninstall.sh && ./uninstall.sh
|
```
|
||||||
|
ou
|
||||||
|
```bash
|
||||||
|
postauto stop
|
||||||
|
postauto update
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Dévelopement.
|
### Manuellement
|
||||||
|
```bash
|
||||||
|
postauto stop \
|
||||||
|
&& wget -qO update.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/update.sh \
|
||||||
|
&& chmod +x update.sh \
|
||||||
|
&& ./update.sh
|
||||||
|
```
|
||||||
|
|
||||||
Comme toujours vos idées et axes d'amélioration sont les bienvenus.
|
### Passage en 7z (12/03/2024)
|
||||||
|
```bash
|
||||||
|
cd ~/autopost
|
||||||
|
wget -qO compress.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/compress.sh \
|
||||||
|
&& chmod +x compress.sh \
|
||||||
|
&& ./compress.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Désinstallation
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget -qO uninstall.sh https://tig.unfr.pw/UNFR/postauto/raw/branch/main/uninstall.sh \
|
||||||
|
&& chmod +x uninstall.sh \
|
||||||
|
&& ./uninstall.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
- Propose d’arrêter `postauto`, de supprimer la conf, la base, les NZB, et les fichiers Node.
|
||||||
|
- Nettoie l’autocomplétion (`~/.bash_completion.d/postauto`) et l’ancien bloc éventuel dans `~/.bashrc`.
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
- Bash → Linux uniquement.
|
||||||
|
- Accès SSH requis sur `/home/$USER`.
|
||||||
|
- Les seedbox peuvent restreindre les ports et/ou l’exécution de services persistants (voir hébergeur).
|
||||||
|
|
||||||
|
## Dépannage
|
||||||
|
|
||||||
|
- **Port refusé** : choisissez un port autorisé (Ultra.cc : `app-ports free`).
|
||||||
|
- **Node manquant** : relancez `install.sh` (il installe `nvm` + Node v22).
|
||||||
|
- **MediaInfo/sqlite** : avec sudo, installés via apt ; sans sudo, binaires fournis dans `~/bin`.
|
||||||
|
- **Erreur GLIBC** sur sqlite ou autre binaire : utilisez la version embarquée par l’installateur (dans `~/bin`).
|
||||||
|
- **Sessions** derrière Nginx : mettez `trustProxy` à `1` (ou `2` via Cloudflare→Nginx) et `cookieSecure: true` si HTTPS.
|
||||||
|
- **Dossiers manquants** : créez/ajustez `DOSSIER_*` (bash) et `*directory` (UI).
|
||||||
|
|
||||||
|
## Développement
|
||||||
|
Vos idées et axes d’amélioration sont les bienvenus — PRs et issues appréciés 🙂
|
||||||
|
|||||||
185
uninstall.sh
185
uninstall.sh
@@ -1,81 +1,148 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
source "$HOME/autopost/common.sh"
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
# ────────── Helpers & couleurs ──────────
|
||||||
|
if [ -t 1 ]; then
|
||||||
|
ROUGE='\e[31m'; VERT='\e[32m'; JAUNE='\e[33m'; BLEU='\e[34m'; NORMAL='\e[0m'
|
||||||
|
else
|
||||||
|
ROUGE=''; VERT=''; JAUNE=''; BLEU=''; NORMAL=''
|
||||||
|
fi
|
||||||
|
log() { printf "${BLEU}%s${NORMAL}\n" "$*"; }
|
||||||
|
ok() { printf "${VERT}%s${NORMAL}\n" "$*"; }
|
||||||
|
warn() { printf "${JAUNE}%s${NORMAL}\n" "$*"; }
|
||||||
|
err() { printf "${ROUGE}%s${NORMAL}\n" "$*"; }
|
||||||
|
|
||||||
|
confirm() { # confirm "message" -> 0 si oui
|
||||||
|
read -r -p "$1 (y/N) : " _ans
|
||||||
|
[[ "${_ans:-}" =~ ^[Yy]$ ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
safe_rm_file(){ # supprime si fichier et sous $HOME
|
||||||
|
local f="$1"
|
||||||
|
[[ -n "$f" && -f "$f" && "$f" == "$HOME/"* ]] && rm -f -- "$f"
|
||||||
|
}
|
||||||
|
|
||||||
|
safe_rm_dir(){ # supprime si dossier et sous $HOME
|
||||||
|
local d="$1"
|
||||||
|
[[ -n "$d" && -d "$d" && "$d" == "$HOME/"* ]] && rm -rf -- "$d"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ────────── Paths ──────────
|
||||||
BIN_DIR="$HOME/bin"
|
BIN_DIR="$HOME/bin"
|
||||||
AUTOPOST_DIR="$HOME/autopost"
|
AUTOPOST_DIR="$HOME/autopost"
|
||||||
|
BASHRC_FILE="$HOME/.bashrc"
|
||||||
|
BASH_COMPLETION_DIR="$HOME/.bash_completion.d"
|
||||||
|
CONF_SH="$AUTOPOST_DIR/conf.sh"
|
||||||
|
|
||||||
LISTE_APPLIS=(
|
# ────────── Charger conf.sh (facultatif) pour récupérer DOSSIER_* / DB_FILE ──────────
|
||||||
"$BIN_DIR/mediainfo"
|
if [ -f "$CONF_SH" ]; then
|
||||||
"$BIN_DIR/sqlite3"
|
# conf.sh ne fait que définir des variables : sourcing OK
|
||||||
"$BIN_DIR/jq"
|
# shellcheck source=/dev/null
|
||||||
"$BIN_DIR/nyuu"
|
. "$CONF_SH"
|
||||||
"$BIN_DIR/parpar"
|
else
|
||||||
"$BIN_DIR/postauto"
|
warn "conf.sh introuvable, certaines suppressions (DOSSIER_*) pourront être ignorées."
|
||||||
"$BIN_DIR/BDInfo"
|
fi
|
||||||
"$BIN_DIR/BDInfoDataSubstractor"
|
|
||||||
|
# ────────── Proposer d’arrêter postauto si présent ──────────
|
||||||
|
if [ -x "$BIN_DIR/postauto" ]; then
|
||||||
|
if confirm "Arrêter 'postauto' avant désinstallation ?"; then
|
||||||
|
"$BIN_DIR/postauto" stop || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ────────── Supprimer binaires installés dans $HOME/bin ──────────
|
||||||
|
log "Suppression des binaires…"
|
||||||
|
BIN_LIST=(
|
||||||
|
"$BIN_DIR/mediainfo"
|
||||||
|
"$BIN_DIR/sqlite3"
|
||||||
|
"$BIN_DIR/jq"
|
||||||
|
"$BIN_DIR/nyuu"
|
||||||
|
"$BIN_DIR/parpar"
|
||||||
|
"$BIN_DIR/postauto"
|
||||||
|
"$BIN_DIR/BDInfo"
|
||||||
|
"$BIN_DIR/BDInfoDataSubstractor"
|
||||||
|
"$BIN_DIR/7z"
|
||||||
)
|
)
|
||||||
|
for f in "${BIN_LIST[@]}"; do
|
||||||
# Vérifier et supprimer les fichiers existants
|
if [ -f "$f" ]; then
|
||||||
for fichier in "${LISTE_APPLIS[@]}"; do
|
echo " - $f"
|
||||||
if [ -f "$fichier" ]; then
|
safe_rm_file "$f"
|
||||||
echo "Suppression de $fichier"
|
fi
|
||||||
rm -f "$fichier"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
rm -f "$AUTOPOST_DIR/common.sh"
|
# ────────── Supprimer scripts autopost ──────────
|
||||||
rm -f "$AUTOPOST_DIR/posteur.sh"
|
log "Suppression des scripts autopost…"
|
||||||
rm -f "$AUTOPOST_DIR/analyzer.sh"
|
safe_rm_file "$AUTOPOST_DIR/common.sh"
|
||||||
rm -rf "${DOSSIER_NFO:-}"
|
safe_rm_file "$AUTOPOST_DIR/posteur.sh"
|
||||||
|
safe_rm_file "$AUTOPOST_DIR/analyzer.sh"
|
||||||
|
|
||||||
# Demander confirmation pour supprimer le fichier de conf
|
# Fichiers Node optionnels (server/db/config, node_modules, sessions, logs)
|
||||||
read -r -p "Voulez-vous vraiment supprimer votre fichier de conf ? (y/n) : " conf
|
if confirm "Supprimer aussi les fichiers Node (server.js, db.js, config.js), node_modules et sessions ?"; then
|
||||||
if [[ "$conf" =~ ^[Yy]$ ]]; then
|
safe_rm_file "$AUTOPOST_DIR/server.js"
|
||||||
rm -f "$AUTOPOST_DIR/conf.sh"
|
safe_rm_file "$AUTOPOST_DIR/db.js"
|
||||||
|
safe_rm_file "$AUTOPOST_DIR/config.js"
|
||||||
|
safe_rm_dir "$AUTOPOST_DIR/node_modules"
|
||||||
|
safe_rm_dir "$AUTOPOST_DIR/sessions"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Demander confirmation pour supprimer la base de données
|
# ────────── Dossiers médias (depuis conf.sh si dispo) ──────────
|
||||||
read -r -p "Voulez-vous vraiment supprimer $DB_FILE ? (y/n) : " filedb
|
# Dossier NFO
|
||||||
if [[ "$filedb" =~ ^[Yy]$ ]]; then
|
if [ -n "${DOSSIER_NFO:-}" ] && [ -d "${DOSSIER_NFO:-}" ]; then
|
||||||
rm -f "$DB_FILE"
|
if confirm "Supprimer le dossier NFO (${DOSSIER_NFO}) ?"; then
|
||||||
|
safe_rm_dir "${DOSSIER_NFO}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Demander confirmation pour supprimer les NZB
|
# Supprimer la conf ?
|
||||||
read -r -p "Voulez-vous supprimer vos NZB ? (y/n) : " nzb
|
if [ -f "$CONF_SH" ] && confirm "Supprimer votre fichier de conf (${CONF_SH}) ?"; then
|
||||||
if [[ "$nzb" =~ ^[Yy]$ ]]; then
|
safe_rm_file "$CONF_SH"
|
||||||
rm -f "$DB_FILE"
|
|
||||||
rm -rf "${DOSSIER_NZB_ATTENTE:-}"
|
|
||||||
rm -rf "${DOSSIER_NZB_FINAL:-}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Vérifier si le dossier existe et est vide
|
# Supprimer la base de données SQLite ?
|
||||||
|
if [ -n "${DB_FILE:-}" ] && [ -f "${DB_FILE:-}" ] && confirm "Supprimer la base SQLite (${DB_FILE}) ?"; then
|
||||||
|
safe_rm_file "$DB_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Supprimer les NZB ?
|
||||||
|
if confirm "Supprimer vos NZB (ATTENTE & FINIS) ?"; then
|
||||||
|
safe_rm_dir "${DOSSIER_NZB_ATTENTE:-}"
|
||||||
|
safe_rm_dir "${DOSSIER_NZB_FINAL:-}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Si dossier autopost devenu vide → supprimer
|
||||||
if [ -d "$AUTOPOST_DIR" ] && [ -z "$(ls -A "$AUTOPOST_DIR" 2>/dev/null)" ]; then
|
if [ -d "$AUTOPOST_DIR" ] && [ -z "$(ls -A "$AUTOPOST_DIR" 2>/dev/null)" ]; then
|
||||||
echo "Suppression du dossier $AUTOPOST_DIR car il est vide."
|
echo "Suppression du dossier $AUTOPOST_DIR (vide)."
|
||||||
rmdir "$AUTOPOST_DIR"
|
rmdir -- "$AUTOPOST_DIR" || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Chemin vers le fichier bashrc
|
# ────────── Nettoyage complétion bash ──────────
|
||||||
BASHRC_FILE="$HOME/.bashrc"
|
|
||||||
|
|
||||||
# Définir les marqueurs qui encadrent le bloc à supprimer
|
|
||||||
DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO"
|
DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO"
|
||||||
FIN_MARKER="# FIN COMPLETION POSTAUTO"
|
FIN_MARKER="# FIN COMPLETION POSTAUTO"
|
||||||
|
|
||||||
# Vérifier si le bloc est présent dans le fichier
|
# 1) Supprimer l'ancien bloc directement dans ~/.bashrc
|
||||||
if grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then
|
if [ -f "$BASHRC_FILE" ] && grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then
|
||||||
echo "Suppression de la configuration de complétion dans $BASHRC_FILE..."
|
echo "Suppression de l'ancien bloc de complétion dans $BASHRC_FILE…"
|
||||||
|
cp "$BASHRC_FILE" "${BASHRC_FILE}.bak"
|
||||||
# Faire une sauvegarde de sécurité du fichier .bashrc
|
sed -i "/$DEBUT_MARKER/,/$FIN_MARKER/d" "$BASHRC_FILE"
|
||||||
cp "$BASHRC_FILE" "${BASHRC_FILE}.bak"
|
ok "Bloc de complétion supprimé (backup: ${BASHRC_FILE}.bak)."
|
||||||
echo "Sauvegarde réalisée dans ${BASHRC_FILE}.bak"
|
|
||||||
|
|
||||||
# Supprimer le bloc de code entre les marqueurs (inclusifs)
|
|
||||||
sed -i "/$DEBUT_MARKER/,/$FIN_MARKER/d" "$BASHRC_FILE"
|
|
||||||
|
|
||||||
echo "Bloc de configuration supprimé."
|
|
||||||
else
|
|
||||||
echo "Aucun bloc de configuration de complétion trouvé dans $BASHRC_FILE."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Suppression du script après exécution..."
|
# 2) Supprimer le fichier de complétion moderne et sa ligne 'source' éventuelle
|
||||||
rm -- "$0"
|
COMP_FILE="$BASH_COMPLETION_DIR/postauto"
|
||||||
|
if [ -f "$COMP_FILE" ]; then
|
||||||
|
echo "Suppression $COMP_FILE"
|
||||||
|
rm -f -- "$COMP_FILE"
|
||||||
|
fi
|
||||||
|
if [ -f "$BASHRC_FILE" ]; then
|
||||||
|
# enlève la ligne de sourcing si présente
|
||||||
|
if grep -q '\.bash_completion.d/postauto' "$BASHRC_FILE"; then
|
||||||
|
cp "$BASHRC_FILE" "${BASHRC_FILE}.bak2"
|
||||||
|
sed -i '\|\.bash_completion\.d/postauto|d' "$BASHRC_FILE"
|
||||||
|
ok "Ligne de sourcing supprimée (backup: ${BASHRC_FILE}.bak2)."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Suppression du script après exécution…"
|
||||||
|
rm -- "$0" 2>/dev/null || true
|
||||||
|
|
||||||
|
ok "Désinstallation terminée."
|
||||||
|
|||||||
619
update.sh
619
update.sh
@@ -1,299 +1,396 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Couleurs de texte
|
|
||||||
NOIR='\e[30m'
|
|
||||||
ROUGE='\e[31m'
|
|
||||||
VERT='\e[32m'
|
|
||||||
JAUNE='\e[33m'
|
|
||||||
BLEU='\e[34m'
|
|
||||||
ROSE='\e[35m'
|
|
||||||
CYAN='\e[36m'
|
|
||||||
BLANC='\e[37m'
|
|
||||||
|
|
||||||
# Couleurs de fond
|
# exiger bash, bloquer le "source"
|
||||||
FOND_NOIR='\e[40m'
|
[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"
|
||||||
FOND_ROUGE='\e[41m'
|
(return 0 2>/dev/null) && { echo "❌ Ne source pas ce script, exécute-le: ./$0"; return 1; }
|
||||||
FOND_VERT='\e[42m'
|
|
||||||
FOND_JAUNE='\e[43m'
|
|
||||||
FOND_BLEU='\e[44m'
|
|
||||||
FOND_ROSE='\e[45m'
|
|
||||||
FOND_CYAN='\e[46m'
|
|
||||||
FOND_BLANC='\e[47m'
|
|
||||||
|
|
||||||
# Effets
|
# chemin canonique du script (robuste: ./script.sh, bash script.sh, via PATH, symlink…)
|
||||||
GRAS='\e[1m'
|
SCRIPT_SOURCE="${BASH_SOURCE[0]}"
|
||||||
SOULIGNE='\e[4m'
|
SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_SOURCE")" && pwd -P)"
|
||||||
CLIGNOTANT='\e[5m'
|
SCRIPT_FILE="$SCRIPT_DIR/$(basename -- "$SCRIPT_SOURCE")"
|
||||||
INVERSE='\e[7m'
|
|
||||||
NORMAL='\e[0m'
|
|
||||||
|
|
||||||
updated="0"
|
set -Eeuo pipefail
|
||||||
|
trap 'echo "❌ ERREUR ligne $LINENO: $BASH_COMMAND" >&2' ERR
|
||||||
|
|
||||||
#Vérification des prérequis
|
# ────────── Helpers & couleurs ──────────
|
||||||
echo -e "$BLEU""Vérification si les prérequis sont disponibles""$NORMAL"
|
if [ -t 1 ]; then
|
||||||
LISTE_APPLIS="curl basename php screen"
|
ROUGE='\e[31m'; VERT='\e[32m'; JAUNE='\e[33m'; BLEU='\e[34m'; NORMAL='\e[0m'
|
||||||
|
else
|
||||||
|
ROUGE=''; VERT=''; JAUNE=''; BLEU=''; NORMAL=''
|
||||||
|
fi
|
||||||
|
log() { printf "${BLEU}%s${NORMAL}\n" "$*"; }
|
||||||
|
ok() { printf "${VERT}%s${NORMAL}\n" "$*"; }
|
||||||
|
warn() { printf "${JAUNE}%s${NORMAL}\n" "$*"; }
|
||||||
|
err() { printf "${ROUGE}%s${NORMAL}\n" "$*"; }
|
||||||
|
die() { err "$*"; exit 1; }
|
||||||
|
|
||||||
|
install_bin(){ install -m 755 "$1" "$2"; }
|
||||||
|
|
||||||
|
# ========= Downloader (curl→wget fallback) =========
|
||||||
|
download() {
|
||||||
|
local url="$1" out="$2"
|
||||||
|
[ -z "$url" ] || [ -z "$out" ] && { echo "download: usage: download <url> <outfile>" >&2; return 2; }
|
||||||
|
mkdir -p -- "$(dirname -- "$out")"
|
||||||
|
local tmp="${out}.dl.$$"
|
||||||
|
local curl_opts=(--fail --silent --show-error --location --retry 5 --retry-all-errors --retry-delay 2 --connect-timeout 15)
|
||||||
|
local wget_opts=(--quiet --https-only --tries=5 --waitretry=2 --retry-connrefused)
|
||||||
|
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
if curl --http1.1 -4 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if env -u http_proxy -u https_proxy -u all_proxy \
|
||||||
|
curl --http1.1 -4 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if curl --http1.1 "${curl_opts[@]}" -o "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
fi
|
||||||
|
if command -v wget >/dev/null 2>&1; then
|
||||||
|
if wget --inet4-only "${wget_opts[@]}" -O "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
if wget "${wget_opts[@]}" -O "$tmp" "$url"; then mv -f -- "$tmp" "$out"; return 0; fi
|
||||||
|
fi
|
||||||
|
rm -f -- "$tmp" 2>/dev/null || true
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- lire une clé JS (ligne "clé: valeur") sans exécuter ---
|
||||||
|
parse_js_raw() {
|
||||||
|
local key="$1"
|
||||||
|
sed -n -E "s/^[[:space:]]*['\"]?${key}['\"]?[[:space:]]*:[[:space:]]*(.*)$/\1/p" "$CFG_JS" \
|
||||||
|
| head -n1 | sed -E "s/[[:space:]]*(,)?[[:space:]]*$//"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- normaliser une valeur JS simple ---
|
||||||
|
normalize_js_value() {
|
||||||
|
local raw="$1"
|
||||||
|
raw="$(printf '%s' "$raw" | sed -E 's@[[:space:]]//.*$@@')" # retire commentaire inline
|
||||||
|
raw="$(printf '%s' "$raw" | sed -E 's/,[[:space:]]*$//')" # retire virgule
|
||||||
|
raw="$(printf '%s' "$raw" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')" # trim
|
||||||
|
if [[ "$raw" =~ ^\"(.*)\"$ ]]; then printf '%s\n' "${BASH_REMATCH[1]}"; return; fi
|
||||||
|
if [[ "$raw" =~ ^\'(.*)\'$ ]]; then printf '%s\n' "${BASH_REMATCH[1]}"; return; fi
|
||||||
|
printf '%s\n' "$raw"
|
||||||
|
}
|
||||||
|
|
||||||
|
# placeholders à refuser (vides, “Voir…”, “CHANGEME…”, etc.)
|
||||||
|
is_placeholder() {
|
||||||
|
local v="$1"
|
||||||
|
[[ -z "$v" ]] && return 0
|
||||||
|
[[ "$v" =~ ^(Voir|voir|Nom|change|CHANGE|changeme|CHANGEME|todo|TODO|example|your|/path/to|A[[:space:]]*NOUS|A[[:space:]]*RETROUVER) ]] && return 0
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# entier (>=0)
|
||||||
|
is_int() { [[ "$1" =~ ^[0-9]+$ ]]; }
|
||||||
|
|
||||||
|
# booléen JS (true/false)
|
||||||
|
is_bool_literal() {
|
||||||
|
local v="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
|
||||||
|
[[ "$v" == "true" || "$v" == "false" ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# ────────── Paths ──────────
|
||||||
BIN_DIR="$HOME/bin"
|
BIN_DIR="$HOME/bin"
|
||||||
AUTOPOST_DIR="$HOME/autopost"
|
AUTOPOST_DIR="$HOME/autopost"
|
||||||
|
BASHRC_FILE="$HOME/.bashrc"
|
||||||
|
BASH_COMPLETION_DIR="$HOME/.bash_completion.d"
|
||||||
|
CONF_SH="$AUTOPOST_DIR/conf.sh"
|
||||||
|
CFG_JS="$AUTOPOST_DIR/config.js"
|
||||||
|
|
||||||
# Vérifier si le dossier bin existe, sinon le créer
|
mkdir -p "$BIN_DIR" "$AUTOPOST_DIR" "$BASH_COMPLETION_DIR" "$AUTOPOST_DIR/views" "$AUTOPOST_DIR/public"
|
||||||
echo -e "$BLEU""Vérification de la présence du dossier bin""$NORMAL"
|
|
||||||
if [ ! -d "$BIN_DIR" ]; then
|
|
||||||
mkdir -p "$BIN_DIR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Création des répertoires si inexistants
|
TMP_DIR="$(mktemp -d)"
|
||||||
mkdir -p "$AUTOPOST_DIR"
|
cleanup(){ rm -rf "$TMP_DIR"; }
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
# Télécharger les fichiers dans autopost
|
updated=0
|
||||||
|
errors=0
|
||||||
|
|
||||||
|
# ────────── MAJ fichiers distants ──────────
|
||||||
# Liste des fichiers à vérifier et mettre à jour
|
|
||||||
declare -A FILES
|
declare -A FILES
|
||||||
FILES["$HOME/autopost/analyzer.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh"
|
FILES["$AUTOPOST_DIR/analyzer.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/analyzer.sh"
|
||||||
FILES["$HOME/autopost/posteur.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh"
|
FILES["$AUTOPOST_DIR/posteur.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/posteur.sh"
|
||||||
FILES["$HOME/autopost/common.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh"
|
FILES["$AUTOPOST_DIR/common.sh"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/common.sh"
|
||||||
FILES["$HOME/bin/postauto"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto"
|
FILES["$BIN_DIR/postauto"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/bin/postauto"
|
||||||
FILES["$HOME/autopost/server.js"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js"
|
FILES["$AUTOPOST_DIR/server.js"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js"
|
||||||
|
FILES["$AUTOPOST_DIR/public/autopost.js"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/public/autopost.js"
|
||||||
|
FILES["$AUTOPOST_DIR/public/checkboxes.css"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/public/checkboxes.css"
|
||||||
|
FILES["$AUTOPOST_DIR/views/autopost.html"]="https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/views/autopost.html"
|
||||||
|
|
||||||
# Vérification et mise à jour des fichiers
|
log "Vérification/MAJ des fichiers…"
|
||||||
for LOCAL_FILE in "${!FILES[@]}"; do
|
for LOCAL in "${!FILES[@]}"; do
|
||||||
URL="${FILES[$LOCAL_FILE]}"
|
URL="${FILES[$LOCAL]}"
|
||||||
TMP_FILE=$(mktemp)
|
TMPF="$TMP_DIR/$(basename "$LOCAL").dl"
|
||||||
|
download "$URL" "$TMPF" || die "Téléchargement échoué: $URL"
|
||||||
|
|
||||||
# Télécharger le fichier distant
|
if [ ! -f "$LOCAL" ] || ! cmp -s "$LOCAL" "$TMPF"; then
|
||||||
curl -s "$URL" -o "$TMP_FILE"
|
cp -f "$LOCAL" "$LOCAL.bak" 2>/dev/null || true
|
||||||
|
case "$LOCAL" in
|
||||||
# Comparer avec le fichier local et mettre à jour si nécessaire
|
*postauto|*.sh) install_bin "$TMPF" "$LOCAL" ;;
|
||||||
if ! diff -q "$LOCAL_FILE" "$TMP_FILE" > /dev/null 2>&1; then
|
*) install -m 644 "$TMPF" "$LOCAL" ;;
|
||||||
#diff -u "$LOCAL_FILE" "$TMP_FILE" || echo "Le fichier local n'existe pas encore."
|
esac
|
||||||
echo "Mise à jour de $LOCAL_FILE..."
|
ok "Mise à jour: $LOCAL"
|
||||||
mv "$TMP_FILE" "$LOCAL_FILE"
|
updated=1
|
||||||
chmod +x "$LOCAL_FILE"
|
fi
|
||||||
updated="1"
|
|
||||||
else
|
|
||||||
rm "$TMP_FILE"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Définir le chemin du fichier bashrc
|
# ────────── Déplacer la complétion vers ~/.bash_completion.d & supprimer l'ancien bloc ──────────
|
||||||
BASHRC_FILE="$HOME/.bashrc"
|
|
||||||
|
|
||||||
# Marqueurs pour identifier la section ajoutée
|
|
||||||
DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO"
|
DEBUT_MARKER="# DEBUT COMPLETION POSTAUTO"
|
||||||
FIN_MARKER="# FIN COMPLETION POSTAUTO"
|
FIN_MARKER="# FIN COMPLETION POSTAUTO"
|
||||||
|
|
||||||
# Le code de complétion à ajouter, encadré par les marqueurs
|
if [ -f "$BASHRC_FILE" ] && grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then
|
||||||
read -r -d '' COMPLETION_CODE << 'EOF'
|
log "Suppression de l'ancien bloc de complétion dans $BASHRC_FILE…"
|
||||||
# DEBUT COMPLETION POSTAUTO
|
cp "$BASHRC_FILE" "${BASHRC_FILE}.bak"
|
||||||
# Fonction de complétion pour ton script
|
sed -i "/$DEBUT_MARKER/,/$FIN_MARKER/d" "$BASHRC_FILE"
|
||||||
|
ok "Ancien bloc supprimé."
|
||||||
|
updated=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMP_FILE="$BASH_COMPLETION_DIR/postauto"
|
||||||
|
COMPLETION_CODE=$(cat <<'EOF'
|
||||||
|
# completion postauto
|
||||||
_autopost_completion() {
|
_autopost_completion() {
|
||||||
local cur prev opts
|
local cur prev opts
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
opts="start stop restart show status createdb add log check update"
|
||||||
# Liste des commandes disponibles
|
|
||||||
opts="start stop restart show status createdb add log check update"
|
|
||||||
|
|
||||||
# Si l'utilisateur est en train de taper le premier argument, proposer les commandes
|
|
||||||
if [ $COMP_CWORD -eq 1 ]; then
|
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# (Optionnel) Pour la sous-commande "add", proposer des fichiers en complétion
|
|
||||||
if [ $COMP_CWORD -eq 2 ] && [ "${COMP_WORDS[1]}" = "add" ]; then
|
|
||||||
COMPREPLY=( $(compgen -f -- "${cur}") )
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Associer la fonction de complétion à ton script (ici, 'postauto' est le nom de la commande)
|
if [ $COMP_CWORD -eq 1 ]; then
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ); return 0
|
||||||
|
fi
|
||||||
|
if [ $COMP_CWORD -eq 2 ] && [ "${COMP_WORDS[1]}" = "add" ]; then
|
||||||
|
COMPREPLY=( $(compgen -f -- "${cur}") ); return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
complete -F _autopost_completion postauto
|
complete -F _autopost_completion postauto
|
||||||
# FIN COMPLETION POSTAUTO
|
|
||||||
EOF
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
# Vérifier si le code est déjà présent dans le fichier bashrc
|
if [ ! -s "$COMP_FILE" ] || ! cmp -s <(printf "%s" "$COMPLETION_CODE") "$COMP_FILE"; then
|
||||||
echo "Vérification et mise à jour de la configuration de complétion dans $BASHRC_FILE"
|
printf "%s" "$COMPLETION_CODE" > "$COMP_FILE"
|
||||||
|
ok "Completion installée: $COMP_FILE"
|
||||||
if grep -q "$DEBUT_MARKER" "$BASHRC_FILE"; then
|
grep -q '\.bash_completion.d/postauto' "$BASHRC_FILE" 2>/dev/null || \
|
||||||
# Extraire l'ancien bloc
|
echo '[ -f "$HOME/.bash_completion.d/postauto" ] && . "$HOME/.bash_completion.d/postauto"' >> "$BASHRC_FILE"
|
||||||
OLD_COMPLETION=$(sed -n "/$DEBUT_MARKER/,/$FIN_MARKER/p" "$BASHRC_FILE")
|
updated=1
|
||||||
|
|
||||||
# Comparer avec la nouvelle version
|
|
||||||
if [ "$OLD_COMPLETION" != "$COMPLETION_CODE" ]; then
|
|
||||||
echo "Mise à jour nécessaire, modification du bloc de complétion..."
|
|
||||||
|
|
||||||
# Faire une sauvegarde de sécurité du fichier .bashrc
|
|
||||||
cp "$BASHRC_FILE" "${BASHRC_FILE}.bak"
|
|
||||||
echo "Sauvegarde réalisée dans ${BASHRC_FILE}.bak"
|
|
||||||
|
|
||||||
# Supprimer l'ancien bloc
|
|
||||||
sed -i "/$DEBUT_MARKER/,/$FIN_MARKER/d" "$BASHRC_FILE"
|
|
||||||
|
|
||||||
# Ajouter une ligne vide pour séparer (optionnel)
|
|
||||||
echo "" >> "$BASHRC_FILE"
|
|
||||||
|
|
||||||
# Ajouter le nouveau code de complétion
|
|
||||||
echo "$COMPLETION_CODE" >> "$BASHRC_FILE"
|
|
||||||
echo "Mise à jour effectuée."
|
|
||||||
updated="1"
|
|
||||||
else
|
|
||||||
echo "Aucune modification nécessaire, le bloc est déjà à jour."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Ajouter le bloc si absent
|
|
||||||
echo "Ajout du bloc de complétion..."
|
|
||||||
echo "" >> "$BASHRC_FILE"
|
|
||||||
echo "$COMPLETION_CODE" >> "$BASHRC_FILE"
|
|
||||||
echo "Ajout terminé."
|
|
||||||
updated="1"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Vérification de l'environnement pour la page de suivi..."
|
# ────────── Outils externes (optionnel: installe si manquants) ──────────
|
||||||
|
ensure_cmd(){ command -v "$1" >/dev/null 2>&1; }
|
||||||
|
|
||||||
# Fonction pour afficher les messages en vert
|
if ! ensure_cmd 7z; then
|
||||||
log() {
|
log "Installation 7z…"
|
||||||
echo -e "\033[1;32m$1\033[0m"
|
pushd "$TMP_DIR" >/dev/null
|
||||||
|
download "https://7-zip.org/a/7z2409-linux-x64.tar.xz" "$TMP_DIR/7z.tar.xz" || die "Téléchargement 7z"
|
||||||
|
tar -xJf "$TMP_DIR/7z.tar.xz"
|
||||||
|
ZBIN="$(find . -maxdepth 1 -type f -name '7zz*' -perm -u+x | head -n1)"
|
||||||
|
[ -n "$ZBIN" ] || die "Binaire 7z introuvable"
|
||||||
|
install_bin "$ZBIN" "$BIN_DIR/7z"
|
||||||
|
popd >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! ensure_cmd BDInfo; then
|
||||||
|
log "Installation BDInfo…"
|
||||||
|
pushd "$TMP_DIR" >/dev/null
|
||||||
|
download "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfo_linux_v2.0.6.zip" "$TMP_DIR/bdinfo.zip" \
|
||||||
|
|| die "Téléchargement BDInfo"
|
||||||
|
unzip -q "$TMP_DIR/bdinfo.zip"
|
||||||
|
BDBIN="$(find . -type f -name BDInfo -perm -u+x | head -n1)"
|
||||||
|
[ -n "$BDBIN" ] || die "BDInfo introuvable"
|
||||||
|
install_bin "$BDBIN" "$BIN_DIR/BDInfo"
|
||||||
|
popd >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! ensure_cmd BDInfoDataSubstractor; then
|
||||||
|
log "Installation BDInfoDataSubstractor…"
|
||||||
|
pushd "$TMP_DIR" >/dev/null
|
||||||
|
download "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfodatasubstractor_linux_v2.0.6.zip" "$TMP_DIR/substractor.zip" \
|
||||||
|
|| die "Téléchargement BDInfoDataSubstractor"
|
||||||
|
unzip -q "$TMP_DIR/substractor.zip"
|
||||||
|
SBBIN="$(find . -type f -name BDInfoDataSubstractor -perm -u+x | head -n1)"
|
||||||
|
[ -n "$SBBIN" ] || die "BDInfoDataSubstractor introuvable"
|
||||||
|
install_bin "$SBBIN" "$BIN_DIR/BDInfoDataSubstractor"
|
||||||
|
popd >/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Modules npm locaux dans $AUTOPOST_DIR
|
||||||
|
log "Vérification modules npm"
|
||||||
|
pushd "$AUTOPOST_DIR" >/dev/null
|
||||||
|
[ -f package.json ] || npm init -y >/dev/null 2>&1 || true
|
||||||
|
modules=(express express-session sqlite3 ansi-to-html @tailwindcss/browser autoprefixer jquery mysql2 session-file-store chokidar)
|
||||||
|
missing=()
|
||||||
|
for m in "${modules[@]}"; do
|
||||||
|
npm list "$m" --depth=0 >/dev/null 2>&1 || missing+=("$m")
|
||||||
|
done
|
||||||
|
if [ "${#missing[@]}" -gt 0 ]; then
|
||||||
|
log "Installation modules: ${missing[*]}"
|
||||||
|
npm install "${missing[@]}"
|
||||||
|
else
|
||||||
|
ok "Tous les modules npm sont présents"
|
||||||
|
fi
|
||||||
|
popd >/dev/null
|
||||||
|
|
||||||
|
# ────────── VALIDATION conf.sh (sans exécuter) ──────────
|
||||||
|
check_conf() {
|
||||||
|
local file="$CONF_SH"
|
||||||
|
[[ -f "$file" ]] || { err "Manquant: $file"; errors=$((errors+1)); return; }
|
||||||
|
|
||||||
|
log "Validation déclarative de $file…"
|
||||||
|
|
||||||
|
declare -A V=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ "$line" =~ ^[[:space:]]*# ]] && continue
|
||||||
|
[[ "$line" =~ ^[[:space:]]*$ ]] && continue
|
||||||
|
line="${line#export }"
|
||||||
|
if [[ "$line" =~ ^[[:space:]]*([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=(.*)$ ]]; then
|
||||||
|
name="${BASH_REMATCH[1]}"
|
||||||
|
val="${BASH_REMATCH[2]}"
|
||||||
|
val="${val%%#*}"; val="${val%%;*}"
|
||||||
|
val="$(echo -n "$val" | sed -E "s/^[[:space:]]*['\"]?//; s/['\"]?[[:space:]]*$//")"
|
||||||
|
V["$name"]="$val"
|
||||||
|
fi
|
||||||
|
done < "$file"
|
||||||
|
|
||||||
|
for k in URL_API APIKEY DOSSIER_GLOBAL DOSSIER_NFO DOSSIER_LOGS DOSSIER_NZB_ATTENTE DOSSIER_NZB_FINAL MOVE_CMD MYSQL_TABLE dbtype; do
|
||||||
|
v="${V[$k]:-}"
|
||||||
|
if is_placeholder "$v"; then
|
||||||
|
err "conf.sh: '$k' non renseigné"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
case "${V[MOVE_CMD]:-}" in
|
||||||
|
"cp -rl"|"cp -rs"|"ln -s"|"mv"|"cp") : ;;
|
||||||
|
*)
|
||||||
|
err "conf.sh: MOVE_CMD invalide ('${V[MOVE_CMD]:-}'), attendus: cp -rl|cp -rs|ln -s|mv|cp"
|
||||||
|
errors=$((errors+1))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
for k in NG_HOST NG_USER NG_PASS; do
|
||||||
|
if is_placeholder "${V[$k]:-}"; then
|
||||||
|
err "conf.sh: '$k' non renseigné"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if ! [[ "${V[NG_PORT]:-}" =~ ^[0-9]+$ ]]; then
|
||||||
|
err "conf.sh: NG_PORT doit être numérique"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
if ! [[ "${V[NG_NBR_CONN]:-}" =~ ^[0-9]+$ ]]; then
|
||||||
|
err "conf.sh: NG_NBR_CONN doit être numérique"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "${V[dbtype]:-}" in
|
||||||
|
sqlite)
|
||||||
|
if is_placeholder "${V[DB_FILE]:-}"; then
|
||||||
|
err "conf.sh: DB_FILE requis en mode sqlite"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
mysql)
|
||||||
|
for k in MYSQL_HOST MYSQL_USER MYSQL_PASS MYSQL_DB; do
|
||||||
|
if is_placeholder "${V[$k]:-}"; then
|
||||||
|
err "conf.sh: '$k' requis en mode mysql"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if ! [[ "${V[MYSQL_PORT]:-}" =~ ^[0-9]+$ ]]; then
|
||||||
|
err "conf.sh: MYSQL_PORT doit être numérique"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "conf.sh: dbtype doit être 'sqlite' ou 'mysql' (actuel='${V[dbtype]:-}')"
|
||||||
|
errors=$((errors+1))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# Définition du répertoire AUTOPOST_DIR (ajuster si nécessaire)
|
# ────────── VALIDATION config.js (avec Node) ──────────
|
||||||
AUTOPOST_DIR="$HOME/autopost"
|
validate_config_js() {
|
||||||
|
[[ -f "$CFG_JS" ]] || { err "Manquant: $CFG_JS"; errors=$((errors+1)); return; }
|
||||||
|
log "Validation déclarative de $CFG_JS…"
|
||||||
|
|
||||||
# Création du dossier si inexistant
|
local dbtype port name secret table
|
||||||
mkdir -p "$AUTOPOST_DIR"
|
dbtype="$(normalize_js_value "$(parse_js_raw dbtype)")"
|
||||||
|
port="$(normalize_js_value "$(parse_js_raw port)")"
|
||||||
|
name="$(normalize_js_value "$(parse_js_raw name)")"
|
||||||
|
secret="$(normalize_js_value "$(parse_js_raw sessionSecret)")"
|
||||||
|
table="$(normalize_js_value "$(parse_js_raw DB_TABLE)")"
|
||||||
|
|
||||||
# Définir le répertoire NVM
|
if ! is_int "$port" || (( port < 1 || port > 65535 )); then
|
||||||
export NVM_DIR="$HOME/.nvm"
|
err "config.js: 'port' invalide ($port)"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
if is_placeholder "$name"; then err "config.js: 'name' non renseigné"; errors=$((errors+1)); fi
|
||||||
|
if is_placeholder "$secret"; then err "config.js: 'sessionSecret' non renseigné"; errors=$((errors+1)); fi
|
||||||
|
if is_placeholder "$table"; then err "config.js: 'DB_TABLE' non renseigné"; errors=$((errors+1)); fi
|
||||||
|
|
||||||
# Vérifier si nvm est déjà chargé dans la session actuelle
|
for key in finishdirectory logdirectory infodirectory; do
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
val="$(normalize_js_value "$(parse_js_raw "$key")")"
|
||||||
log "nvm est déjà installé. Chargement de nvm..."
|
if is_placeholder "$val"; then
|
||||||
\. "$NVM_DIR/nvm.sh"
|
err "config.js: '$key' non renseigné"; errors=$((errors+1))
|
||||||
else
|
fi
|
||||||
log "nvm non trouvé, installation de nvm..."
|
done
|
||||||
# Installer nvm
|
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
|
local tp cs ssp
|
||||||
|
tp="$(normalize_js_value "$(parse_js_raw trustProxy)")"
|
||||||
# Après l'installation, sourcer nvm pour la session courante
|
cs="$(normalize_js_value "$(parse_js_raw cookieSecure)")"
|
||||||
export NVM_DIR="$HOME/.nvm"
|
ssp="$(normalize_js_value "$(parse_js_raw sessionStorePath)")"
|
||||||
if [ -s "$NVM_DIR/nvm.sh" ]; then
|
|
||||||
\. "$NVM_DIR/nvm.sh"
|
if is_placeholder "$tp"; then
|
||||||
log "NVM installé et chargé."
|
err "config.js: 'trustProxy' non renseigné"; errors=$((errors+1))
|
||||||
else
|
else
|
||||||
log "Erreur : nvm n'a pas pu être chargé."
|
if is_int "$tp"; then
|
||||||
exit 1
|
if (( tp < 0 )); then
|
||||||
|
err "config.js: 'trustProxy' doit être >= 0 (valeur=$tp)"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! is_bool_literal "$cs"; then
|
||||||
|
err "config.js: 'cookieSecure' doit être true ou false (valeur='$cs')"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if is_placeholder "$ssp"; then
|
||||||
|
err "config.js: 'sessionStorePath' non renseigné"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$dbtype" in
|
||||||
|
sqlite)
|
||||||
|
val="$(normalize_js_value "$(parse_js_raw dbFile)")"
|
||||||
|
if is_placeholder "$val"; then
|
||||||
|
err "config.js: 'dbFile' requis (sqlite)"; errors=$((errors+1))
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
mysql)
|
||||||
|
local H P U PW DB
|
||||||
|
H="$(normalize_js_value "$(parse_js_raw DB_HOST)")"
|
||||||
|
P="$(normalize_js_value "$(parse_js_raw DB_PORT)")"
|
||||||
|
U="$(normalize_js_value "$(parse_js_raw DB_USER)")"
|
||||||
|
PW="$(normalize_js_value "$(parse_js_raw DB_PASSWORD)")"
|
||||||
|
DB="$(normalize_js_value "$(parse_js_raw DB_DATABASE)")"
|
||||||
|
if is_placeholder "$H"; then err "config.js: 'DB_HOST' requis (mysql)"; errors=$((errors+1)); fi
|
||||||
|
if ! is_int "$P"; then err "config.js: 'DB_PORT' entier requis (mysql)"; errors=$((errors+1)); fi
|
||||||
|
if is_placeholder "$U"; then err "config.js: 'DB_USER' requis (mysql)"; errors=$((errors+1)); fi
|
||||||
|
if is_placeholder "$PW"; then err "config.js: 'DB_PASSWORD' requis (mysql)"; errors=$((errors+1)); fi
|
||||||
|
if is_placeholder "$DB"; then err "config.js: 'DB_DATABASE' requis (mysql)"; errors=$((errors+1)); fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "config.js: 'dbtype' doit être 'sqlite' ou 'mysql' (actuel='$dbtype')"
|
||||||
|
errors=$((errors+1))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
check_conf "$CONF_SH"
|
||||||
|
validate_config_js
|
||||||
|
|
||||||
|
# ────────── Résumé & exit codes ──────────
|
||||||
|
if [ "$updated" -eq 1 ]; then
|
||||||
|
warn "Mises à jour appliquées — relance: 'postauto restart'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Vérification de Node.js
|
if [ "$errors" -gt 0 ]; then
|
||||||
if command -v node &> /dev/null; then
|
err "Des problèmes de configuration ont été détectés (${errors}). Corrige-les puis relance l’update."
|
||||||
current_version=$(node -v | sed 's/^v//')
|
exit 2
|
||||||
major_version=$(echo "$current_version" | cut -d. -f1)
|
else
|
||||||
if [ "$major_version" -lt 22 ]; then
|
ok "Configuration OK."
|
||||||
log "Node.js version $current_version détectée (inférieure à 22). Mise à jour en cours..."
|
fi
|
||||||
nvm install 22
|
|
||||||
nvm use 22
|
# auto-suppression (désactivable via SKIP_SELF_DELETE=1)
|
||||||
|
if [ -z "${SKIP_SELF_DELETE:-}" ] && [ -f "$SCRIPT_FILE" ]; then
|
||||||
|
if rm -f -- "$SCRIPT_FILE"; then
|
||||||
|
ok "Script supprimé: $SCRIPT_FILE"
|
||||||
else
|
else
|
||||||
log "Node.js version $current_version détectée, compatible."
|
warn "Impossible de supprimer $SCRIPT_FILE (droits sur le dossier ?)"
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
log "Node.js non trouvé, installation de Node.js 22..."
|
|
||||||
nvm install 22
|
|
||||||
nvm use 22
|
|
||||||
updated="1"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Charger nvm après installation
|
|
||||||
export NVM_DIR="$HOME/.nvm"
|
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
|
||||||
|
|
||||||
# Vérification des modules npm nécessaires
|
|
||||||
log "Vérification des modules npm requis..."
|
|
||||||
|
|
||||||
modules=("express" "express-session" "sqlite3" "ansi-to-html" "@tailwindcss/browser" "jquery" "mysql2")
|
|
||||||
missing_modules=()
|
|
||||||
|
|
||||||
for module in "${modules[@]}"; do
|
|
||||||
# On regarde uniquement les dépendances directes et on vérifie si le module apparaît dans la sortie.
|
|
||||||
if ! npm list "$module" --depth=0 2>&1 | grep -q "$module@"; then
|
|
||||||
missing_modules+=("$module")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ${#missing_modules[@]} -gt 0 ]; then
|
|
||||||
log "Modules manquants détectés : ${missing_modules[*]}"
|
|
||||||
npm install "${missing_modules[@]}"
|
|
||||||
else
|
|
||||||
log "Tous les modules requis sont déjà installés."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vérification et téléchargement des fichiers de configuration
|
|
||||||
log "Vérification des fichiers de configuration..."
|
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/server.js" ]; then
|
|
||||||
log "Téléchargement de server.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/server.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/server.js"
|
|
||||||
updated="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/db.js" ]; then
|
|
||||||
log "Téléchargement de db.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/db.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/db.js"
|
|
||||||
updated="1"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "$AUTOPOST_DIR/config.js" ]; then
|
|
||||||
log "Téléchargement de config.js..."
|
|
||||||
wget -q -O "$AUTOPOST_DIR/config.js" "https://tig.unfr.pw/UNFR/postauto/raw/branch/main/autopost/config.js"
|
|
||||||
echo -e "${BLEU}Installation terminée. Vous pouvez maintenant configurer $AUTOPOST_DIR/config.js.${NORMAL}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Vérifier et installer 7z si manquant
|
|
||||||
if command -v 7z > /dev/null 2>&1; then
|
|
||||||
LISTE_APPLIS+=("7z")
|
|
||||||
else
|
|
||||||
echo -e "${ROUGE}7z est manquant. Installation en cours...${NORMAL}"
|
|
||||||
Z_URL="https://7-zip.org/a/7z2409-linux-x64.tar.xz"
|
|
||||||
Z_TAR="7z2409-linux-x64.tar.xz"
|
|
||||||
Z_DIR="7z2409-linux-x64"
|
|
||||||
Z_EXE="7zzs"
|
|
||||||
wget -q -O "$Z_TAR" "$Z_URL"
|
|
||||||
tar -xJf "$Z_TAR" > /dev/null 2>&1
|
|
||||||
mv "$Z_EXE" "$BIN_DIR/7z"
|
|
||||||
rm "$Z_TAR" 7zz
|
|
||||||
chmod 777 "$BIN_DIR/7z"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/7z")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vérifier et installer BDInfo si manquant
|
|
||||||
if command -v BDInfo > /dev/null 2>&1; then
|
|
||||||
LISTE_APPLIS+=("BDInfo")
|
|
||||||
else
|
|
||||||
echo -e "${ROUGE}BDInfo est manquant. Installation en cours...${NORMAL}"
|
|
||||||
curl -L -o bdinfo_linux_v2.0.6.zip "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfo_linux_v2.0.6.zip"
|
|
||||||
unzip bdinfo_linux_v2.0.6.zip -d "$BIN_DIR"
|
|
||||||
chmod 777 "$BIN_DIR/BDInfo"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/BDInfo")
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Vérifier et installer BDInfo si manquant
|
|
||||||
if command -v BDInfoDataSubstractor > /dev/null 2>&1; then
|
|
||||||
LISTE_APPLIS+=("BDInfoDataSubstractor")
|
|
||||||
else
|
|
||||||
echo -e "${ROUGE}BDInfoDataSubstractor est manquant. Installation en cours...${NORMAL}"
|
|
||||||
curl -L -o bdinfodatasubstractor_linux_v2.0.6.zip "https://github.com/dotnetcorecorner/BDInfo/releases/download/linux-2.0.6/bdinfodatasubstractor_linux_v2.0.6.zip"
|
|
||||||
unzip bdinfodatasubstractor_linux_v2.0.6.zip -d "$BIN_DIR"
|
|
||||||
chmod 777 "$BIN_DIR/BDInfoDataSubstractor"
|
|
||||||
LISTE_APPLIS+=("$BIN_DIR/BDInfoDataSubstractor")
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
#echo -e "${ROUGE}Merci d'aller lire le readme pour compresser vos anciens NZB${NORMAL}"
|
|
||||||
|
|
||||||
if [ $updated = "1" ]; then
|
|
||||||
echo -e "${ROUGE}Mise à jour effectué merci de relancer la commande 'postauto restart'${NORMAL}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#echo "Suppression du script après exécution..."
|
|
||||||
rm -- "$0"
|
|
||||||
Reference in New Issue
Block a user