Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

Commit

Permalink
fin de l'application debian
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin GRONDIN committed Dec 21, 2020
0 parents commit e55d821
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package-lock.json
yarn.lock
debian/changelog
node_modules
92 changes: 92 additions & 0 deletions README.md
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
```
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
11 changes: 11 additions & 0 deletions debian/control
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
1 change: 1 addition & 0 deletions debian/dirs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
etc/sendmailer
2 changes: 2 additions & 0 deletions debian/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
README.md
exemple.env
3 changes: 3 additions & 0 deletions debian/install
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
11 changes: 11 additions & 0 deletions debian/rules
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
13 changes: 13 additions & 0 deletions debian/sendmailer.service
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
14 changes: 14 additions & 0 deletions debian/[email protected]
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
3 changes: 3 additions & 0 deletions exemple.env
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]
18 changes: 18 additions & 0 deletions package.json
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"
}
}
36 changes: 36 additions & 0 deletions sendmailer.js
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);
}
});
})();

0 comments on commit e55d821

Please sign in to comment.