137 lines
4.7 KiB
Markdown
137 lines
4.7 KiB
Markdown
# utils
|
|
|
|
Small tools needed to solve immediate tasks independently or as part of a project
|
|
|
|
* [`build-python`.sh](https://git.hmp.today/pavel.muhortov/utils#build-python-sh)
|
|
* [`sendmail`.py](https://git.hmp.today/pavel.muhortov/utils#sendmail-py)
|
|
* [`simplewc`.py](https://git.hmp.today/pavel.muhortov/utils#simplewc-py)
|
|
|
|
____
|
|
|
|
## `build-python`.sh
|
|
|
|
**Description:**
|
|
> Building Python from sources.
|
|
|
|
**Dependencies:**
|
|
>
|
|
> * [bash](https://www.gnu.org/software/bash/) (tested versions: 5.1.4 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/), 5.0.17 on [Ubuntu 20](https://wiki.ubuntu.com/FocalFossa/ReleaseNotes), 4.2.46 on [CentOS 7](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS7.2009))
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|-----------|--------------|------------------------|---------------|
|
|
| 1 |**[qn]**|execution without pauses||
|
|
| 2 |**[version]**|version of Python|`3.9.5`|
|
|
| 3 |**[path/to/log]**|path to log|`/dev/null`|
|
|
|
|
Example usage in terminal with make the script executable:
|
|
|
|
```bash
|
|
wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh
|
|
chmod u+x ./build-python.sh
|
|
sudo ./build-python.sh - 3.9.5
|
|
```
|
|
|
|
Example usage in terminal without download:
|
|
|
|
```bash
|
|
sudo su - -c "bash <(curl -s https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/build-python.sh) qn 3.9.5 install-python.log"
|
|
```
|
|
|
|
____
|
|
|
|
## `sendmail`.py
|
|
|
|
**Description:**
|
|
> Sending email from Python.
|
|
|
|
**Dependencies:**
|
|
>
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
| PARAMETERS | DESCRIPTION | DEFAULT|
|
|
|-------------|-------------|--------|
|
|
|**-u**, **--user**|smtp valid user|**REQUIRED**|
|
|
|**-p**, **--pass**|smtp valid password|**REQUIRED**|
|
|
|**-d**, **--dest**|destination addresses|**REQUIRED**|
|
|
|**[-h]**|print help and exit||
|
|
|**[--smtp]**|smtp hostname or ip address|smtp.gmail.com|
|
|
|**[--port]**|smtp port number|587|
|
|
|**[--stls]**|smtp required TLS|`True`|
|
|
|**[--from]**|mail from alias|**--user** value|
|
|
|**[--subj]**|mail subject|'no subject'|
|
|
|**[--text]**|mail body text|'no text'|
|
|
|**[--type]**|mail body type: plain, html|plain|
|
|
|**[--file]**|mail attachment files|`None`|
|
|
|**[--time]**|minutes of attempts to send|3|
|
|
|
|
Example usage in terminal:
|
|
|
|
```bash
|
|
# download
|
|
sudo wget https://git.hmp.today/pavel.muhortov/utils/raw/branch/master/sendmail.py -O /usr/local/bin/sendmail.py
|
|
sudo chmod +x /usr/local/bin/sendmail.py
|
|
```
|
|
|
|
```bash
|
|
# example 1
|
|
sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com
|
|
```
|
|
|
|
```bash
|
|
# example 2
|
|
/usr/local/opt/python-3.9/bin/python3.9 /usr/local/bin/sendmail.py -u user@gmail.com -p pass -d addr1@gmail.com,addr2@gmail.com --file "/path/to/file1,/path/to/file2"
|
|
```
|
|
|
|
Example usage in Python:
|
|
|
|
```Python
|
|
from sendmail import Mail
|
|
|
|
msg = Mail(smtp_user='user@gmail.com', smtp_pass='pass', mail_dest='addr1@gmail.com,addr2@gmail.com')
|
|
log = msg.send()
|
|
print(log)
|
|
```
|
|
|
|
____
|
|
|
|
## `simplewc`.py
|
|
|
|
**Description:**
|
|
> Update Let's Encrypt wildcard certificate with DNS-01 challenge.
|
|
|
|
**Dependencies:**
|
|
>
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
> * installed or downloaded [acme.sh](https://github.com/Neilpang/acme.sh)
|
|
> * installed [dnspython](https://github.com/rthalley/dnspython) package
|
|
> * dns is supported to [dynamic update](https://en.wikipedia.org/wiki/Dynamic_DNS)
|
|
|
|
| PARAMETERS | DESCRIPTION | DEFAULT|
|
|
|-------------|-------------|--------|
|
|
|**--domain**|domain for which the wildcard certificate is issued|**REQUIRED**|
|
|
|**--server**|master server containing the domain zone|**REQUIRED**|
|
|
|**--keyname**|name of the key to update the zone|**REQUIRED**|
|
|
|**--keydata**|content of the key to update the zone|**REQUIRED**|
|
|
|**[-h]**|print help and exit||
|
|
|**[--acmepath]**|alternative path to bin (example: ~/.acme.sh/acme.sh)|`None`|
|
|
|**[--force]**|"force" argument for the acme.sh|`False`|
|
|
|**[--test]**|"test" argument for the acme.sh|`False`|
|
|
|
|
Example usage in cron with Python:
|
|
|
|
```bash
|
|
# at 00:00 on Monday
|
|
0 0 * * 1 /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT > /dev/null
|
|
# 00:00 on day-of-month 1 and 15
|
|
0 0 1,15 * * /usr/bin/python3 ~/simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY > /dev/null
|
|
|
|
```
|
|
|
|
Example usage in terminal with make the script executable:
|
|
|
|
```bash
|
|
chmod u+x ./simplewc.py
|
|
./simplewc.py --domain EXAMPLE.COM --server 8.8.8.8 --keyname KEY --keydata YOU_KEY_CONTENT --test --force
|
|
./simplewc.py --domain EXAMPLE.COM --server dyn.dns.he.net --keyname - --keydata YOU_DDNSKEY --test --force
|
|
```
|