Skip to content

Commit

Permalink
Added docs workflows and CQ improvements
Browse files Browse the repository at this point in the history
* Updated script for also clearing Journal Logs
* Added docker stacks
* Automated documentation and secret scanning (#6)
* Improved code quality and docs auto-workflow (#7)
* Improved CQ and docs workflow
* Fix for SH-2059, SH-2005, SH-2027, SH-1083 and more
  • Loading branch information
bearlike committed Apr 10, 2022
1 parent de2ed5e commit ad6b3f8
Show file tree
Hide file tree
Showing 32 changed files with 759 additions and 84 deletions.
6 changes: 1 addition & 5 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
version = 1

[[analyzers]]
name = "secrets"
enabled = true

[[analyzers]]
name = "shell"
enabled = true
Expand All @@ -13,7 +9,7 @@ name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
runtime_version = "3.7.x"

[[transformers]]
name = "autopep8"
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/check_and_generate_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Check and generate documentations

on:
push:

jobs:
check:
name: Check if generating is necessary
outputs:
run_job: ${{ steps.check_files.outputs.run_job }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 3

- name: Check modified files
id: check_files
run: |
echo "=============== List modified files ==============="
git diff --name-only HEAD^ HEAD
echo "========== Check paths of modified files =========="
git diff --name-only HEAD^ HEAD > files.txt
while IFS= read -r file
do
echo $file
if [[ $file != docs/* ]]; then
echo "This modified file is not under the 'docs' folder."
echo "::set-output name=run_job::false"
break
else
echo "::set-output name=run_job::true"
fi
done < files.txt
update:
name: Update documentation
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.run_job == 'true'
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 1 # otherwise, there would be errors pushing refs to the destination repository.
- uses: actions/setup-python@v3
with:
python-version: "3.9"
cache: "pip"
- name: Updating scripts table in README.md
run: |
cd "docs/templates/" && pip install -r requirements.txt && python update_scripts_table.py
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "Krishna Alagiri [bot]"
git commit -m "[skip ci] Updating documentation" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_TOKEN }}
branch: ${{ github.ref }}
31 changes: 31 additions & 0 deletions .github/workflows/generate_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Generate Documentations

on:
workflow_dispatch:

jobs:
update:
name: Update documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 1 # otherwise, there would be errors pushing refs to the destination repository.
- uses: actions/setup-python@v3
with:
python-version: "3.9"
cache: "pip"
- name: Updating scripts table in README.md
run: |
cd "docs/templates/" && pip install -r requirements.txt && python update_scripts_table.py
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "Krishna Alagiri [bot]"
git commit -m "[skip ci] Updating documentation" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_TOKEN }}
branch: ${{ github.ref }}
21 changes: 21 additions & 0 deletions .github/workflows/scan_secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Scan for leaked secrets (keys, tokens, etc.)

on: [push, pull_request]

jobs:
scanning:
name: GitGuardian scan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # fetch all history so multiple commits can be scanned
- name: GitGuardian scan
uses: GitGuardian/ggshield-action@master
env:
GITHUB_PUSH_BEFORE_SHA: ${{ github.event.before }}
GITHUB_PUSH_BASE_SHA: ${{ github.event.base }}
GITHUB_PULL_BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
GITGUARDIAN_API_KEY: ${{ secrets.GITGUARDIAN_API_KEY }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,5 @@ dmypy.json
.vscode/

# Enviroinment variable file
.env
.env
docs/~$scripts.xlsx
46 changes: 32 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

<!-- Generated on 2022-04-10 12:07:44+00:00 -->
<!-- Do not edit this file. Edit README.md/base.md.j2 instead. -->
# Scripts
Collection of automation scripts. Use it if you have the same purpose.

Expand All @@ -9,24 +12,39 @@ Got scripts? See [Contributing](.github/CONTRIBUTING.md).

## Lot of Scripts

| **Title** | **Filename** | **Type** | **Description** |
|----------------------------------|------------------------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------------------------------|
| Clean System | [`clean-system.sh`](bash/clean-system.sh) | Bash | Removing unused `apt` packages, kernels, thumbnail cache, and docker objects. |
| Cloudflare - Add DNS A record | [`cloudflare_create_dns_record.py`](python/cloudflare_create_dns_record.py) | Python | Adds DNS A record pointing to a mentioned server using Cloudflare API v4. |
| Cloudflare - Delete DNS A record | [`cloudflare_delete_dns_records.py`](python/cloudflare_delete_dns_records.py) | Python | Deletes DNS A record pointing to a mentioned server using Cloudflare API v4. |
| Deletes old files in a directory | [`delete_old_file.py`](python/delete_old_file.py) | Python | Periodically deletes old files from a directory. For use in torrent box(es). |
| Find and Fix Git Email Leak | [`find-fix-git-email-leak/`](https://github.com/bearlike/find-fix-git-email-leak/) | Python | Find and Fix publicly accessible commit email addresses. |
| Macro Keyboard | [`Lua Macros/marco_keyboard.lua`](lua/Lua%20Macros/marco_keyboard.lua) | Lua | Load this script in [Lua Macros](https://github.com/me2d13/luamacros) to use multiple-keyboards for macro-triggerring application. |
| Macro Keyboard Companion | [`macro_keyboard_companion.py`](python/macro_keyboard_companion.py) | Python | Companion script for my Macro Keyboard. `Lua Macros/marco_keyboard.lua` for keyboard input grabbing. Basic alternative for AutoHotKey.|
| Nextcloud Snapshot | [`nextcloud_snapshot.sh`](bash/nextcloud_snapshot.sh) | Bash | Snapshot Nextcloud and uploads to remote locations such as Google Drive. Can be used as a Cronjob. |
| Raspberry Pi MOTD | [`status_motd_rpi.sh`](bash/status_motd_rpi.sh) | Bash | Raspberry Pi MOTD that displays basic system information on login. |
| Turn off Samsung TV | [`tv-shutdown.py`](python/tv-shutdown.py) | Python | Turn off Samsung TV using `samsungctl`. |
| Update System | [`update-system.sh`](bash/update-system.sh) | Bash | For Updating `apt` Packages and Portainer via docker. |
| Title | Filename | Type | Description |
| -------------------------------- | ------------------------------------------------------------------------------------------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Clean System | [`clean-system.sh`](bash/clean-system.sh) | Bash | Removing unused `apt` packages, kernels, thumbnail cache, and docker objects. |
| Nextcloud Snapshot | [`nextcloud_snapshot.sh`](bash/nextcloud_snapshot.sh) | Bash | Snapshot Nextcloud and uploads to remote locations such as Google Drive. Can be used as a Cronjob. |
| Raspberry Pi MOTD | [`status_motd_rpi.sh`](bash/status_motd_rpi.sh) | Bash | Raspberry Pi MOTD that displays basic system information on login. |
| Update System | [`update-system.sh`](bash/update-system.sh) | Bash | For Updating `apt` Packages and Portainer via docker. |
| Alias and functions | [`alias.sh`](bash/alias.sh) | Bash | Human friendly aliases and functions |
| Send notificatiovs via gotify | [`gotify-send.sh`](bash/gotify-send.sh) | Bash | Send notifications via gotify |
| Scan Pages | [`scan_page.sh`](bash/scan_page.sh) | Bash | Scan a page from my HP flatbed scanner through SANE (Scanner Access Now Easy) interface |
| Gotify Docker Stack | [`gotify/docker-compose.yml`](/docker-compose/gotify/docker-compose.yml) | docker-compose | |
| Homeassistant Docker Stack | [`homeassistant/docker-compose.yml`](/docker-compose/homeassistant/docker-compose.yml) | docker-compose | |
| Local Sites Docker Stack | [`local_sites/docker-compose.yml`](/docker-compose/local_sites/docker-compose.yml) | docker-compose | |
| MongoDB Docker Stack | [`mongodb/docker-compose.yml`](/docker-compose/mongodb/docker-compose.yml) | docker-compose | MongoDB and Mongo Express |
| Nextcloud Docker Stack | [`nextcloud/docker-compose.yml`](/docker-compose/nextcloud/docker-compose.yml) | docker-compose | |
| NGINX Proxy Manager Docker Stack | [`nginx_proxy_manager/docker-compose.yml`](/docker-compose/nginx_proxy_manager/docker-compose.yml) | docker-compose | |
| Pi-Hole Docker Stack | [`pihole/docker-compose.yml`](/docker-compose/pihole/docker-compose.yml) | docker-compose | |
| ScanservJS Docker Stack | [`scanner_app/docker-compose.yml`](/docker-compose/scanner_app/docker-compose.yml) | docker-compose | SANE web UI frontend for scanners. |
| Secrets Manager Docker Stack | [`simple_secret_manager/docker-compose.yml`](/docker-compose/simple_secret_manager/docker-compose.yml) | docker-compose | Secure storage, and delivery for tokens Visit [bearlike/simple-secrets-manager](https://github.com/bearlike/simple-secrets-manager) to know more. |
| Watchtower Docker Stack | [`watchtower/docker-compose.yml`](/docker-compose/watchtower/docker-compose.yml) | docker-compose | |
| Wireguard Docker Stack | [`wireguard/docker-compose.yml`](/docker-compose/wireguard/docker-compose.yml) | docker-compose | |
| Macro Keyboard | [`Lua Macros/marco_keyboard.lua`](lua/Lua%20Macros/marco_keyboard.lua) | Lua | Load this script in [Lua Macros](https://github.com/me2d13/luamacros) to use multiple-keyboards for macro-triggerring application. |
| Cloudflare - Add DNS A record | [`cloudflare_create_dns_record.py`](python/cloudflare_create_dns_record.py) | Python | Adds DNS A record pointing to a mentioned server using Cloudflare API v4. |
| Cloudflare - Delete DNS A record | [`cloudflare_delete_dns_records.py`](python/cloudflare_delete_dns_records.py) | Python | Deletes DNS A record pointing to a mentioned server using Cloudflare API v4. |
| Deletes old files in a directory | [`delete_old_file.py`](python/delete_old_file.py) | Python | Periodically deletes old files from a directory. For use in torrent box(es). |
| Find and Fix Git Email Leak | [`find-fix-git-email-leak/`](https://github.com/bearlike/find-fix-git-email-leak/) | Python | Find and Fix publicly accessible commit email addresses. |
| Macro Keyboard Companion | [`macro_keyboard_companion.py`](python/macro_keyboard_companion.py) | Python | Companion script for my Macro Keyboard. `Lua Macros/marco_keyboard.lua` for keyboard input grabbing. Basic alternative for AutoHotKey. |
| Turn off Samsung TV | [`tv-shutdown.py`](python/tv-shutdown.py) | Python | Turn off Samsung TV using `samsungctl`. |
| Login Notification via Gotify | [`login_notification.py`](python/login_notification.py) | Python | Retrieves `Gotify` tokens from `Simple Secrets Manager (SSM)` and sends notification on user login. For Windows, Use task scheduler to automate. |


**[`^ back to top ^`](#Scripts)**


## License
[![Creative Commons License](http://i.creativecommons.org/l/by/4.0/88x31.png)](http://creativecommons.org/licenses/by/4.0/)
<br> This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
<br> This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
11 changes: 6 additions & 5 deletions bash/alias.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Human friendly aliases and functions
# @title: Alias and functions
# @description: Human friendly aliases and functions

: ' Personal Aliases and Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
Expand Down Expand Up @@ -67,10 +68,10 @@ alias d-ex="docker exec -i -t"
alias d-cl="docker system prune"

# Stop all containers
d-stop-all() { docker stop $(docker ps -a -q) }
d-stop-all() { docker stop $(docker ps -a -q); }

# Show all docker related aliases
d-alias() { _guide_alias_ "Docker" "docker" }
d-alias() { _guide_alias_ "Docker" "docker"; }

# Bash into a running container
# arg $1 : container name/id
Expand All @@ -88,6 +89,6 @@ normal=$(tput sgr0)
# arg $1 : Title
# arg $2 : grep argument
_guide_alias_() {
printf "${underline}${1} aliases${nounderline}\n\n"
alias | grep $2 | sed "s/^\([^=]*\)=\(.*\)/\1 \t=> \2/" | sed "s/['|\']//g" | sort
printf "${underline}${1} aliases${nounderline}\n\n";
alias | grep $2 | sed "s/^\([^=]*\)=\(.*\)/\1 \t=> \2/" | sed "s/['|\']//g" | sort;
}
10 changes: 7 additions & 3 deletions bash/clean-system.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Removing unused apt packages, kernels, thumbnail cache, and docker objects.
# Last Updated June 2, 2020
# Tested on Ubuntu Server 20.04 LTS
# @title: Clean System
# @description: Removing unused apt packages, kernels, thumbnail cache, and docker objects.
# Tested on Ubuntu Server 20.04 LTS and Raspberry Pi OS

# Variables for pretty printing
RED=$(tput bold)$(tput setaf 1) # Red Color
Expand Down Expand Up @@ -29,6 +29,7 @@ OLD_KERNELS=$(
grep -Ei 'linux-image|linux-headers|linux-modules' |
awk '{ print $2 }'
)
# skipcq: SH-2154
if [ "${#files[@]}" -ne "0" ]; then
echo -e "\n${GREEN}Old Kernels to be removed:${NC}"
echo -e "${GREEN}$OLD_KERNELS${NC}\n"
Expand Down Expand Up @@ -57,6 +58,9 @@ echo -e "${RED}Cleaning Thumbnails...${NC}" &&
docker volume prune -f &&
docker network prune -f

# Delete journal logs older than 5 days
sudo journalctl --vacuum-time=5days

# Summarization
END=$(df /home --output=used | grep -Eo '[0-9]+')
RECLAIMED=$((BEGIN - END))
Expand Down
Loading

0 comments on commit ad6b3f8

Please sign in to comment.