Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Created March 8, 2023 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjohndoe/7776c14dbb5359e94c8d9dedfb1e2248 to your computer and use it in GitHub Desktop.
Save johnjohndoe/7776c14dbb5359e94c8d9dedfb1e2248 to your computer and use it in GitHub Desktop.
This script enables/disables the public/private keys for work and hobby.
#!/bin/python3
#
# This script enables/disables the public/private keys for work and hobby.
import os
ACTIVATED_PRI = "/home/USERNAME/.ssh/id_ed25519"
ACTIVATED_PUB = "/home/USERNAME/.ssh/id_ed25519.pub"
INACTIVE_HOBBY_PRI = "/home/USERNAME/.ssh/id_ed25519.HOBBY"
INACTIVE_HOBBY_PUB = "/home/USERNAME/.ssh/id_ed25519.pub.HOBBY"
INACTIVE_WORK_PRI = "/home/USERNAME/.ssh/id_ed25519.WORK"
INACTIVE_WORK_PUB = "/home/USERNAME/.ssh/id_ed25519.pub.WORK"
def fileExists(file):
return os.path.isfile(file)
def renameFile(old, new):
return os.rename(old, new)
def isWorkActivated():
return fileExists(ACTIVATED_PUB) and fileExists(INACTIVE_HOBBY_PUB) and not fileExists(INACTIVE_WORK_PUB) and fileExists(INACTIVE_HOBBY_PRI) and not fileExists(INACTIVE_WORK_PRI)
def isHobbyActivated():
return fileExists(ACTIVATED_PUB) and not fileExists(INACTIVE_HOBBY_PUB) and fileExists(INACTIVE_WORK_PUB)and not fileExists(INACTIVE_HOBBY_PRI) and fileExists(INACTIVE_WORK_PRI)
if isWorkActivated():
print("Work is activated. Activating hobby now ...")
renameFile(ACTIVATED_PUB, INACTIVE_WORK_PUB)
renameFile(INACTIVE_HOBBY_PUB, ACTIVATED_PUB)
renameFile(ACTIVATED_PRI, INACTIVE_WORK_PRI)
renameFile(INACTIVE_HOBBY_PRI, ACTIVATED_PRI)
elif isHobbyActivated():
print("Hobby is activated. Activating work now ...")
renameFile(ACTIVATED_PUB, INACTIVE_HOBBY_PUB)
renameFile(INACTIVE_WORK_PUB, ACTIVATED_PUB)
renameFile(ACTIVATED_PRI, INACTIVE_HOBBY_PRI)
renameFile(INACTIVE_WORK_PRI, ACTIVATED_PRI)
else:
raise Exception("Neither work nor hobby is activated.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment