|
| 1 | +from pathlib import Path |
1 | 2 | import argparse |
2 | 3 | import os |
3 | 4 | import shutil |
|
10 | 11 | action='store_true', |
11 | 12 | help='deletes any existing configs. WARNING: Make sure to backup your local env, and stalwart configs!', |
12 | 13 | ) |
| 14 | +arg_parse.add_argument( |
| 15 | + '--v016-only', |
| 16 | + action='store_true', |
| 17 | + help='Only bootstraps Stalwart v0.16 / Stalwart New', |
| 18 | +) |
13 | 19 |
|
14 | 20 | args = arg_parse.parse_args() |
15 | 21 |
|
16 | 22 |
|
17 | | -def main(): |
18 | | - from_scratch = args.from_scratch |
19 | | - |
20 | | - print('Bootstrapping project:') # noqa: T201 |
| 23 | +def bootstrap_legacy(from_scratch): |
21 | 24 | if not os.path.isfile('.env') or from_scratch: |
22 | 25 | try: |
23 | 26 | shutil.copy('.env.example', '.env') |
24 | 27 | print('\t* Copied .env.example to .env') # noqa: T201 |
25 | 28 | except SameFileError: |
26 | 29 | pass |
27 | 30 |
|
28 | | - if os.path.isdir('mail/data') and from_scratch: |
29 | | - shutil.rmtree('mail/data') |
30 | | - print('\t* Removed mail/data') # noqa: T201 |
| 31 | + if os.path.isdir('mail/stalwart_legacy/data') and from_scratch: |
| 32 | + shutil.rmtree('mail/stalwart_legacy/data') |
| 33 | + print('\t* Removed mail/stalwart_legacy/data') # noqa: T201 |
31 | 34 |
|
32 | | - if not os.path.isfile('mail/etc/config.toml') or from_scratch: |
| 35 | + if not os.path.isfile('mail/stalwart_legacy/etc/config.toml') or from_scratch: |
33 | 36 | try: |
34 | | - os.makedirs('mail/etc', exist_ok=True) |
35 | | - shutil.copy('config.toml.example', 'mail/etc/config.toml') |
36 | | - print('\t* Copied config.toml.example to mail/etc/config.toml') # noqa: T201 |
| 37 | + os.makedirs('mail/stalwart_legacy/etc/', exist_ok=True) |
| 38 | + shutil.copy('config.toml.example', 'mail/stalwart_legacy/etc/config.toml') |
| 39 | + print('\t* Copied config.toml.example to mail/stalwart_legacy/etc/config.toml') # noqa: T201 |
37 | 40 | except SameFileError: |
38 | 41 | pass |
39 | 42 |
|
| 43 | + |
| 44 | +def bootstrap_new(from_scratch): |
| 45 | + # Handle v0.16 |
| 46 | + path = Path('mail/stalwart/lib') |
| 47 | + if os.path.isdir(path) and from_scratch: |
| 48 | + os.remove(path / 'main.db') |
| 49 | + print(f'\t* Removed {path}/main.db') # noqa: T201 |
| 50 | + if not os.path.isfile(path / 'main.db'): |
| 51 | + shutil.copy(path / 'main.db.example', path / 'main.db') |
| 52 | + print(f'\t* Copied {path}/main.db.example to {path}/main.db') # noqa: T201 |
| 53 | + |
| 54 | + path = Path('mail/stalwart/etc') |
| 55 | + if os.path.isdir(path) and from_scratch: |
| 56 | + os.remove(path / 'config.json') |
| 57 | + print(f'\t* Removed {path}/config.json') # noqa: T201 |
| 58 | + if not os.path.isfile(path / 'config.json'): |
| 59 | + shutil.copy(path / 'config.json.example', path / 'config.json') |
| 60 | + print(f'\t* Copied {path}/config.json.example to {path}/config.json') # noqa: T201 |
| 61 | + |
40 | 62 | print('Finished!') # noqa: T201 |
41 | 63 |
|
42 | 64 |
|
| 65 | +def main(): |
| 66 | + new_only = args.v016_only |
| 67 | + from_scratch = args.from_scratch |
| 68 | + |
| 69 | + print('Bootstrapping project:', args.__dict__) # noqa: T201 |
| 70 | + |
| 71 | + if not new_only: |
| 72 | + print('Bootstrapping v0.15') # noqa: T201 |
| 73 | + bootstrap_legacy(from_scratch) |
| 74 | + |
| 75 | + print('Bootstrapping v0.16') # noqa: T201 |
| 76 | + bootstrap_new(from_scratch) |
| 77 | + |
| 78 | + |
43 | 79 | if __name__ == '__main__': |
44 | 80 | main() |
0 commit comments