diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2e21b327e39e709c7260da97032f6eb80958648a --- /dev/null +++ b/.gitignore @@ -0,0 +1,36 @@ +~* +*~ +*.sw[op] +*.py[cod] +.DS_Store +__pycache__/ +.vagrant/ +vendor/ +Thumbs.db +*.retry +.svn/ +.sass-cache/ +*.log +a.out +node-modules/ +nbproject/ +*.ipynb +.idea/ +*.egg-info/ +*.[ao] +.classpath +.cache/ +bower_components/ +*.class +*.jar +secring.* +.*.kate-swp +.swp.* +.directory +.Trash-* +build/ +_build/ +dist/ +.tox/ +roles +db/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58d620ddff136ec5c6b7255a687db0142a9cb8bd --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +- repo: https://github.com/pre-commit/pre-commit-hooks + sha: v0.7.1 + hooks: + - id: check-added-large-files + - id: check-yaml + - id: check-merge-conflict +- repo: https://github.com/willthames/ansible-lint + sha: v3.4.13 + hooks: + - id: ansible-lint + files: playbook\.yml + args: ['--exclude=roles'] +- repo: https://github.com/adarnimrod/shell-pre-commit + sha: v0.5.4 + hooks: + - id: shell-lint + files: receiver + - id: shellcheck + files: receiver diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..cbf0f7ce4c01083a36ac84ace0221d898c977df7 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# Poquita + +My setup of [Poca](https://github.com/brokkr/poca/). + +My workflow is managing the podcast list (and config and provisioning and +deployment scripts) via git, using +[gitreceive](https://github.com/progrium/gitreceive/) to deploy new versions to +the downloading machine (syncing files locally when afterward). + +## Running Poca locally + +`tox` + +## Running poca-subscribe locally + +`tox -e poca-subscribe -- {add,delete,list,toggle} ...` + +## Provision a machine for git push + +`tox -e ansible -- -i xbmc.shore.co.il,` + +## Deploying a new version + + git remote add kodi git@xbmc.shore.co.il:poquita.git + git push kodi + +## Running [pre-commit](http://pre-commit.com/) + +`tox -e pre-commit` diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000000000000000000000000000000000000..1865bc95585e6c68aa27400082aa826d1453b2b5 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,18 @@ +[defaults] +library = library +host_key_checking = False +retry_files_enabled = False +roles_path = ./roles/ +command_warnings = True +deprecation_warnings = True +callback_whitelist = profile_tasks +retry_files_save_path = /tmp/ + +[ssh_connection] +pipelining = True + +[privilege_escalation] +become = True +become_method = sudo +become_user = root +become_ask_pass = False diff --git a/db/.gitkeep b/db/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000000000000000000000000000000000000..9af9176874c7f1faafb88b521e5d464af2e755c9 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,42 @@ +--- +- hosts: all + pre_tasks: + - name: APT install Python3, Tox, Cron + apt: + name: + - python3 + - tox + - cron-daemon + state: present + update_cache: True + cache_valid_time: 3600 + + - name: Get authorized keys + become: False + slurp: + src: ~/.ssh/authorized_keys + register: authorized_keys + roles: + - name: gitreceive + gitreceive_public_keys: "{{ (authorized_keys['content']|b64decode).splitlines() }}" + gitreceive_receiver_script: | + #!/bin/sh + set -eu + echo '----> Unpacking ...' + mkdir -p ~/poquita + cd ~/poquita + tar -xf - + if [ -f receiver ] && [ -x receiver ] + then + echo '----> Running receiver ...' + ./receiver + fi + echo '----> OK.' + post_tasks: + - name: Create Podcasts directory + file: + path: /srv/library/nimrod/Podcasts + state: directory + owner: nimrod + group: git + mode: 0o0775 diff --git a/poca.xml b/poca.xml new file mode 100644 index 0000000000000000000000000000000000000000..ac6d8cca17d1c106f22af61d9ae3af048adac190 --- /dev/null +++ b/poca.xml @@ -0,0 +1,49 @@ +<poca version="0.8"> + <!-- Please see detailed configuration documentation online: + https://github.com/brokkr/poca/wiki/Configuration --> + <!-- The meaning of the settings options are briefly as follows: + * base_dir: Directory containing the individual subscription folders + * id3encoding: Encoding to use on metadata (utf8 or latin1) + * id3removev1: Should we remove id3v1, only keeping v2 (yes or no) + * useragent: _Fallback_ user agent if connection is rejected for + default python user agent. Leave empty not to use a fallback. + * email logging setup not included by default, see wiki for details. + --> + <settings> + <base_dir>/srv/library/nimrod/Podcasts</base_dir> + <id3encoding>utf8</id3encoding> + <id3removev1>yes</id3removev1> + <useragent/> + </settings> + <!-- Defaults take the same options as any single subscription. A + setting here, e.g. max_number, is applied to all subscriptions but + always overruled by sub-specific settings. Non-overruling settings in + metadata and filters are combined, e.g. a sub-specific 'artist' tag and + a global 'genre' tag --> + <defaults> + </defaults> + <subscriptions> + <!-- The meaning of the subscription options are brifly as follows: + * category: A category attribute on a subscription tag is helpful in + organizing the output of 'poca-subscribe list'. + * state: A state attribute is either 'active' or 'inactive'. inactive + subs are not updated. subs without state attribute are active. + * title: Name used for the folder of the subscription (required) + * url: The address of the rss feed (required) + * max_number: Max number of files to keep in subscription (optional) + * from_the_top: Get oldest files first, not newest (optional) + * metadata: Override id3 header fields with these values + (see https://github.com/brokkr/poca/wiki/ID3-frames for details) + * filters: Contains one or more of following tags (all optional) + * filename: Filename of the entry must match this string/regex + * title: Same as above, only for the title in the rss + * hour: The hour (24h-format) at which the entry was published. + * weekdays: Only entries from one of these weekdays (as integers) + * after_date: Only use entries published after date specified. + --> + <subscription> + <url>http://feeds.twit.tv/floss.xml</url> + <title>Floss Weekly</title> + </subscription> + </subscriptions> +</poca> diff --git a/receiver b/receiver new file mode 100755 index 0000000000000000000000000000000000000000..9e6f00c8550b5cb5c25df7fa063a0ecda5fbe05b --- /dev/null +++ b/receiver @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu + +# shellcheck disable=SC2016 +( (crontab -l 2>/dev/null || true) | sed '/poquita/d'; echo '0 */4 * * * tox -c $HOME/poquita/tox.ini | logger' ) | crontab - diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000000000000000000000000000000000000..e916d11dd6e3e7483e01d3ac6823d451187c8e00 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,3 @@ +--- +- src: adarnimrod.gitreceive + name: gitreceive diff --git a/roles/.gitkeep b/roles/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000000000000000000000000000000000000..741e8375d75533075f0f25b446f85ca1219f98b4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,40 @@ +[tox] +skipsdist = True +envlist = poca + +[testenv:poca] +basepython = python3 +deps = + feedparser + lxml + mutagen + git+https://github.com/brokkr/poca/@v0.8 +commands = + poca --config ./ {posargs} + +[testenv:poca-subscribe] +envdir = {toxworkdir}/poca +basepython = python3 +deps = + feedparser + lxml + mutagen + git+https://github.com/brokkr/poca/@v0.8 +commands = + poca-subscribe --config ./ {posargs} + +[testenv:ansible] +deps = + ansible==2.3.0.0 +commands = + ansible-galaxy install -r requirements.yml + ansible-playbook playbook.yml {posargs} +passenv = HOME TERM ANSIBLE_* AWS_* +setenv = + ANSIBLE_VERBOSITY=2 + +[testenv:pre-commit] +deps = + pre-commit==0.14.1 +commands = + pre-commit {posargs}