syncthing-upgrade-script

Description

Create a shell script that tries the 'syncthing -upgrade' command, and if successful, restarts all running syncthing service units.

Variables

Name Type Default Description

add_cron_job

boolean True

Whether to add a cron job (default) or not.

Code

doc:
  short_help: Create 'syncthing' upgrade wrapper script, and add a cron job to run
    it regulary.
  help: |
    Create a shell script that tries the 'syncthing -upgrade' command, and if successful, restarts all running
    syncthing service units.

args:
  add_cron_job:
    doc:
      short_help: Whether to add a cron job (default) or not.
    type: boolean
    required: false
    default: true

frecklets:
- file-with-content:
    path: /usr/local/bin/syncthing_upgrade
    mode: '0775'
    owner: root
    content: |
      #!/usr/bin/env bash

      /usr/local/bin/syncthing -upgrade
      upgraded=$?

      if [ $upgraded -eq 0 ]; then
          systemctl restart 'syncthing@*'
      fi
- cronjob-exists:
    frecklet::skip: '{{:: add_cron_job | negate ::}}'
    user: root
    name: syncthing upgrade check
    job: /usr/local/bin/syncthing_upgrade
    special_time: daily
frecklecute syncthing-upgrade-script --help

Usage: frecklecute syncthing-upgrade-script [OPTIONS]

  Create a shell script that tries the 'syncthing -upgrade' command, and if
  successful, restarts all running syncthing service units.

Options:
  --add-cron-job / --no-add-cron-job
                                  Whether to add a cron job (default) or not.
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.syncthing_upgrade_script.SyncthingUpgradeScript
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class SyncthingUpgradeScript(AutoPycklet):
    """Create a shell script that tries the 'syncthing -upgrade' command, and if successful, restarts all running
     syncthing service units.

       Args:
         add_cron_job: Whether to add a cron job (default) or not.

    """

    FRECKLET_ID = "syncthing-upgrade-script"

    add_cron_job: bool = None


    def __post_init__(self):
        super(SyncthingUpgradeScript, self).__init__(var_names=["add_cron_job"])


frecklet_class = SyncthingUpgradeScript
# -*- coding: utf-8 -*-


#
# module path: pycklets.syncthing_upgrade_script.SyncthingUpgradeScript
#


from pyckles import AutoPycklet

class SyncthingUpgradeScript(AutoPycklet):
    """Create a shell script that tries the 'syncthing -upgrade' command, and if successful, restarts all running
     syncthing service units.

       Args:
         add_cron_job: Whether to add a cron job (default) or not.

    """

    FRECKLET_ID = "syncthing-upgrade-script"

    def __init__(self, add_cron_job=True):

        super(SyncthingUpgradeScript, self).__init__(var_names=["add_cron_job"])
        self._add_cron_job = add_cron_job

    @property
    def add_cron_job(self):
        return self._add_cron_job

    @add_cron_job.setter
    def add_cron_job(self, add_cron_job):
        self._add_cron_job = add_cron_job



frecklet_class = SyncthingUpgradeScript