Replace deploy.sh with deploy.py Some updates to setup scripts, for more consistency Split out some common unix setup tasks into a script that both mac and linux scripts call.
70 lines
1.6 KiB
Python
70 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
home = Path.home().resolve().absolute()
|
|
dotdir = Path(__file__).parent.resolve().absolute()
|
|
|
|
simple = [
|
|
# 'gemrc',
|
|
'gitconfig',
|
|
'ideavimrc',
|
|
'lein',
|
|
# 'irbrc',
|
|
# 'nethackrc',
|
|
# 'spacemacs',
|
|
'tmux.conf',
|
|
'vimrc'
|
|
]
|
|
|
|
targeted = {
|
|
'doom': '.doom.d',
|
|
'fish': '.config/fish',
|
|
}
|
|
|
|
|
|
def deploy(source_name, target_name, dry_run=False):
|
|
source = dotdir.joinpath(source_name)
|
|
target = home.joinpath(target_name)
|
|
|
|
if not source.exists():
|
|
raise FileNotFoundError(f"Asked to link {source_name}, which doesn't exist in {dotdir}.")
|
|
|
|
if target.exists():
|
|
if target.samefile(source):
|
|
print(f"{target}->{source} already linked.")
|
|
return
|
|
|
|
backup_path = target.parent.joinpath(f"{target.name}.bak")
|
|
|
|
print(f"{target} moves to {backup_path}")
|
|
if not dry_run:
|
|
target.replace(backup_path)
|
|
|
|
if not target.parent.exists():
|
|
print(f"making parent directories of {target}")
|
|
if not dry_run:
|
|
target.parent.mkdir(parents=True)
|
|
|
|
print(f"linking {target} to {source}")
|
|
if not dry_run:
|
|
target.symlink_to(source)
|
|
|
|
|
|
def main(dry_run=True):
|
|
for source in simple:
|
|
target = f".{source}"
|
|
deploy(source, target, dry_run=dry_run)
|
|
|
|
for source, target in targeted.items():
|
|
deploy(source, target, dry_run=dry_run)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main(False)
|
|
except FileNotFoundError as e:
|
|
print(e)
|
|
sys.exit(1)
|