diff --git a/install b/install new file mode 100755 index 0000000..cb92f93 --- /dev/null +++ b/install @@ -0,0 +1,11 @@ +#!/bin/bash +# vim: ft=bash + +if ! command -v python3 >/dev/null 2>&1; then + echo "Err: This script requires Python 3." + exit -1 +fi + +dotfile_dir=$(realpath $(dirname "$0")) + +python3 $dotfile_dir/meta/install.py $dotfile_dir diff --git a/meta/components.json b/meta/components.json new file mode 100644 index 0000000..d9aaad5 --- /dev/null +++ b/meta/components.json @@ -0,0 +1,8 @@ +[ + { + "name": "zsh", + "link-files": [ + { "source": "init.zsh", "dest": ".zshrc" } + ] + } +] diff --git a/meta/install.py b/meta/install.py new file mode 100644 index 0000000..1106f59 --- /dev/null +++ b/meta/install.py @@ -0,0 +1,39 @@ +import sys +import os +import json +import pathlib + +dotfile_dir = sys.argv[1] +home_dir = str(pathlib.Path.home()) + +def install_component(comp): + print('Installing configuration: {}...'.format(comp['name'])) + comp_dir = os.path.join(dotfile_dir, comp['name']) + + if 'link-files' in comp: + link_files = comp['link-files'] + for f in link_files: + source_path = os.path.join(comp_dir, f['source']) + dest_path = os.path.join(home_dir, f['dest']) + if not os.path.exists(dest_path): + print(' linking {} -> {}'.format(dest_path, source_path)) + os.symlink(source_path, dest_path) + + if 'link-dirs' in comp: + link_dirs = comp['link-dirs'] + for f in link_dirs: + source_path = os.path.join(comp_dir, f['source']) + dest_path = os.path.join(home_dir, f['dest']) + if not os.path.exists(dest_path): + print(' linking {} -> {}'.format(dest_path, source_path)) + os.symlink(source_path, dest_path) + + +components_path = os.path.join(dotfile_dir, 'meta', 'components.json') +components = None + +with open(components_path, 'r') as f: + components = json.load(f) + +for comp in components: + install_component(comp) diff --git a/meta/uninstall.py b/meta/uninstall.py new file mode 100644 index 0000000..e0751c5 --- /dev/null +++ b/meta/uninstall.py @@ -0,0 +1,39 @@ +import sys +import os +import json +import pathlib + +dotfile_dir = sys.argv[1] +home_dir = str(pathlib.Path.home()) + +def uninstall_component(comp): + print('Uninstalling component: {}...'.format(comp['name'])) + comp_dir = os.path.join(dotfile_dir, comp['name']) + + if 'link-files' in comp: + link_files = comp['link-files'] + for f in link_files: + source_path = os.path.join(comp_dir, f['source']) + dest_path = os.path.join(home_dir, f['dest']) + if os.path.exists(dest_path): + print(' removing link {}'.format(dest_path)) + os.unlink(dest_path) + + if 'link-dirs' in comp: + link_dirs = comp['link-dirs'] + for f in link_dirs: + source_path = os.path.join(comp_dir, f['source']) + dest_path = os.path.join(home_dir, f['dest']) + if not os.path.exists(dest_path): + print(' removing link {} -> {}'.format(dest_path)) + os.unlink(dest_path) + + +components_path = os.path.join(dotfile_dir, 'meta', 'components.json') +components = None + +with open(components_path, 'r') as f: + components = json.load(f) + +for comp in components: + uninstall_component(comp) diff --git a/uninstall b/uninstall new file mode 100755 index 0000000..6da353e --- /dev/null +++ b/uninstall @@ -0,0 +1,11 @@ +#!/bin/bash +# vim: ft=bash + +if ! command -v python3 >/dev/null 2>&1; then + echo "Err: This script requires Python 3." + exit -1 +fi + +dotfile_dir=$(realpath $(dirname "$0")) + +python3 $dotfile_dir/meta/uninstall.py $dotfile_dir