Skip to content

Instantly share code, notes, and snippets.

@yasn77
Last active January 12, 2021 12:03
Show Gist options
  • Save yasn77/864ebf83b6feb9adbf15c523155c03c6 to your computer and use it in GitHub Desktop.
Save yasn77/864ebf83b6feb9adbf15c523155c03c6 to your computer and use it in GitHub Desktop.
[Unit]
Description=Update opsctl using daily timer
Wants=update-opsctl.timer
[Service]
Type=oneshot
ExecStart=<PATH_TO_UPDATE_OPSCTL_SCRIPT>
[Install]
WantedBy=multi-user.target
#!/usr/bin/env bash
# Requires opsctl version 1.9.0 (https://github.com/giantswarm/opsctl/releases/tag/v1.9.0)
set -o errexit
set -o nounset
set -o pipefail
OPSCTL_BINDIR=${OPSCTL_BINDIR:-"${HOME}/.local/bin"}
if [ -x ${OPSCTL_BINDIR}/opsctl ]
then
VER_CHECK_EXIT_CODE="$(${OPSCTL_BINDIR}/opsctl version check &>/dev/null; echo $?)"
else
echo "${OPSCTL_BINDIR}/opsctl is not there or isn't executable"
exit 1
fi
if [ "$VER_CHECK_EXIT_CODE" == "125" ]
then
echo -n "🔺 Updating..."
${OPSCTL_BINDIR}/opsctl version update
echo "...Done 🚀"
else
echo "You already have the latest opsctl release 👍"
fi
[Unit]
Description=Update opsctl
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
@yasn77
Copy link
Author

yasn77 commented Jul 23, 2020

To use:

mkdir -p ~/.config/environment.d/ && echo GITHUB_TOKEN=$GITHUB_TOKEN > ~/.config/environment.d/update-opsctl.conf
curl https://gist.github.com/yasn77/864ebf83b6feb9adbf15c523155c03c6/raw/e146424d6518241bf6b8b17e8b7c257a89060dfe/update-opsctl.timer -o ~/.config/systemd/user/update-opsctl.timer
curl https://gist.github.com/yasn77/864ebf83b6feb9adbf15c523155c03c6/raw/e146424d6518241bf6b8b17e8b7c257a89060dfe/update-opsctl.service -o ~/.config/systemd/user/update-opsctl.service
curl https://gist.github.com/yasn77/864ebf83b6feb9adbf15c523155c03c6/raw/e146424d6518241bf6b8b17e8b7c257a89060dfe/update-opsctl.sh -o ~/.local/bin/update-opsctl.sh
chmod +x ~/.local/bin/update-opsctl.sh
systemctl --user enable update-opsctl.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment