This repository has been archived by the owner on Dec 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin GRONDIN
committed
Dec 21, 2020
0 parents
commit e55d821
Showing
13 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package-lock.json | ||
yarn.lock | ||
debian/changelog | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# SendMail | ||
|
||
> Ce projet m'a permis de savoir comment on package un service sous debian manuellement | ||
Le système de template de service permet de rendre chaque projet indépendant | ||
|
||
## Prérequies | ||
|
||
Si vous utilisez gmail il faut autoriser l'utilisation de votre login et mot de passe | ||
|
||
cliquez [ici]( https://www.google.com/accounts/DisplayUnlockCaptcha) pour forcer | ||
|
||
## Dependences pour le packaging | ||
|
||
Télécharger le dpkg_changelog [ici](http://deb.regdrasil.com/) en __root__ | ||
|
||
```Shell | ||
echo "deb http://deb.regdrasil.com/apt/debian regdrasil main" > /etc/apt/sources.list.d/regdrasil.com.list | ||
|
||
wget -O - http://deb.regdrasil.com/apt/debian/regdrasil.gpg.key | apt-key add - | ||
|
||
# Installer les MAJ | ||
apt update | ||
``` | ||
|
||
```Shell | ||
apt-get install dh-make dpkg-changelog git | ||
``` | ||
|
||
## Dossier Debian | ||
|
||
Voici le contenu du dossier debian | ||
|
||
```Config | ||
changelog : journal des modifications | ||
compat: | ||
control: métadonnées sur le paquet (dépendances) | ||
dh_install ( *.dirs, *.docs, *.manpages...) | ||
install : | ||
rules : | ||
``` | ||
|
||
## Builder | ||
|
||
- faire un premier commit | ||
- Modifier la version dans `debian/control` | ||
- `ctrl+shift+p` pour creer un tag avec __create:tag__ | ||
- tapez la version exemple __1.0.0__ arrivez au message même chose | ||
- Un nouveau commit avec pour message uniquement le numéro version | ||
- `dpkg-changelog` | ||
- `dpkg-buildpackage -us -uc -b` pour builder un .deb ( /!\ le build n'est pas construit dans le répertoire courant, mais un niveau au dessus ) | ||
- `dpkg-buildpackage -Tclean` pour effacer les traces de build | ||
- `dpkg -i` suivi du .deb créé dans le repertoire parent du projet | ||
|
||
## Execute service | ||
|
||
Initialiser le projet | ||
|
||
``` | ||
# Ce rendre dans sendmailer | ||
/etc/sendmailer | ||
# Creer un dossier | ||
mkdir projet1 | ||
# Creer votre fichier `.env` avec l'exemple dans /usr/share/doc/sendmailer | ||
``` | ||
|
||
`.env` | ||
|
||
```Env | ||
[email protected] | ||
PASS_SENDER=monmotdepasse | ||
[email protected] | ||
``` | ||
|
||
Lancer le service ( recommandé pour une crontab ) | ||
|
||
``` | ||
/bin/systemctl start sendmailer@projet1 | ||
``` | ||
|
||
Regarder le service | ||
|
||
``` | ||
# | ||
## Rappel journalctl : -t pour definir un tag, et -u pour les services comme ici | ||
# | ||
# rajouté pour l'argument -f pour visualiser en direct | ||
journalctl -u sendmailer@projet1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Source: sendmailer | ||
Build-Depends: debhelper (>= 9), npm | ||
Section: base | ||
Priority: optional | ||
Maintainer: Kevin grondin <[email protected]> | ||
Standards-Version: 1.1.2 | ||
|
||
Package: sendmailer | ||
Architecture: all | ||
Depends: nodejs | ||
Description: Send dog by email without node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
etc/sendmailer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
README.md | ||
exemple.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
sendmailer.js usr/share/sendmailer | ||
package.json usr/share/sendmailer | ||
node_modules usr/share/sendmailer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/make -f | ||
|
||
DPKG_EXPORT_BUILDFLAGS = 1 | ||
include /usr/share/dpkg/default.mk | ||
|
||
|
||
%: | ||
dh $@ --with systemd | ||
|
||
override_dh_auto_build: | ||
npm run get:install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Unit] | ||
Description=sendmailer parent service | ||
After=network.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/bin/true | ||
ExecReload=/bin/true | ||
WorkingDirectory=/etc/sendmailer | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=sendmailer %I | ||
After=syslog.target | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
Restart=no | ||
WorkingDirectory=/etc/sendmailer/%i | ||
ExecStart=/usr/bin/node /usr/share/sendmailer/sendmailer.js | ||
RuntimeMaxSec=240 | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MAIL_SENDER=[email protected] | ||
PASS_SENDER=monmotdepasse | ||
MAIL_RECEIVER=[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "sendmail", | ||
"version": "1.0.0", | ||
"description": "Journée du chien", | ||
"main": "sendmailer.js", | ||
"scripts": { | ||
"get:install": "npm install" | ||
}, | ||
"keywords": [], | ||
"author": "kevin grondin", | ||
"license": "ISC", | ||
"dependencies": { | ||
"axios": "^0.21.0", | ||
"dotenv": "^8.2.0", | ||
"nodemailer": "^6.4.17", | ||
"nodemailer-smtp-transport": "^2.7.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const smtpTransport = require('nodemailer-smtp-transport'); | ||
const nodemailer = require('nodemailer'); | ||
const axios = require("axios"); | ||
const config = require('dotenv').config(); | ||
|
||
(async () => { | ||
const transporter = nodemailer.createTransport(smtpTransport({ | ||
service: 'gmail', | ||
host: 'smtp.gmail.com', | ||
auth: { | ||
user: process.env.MAIL_SENDER, | ||
pass: process.env.PASS_SENDER | ||
} | ||
})); | ||
|
||
const subject = "Journée du chien" | ||
let { data } = await axios.get("https://api.thedogapi.com/v1/images/search") | ||
let {url} = data[0] | ||
|
||
const message = `Le chien du jour 😁 <br/><img src="${url}" width="300px">` | ||
|
||
const mailOptions = { | ||
from: process.env.MAIL_SENDER, | ||
to: process.env.MAIL_RECEIVER, | ||
subject: subject, | ||
html: message | ||
}; | ||
|
||
transporter.sendMail(mailOptions, function(error, info){ | ||
if (error) { | ||
console.error(error); | ||
} else { | ||
console.info('Email sent: ' + info.response); | ||
} | ||
}); | ||
})(); |