added quit option and set default scripts
This commit is contained in:
@@ -20,3 +20,68 @@ repos:
|
||||
teardown: ''
|
||||
verified: ''
|
||||
alias: 'fh'
|
||||
- account: kevinveenbirkenbach
|
||||
alias: drctrycntnts
|
||||
provider: github.com
|
||||
repository: directory-content-scanner
|
||||
verified: efcfc585d7a396ff7983196a621256a64728438b
|
||||
- account: kevinveenbirkenbach
|
||||
alias: blkstrngrplc
|
||||
provider: github.com
|
||||
repository: bulk-string-replacer
|
||||
verified: c7bf51941b691eea3cb8536d0f4e18427ba916e8
|
||||
- account: kevinveenbirkenbach
|
||||
alias: mgrszrcl
|
||||
provider: github.com
|
||||
repository: image-resizer-cli
|
||||
verified: ee279a127fd1f4a2b9c4a3a9de86b3a0ad8cf8ce
|
||||
- account: kevinveenbirkenbach
|
||||
alias: mdsrtngtls
|
||||
provider: github.com
|
||||
repository: media-sorting-tools
|
||||
verified: 2cb735f45a15c3cadb8edc948d5f5f03e79fcb1a
|
||||
- account: kevinveenbirkenbach
|
||||
alias: nsblncryptr
|
||||
provider: github.com
|
||||
repository: ansible-encryptor
|
||||
verified: 0053384aa0aa85dcef764a8b74c03a72537d0115
|
||||
- account: kevinveenbirkenbach
|
||||
alias: fdrtdtcntrls
|
||||
provider: github.com
|
||||
repository: federated-to-central-social-network-bridge
|
||||
verified: 1f6ace3fe84cb537436839a8a8164f1dc7b6e0c3
|
||||
- account: kevinveenbirkenbach
|
||||
alias: lnxmgmngr
|
||||
provider: github.com
|
||||
repository: linux-image-manager
|
||||
verified: 13454c7e8722b344723dbe6a997102672edce105
|
||||
- account: kevinveenbirkenbach
|
||||
alias: dckrvlmbckp
|
||||
provider: github.com
|
||||
repository: docker-volume-backup
|
||||
verified: f847c8dd74c6c69067fd2a3591f7ec6fafefc9e0
|
||||
- account: kevinveenbirkenbach
|
||||
alias: dplctflhndlr
|
||||
provider: github.com
|
||||
repository: duplicate-file-handler
|
||||
verified: 89e15dd023aee82190bacaadc337c282b91f5357
|
||||
- account: kevinveenbirkenbach
|
||||
alias: crtlnxswpfl
|
||||
provider: github.com
|
||||
repository: create-linux-swapfile
|
||||
verified: d68cc2c18ea10f6c494bbd6a425f51d99f30a601
|
||||
- account: kevinveenbirkenbach
|
||||
alias: spltdscrt
|
||||
provider: github.com
|
||||
repository: splitted-secret
|
||||
verified: 44b2db0cbc03101ef43aff73eef1ab6ed011b9f5
|
||||
- account: kevinveenbirkenbach
|
||||
alias: drctryvldtr
|
||||
provider: github.com
|
||||
repository: directory-validator
|
||||
verified: 73a29a092adaf4d513bc23357b7700d690d5a663
|
||||
- account: kevinveenbirkenbach
|
||||
alias: lkskymngmnts
|
||||
provider: github.com
|
||||
repository: luks-key-management-script
|
||||
verified: 2f5fe1a73f5ce6d661679083bde6d56b19b867f1
|
||||
45
main.py
45
main.py
@@ -130,11 +130,12 @@ def generate_alias(repo, bin_dir, existing_aliases):
|
||||
candidate3 = candidate3[:12]
|
||||
return candidate3
|
||||
|
||||
def create_executable(repo, base_dir, bin_dir, all_repos, preview=False):
|
||||
"""Create an executable bash wrapper for the repository.
|
||||
def create_executable(repo, base_dir, bin_dir, all_repos, quiet=False, preview=False):
|
||||
"""
|
||||
Create an executable bash wrapper for the repository.
|
||||
|
||||
If 'verified' is set, the wrapper will checkout that commit and warn in orange if it does not match.
|
||||
If no verified commit is set, a warning in orange is printed.
|
||||
If 'verified' is set, the wrapper will checkout that commit and warn (unless quiet is True).
|
||||
If no verified commit is set, a warning is printed unless quiet is True.
|
||||
If an 'alias' field is provided, a symlink is created in bin_dir with that alias.
|
||||
"""
|
||||
repo_identifier = get_repo_identifier(repo, all_repos)
|
||||
@@ -148,23 +149,26 @@ def create_executable(repo, base_dir, bin_dir, all_repos, preview=False):
|
||||
elif os.path.exists(main_py):
|
||||
command = "python3 main.py"
|
||||
else:
|
||||
print(f"No command defined and no main.sh/main.py found in {repo_dir}. Skipping alias creation.")
|
||||
if not quiet:
|
||||
print(f"No command defined and no main.sh/main.py found in {repo_dir}. Skipping alias creation.")
|
||||
return
|
||||
|
||||
ORANGE = r"\033[38;5;208m"
|
||||
RESET = r"\033[0m"
|
||||
|
||||
verified = repo.get("verified")
|
||||
if verified:
|
||||
preamble = f"""\
|
||||
if verified := repo.get("verified"):
|
||||
if not quiet:
|
||||
preamble = f"""\
|
||||
git checkout {verified} || echo -e "{ORANGE}Warning: Failed to checkout commit {verified}.{RESET}"
|
||||
CURRENT=$(git rev-parse HEAD)
|
||||
if [ "$CURRENT" != "{verified}" ]; then
|
||||
echo -e "{ORANGE}Warning: Current commit ($CURRENT) does not match verified commit ({verified}).{RESET}"
|
||||
fi
|
||||
"""
|
||||
else:
|
||||
preamble = ""
|
||||
else:
|
||||
preamble = f'echo -e "{ORANGE}Warning: No verified commit set for this repository.{RESET}"'
|
||||
preamble = "" if quiet else f'echo -e "{ORANGE}Warning: No verified commit set for this repository.{RESET}"'
|
||||
|
||||
script_content = f"""#!/bin/bash
|
||||
cd "{repo_dir}"
|
||||
@@ -179,7 +183,8 @@ cd "{repo_dir}"
|
||||
with open(alias_path, "w") as f:
|
||||
f.write(script_content)
|
||||
os.chmod(alias_path, 0o755)
|
||||
print(f"Installed executable for {repo_identifier} at {alias_path}")
|
||||
if not quiet:
|
||||
print(f"Installed executable for {repo_identifier} at {alias_path}")
|
||||
|
||||
alias_name = repo.get("alias")
|
||||
if alias_name:
|
||||
@@ -188,11 +193,13 @@ cd "{repo_dir}"
|
||||
if os.path.exists(alias_link_path) or os.path.islink(alias_link_path):
|
||||
os.remove(alias_link_path)
|
||||
os.symlink(alias_path, alias_link_path)
|
||||
print(f"Created alias '{alias_name}' pointing to {repo_identifier}")
|
||||
if not quiet:
|
||||
print(f"Created alias '{alias_name}' pointing to {repo_identifier}")
|
||||
except Exception as e:
|
||||
print(f"Error creating alias '{alias_name}': {e}")
|
||||
if not quiet:
|
||||
print(f"Error creating alias '{alias_name}': {e}")
|
||||
|
||||
def install_repos(selected_repos, base_dir, bin_dir, all_repos, preview=False):
|
||||
def install_repos(selected_repos, base_dir, bin_dir, all_repos, preview=False, quiet=False):
|
||||
"""Install repositories by creating executable wrappers and running setup."""
|
||||
for repo in selected_repos:
|
||||
repo_identifier = get_repo_identifier(repo, all_repos)
|
||||
@@ -200,7 +207,7 @@ def install_repos(selected_repos, base_dir, bin_dir, all_repos, preview=False):
|
||||
if not os.path.exists(repo_dir):
|
||||
print(f"Repository directory '{repo_dir}' does not exist. Clone it first.")
|
||||
continue
|
||||
create_executable(repo, base_dir, bin_dir, all_repos, preview=preview)
|
||||
create_executable(repo, base_dir, bin_dir, all_repos, quiet=quiet, preview=preview)
|
||||
setup_cmd = repo.get("setup")
|
||||
if setup_cmd:
|
||||
run_command(setup_cmd, cwd=repo_dir, preview=preview)
|
||||
@@ -275,9 +282,9 @@ def delete_repos(selected_repos, base_dir, all_repos, preview=False):
|
||||
else:
|
||||
print(f"Repository directory '{repo_dir}' not found for {repo_identifier}.")
|
||||
|
||||
def update_repos(selected_repos, base_dir, bin_dir, all_repos, system_update=False, preview=False):
|
||||
def update_repos(selected_repos, base_dir, bin_dir, all_repos, system_update=False, preview=False, quiet=False):
|
||||
pull_repos(selected_repos, base_dir, all_repos, extra_args=[], preview=preview)
|
||||
install_repos(selected_repos, base_dir, bin_dir, all_repos, preview=preview)
|
||||
install_repos(selected_repos, base_dir, bin_dir, all_repos, preview=preview, quier=quiet)
|
||||
if system_update:
|
||||
run_command("yay -S", preview=preview)
|
||||
run_command("sudo pacman -Syyu", preview=preview)
|
||||
@@ -436,6 +443,7 @@ if __name__ == "__main__":
|
||||
|
||||
install_parser = subparsers.add_parser("install", help="Install repository/repositories")
|
||||
add_identifier_arguments(install_parser)
|
||||
install_parser.add_argument("-q", "--quiet", action="store_true", help="Suppress warnings and info messages")
|
||||
|
||||
pull_parser = subparsers.add_parser("pull", help="Pull updates for repository/repositories")
|
||||
add_identifier_arguments(pull_parser)
|
||||
@@ -455,6 +463,7 @@ if __name__ == "__main__":
|
||||
update_parser = subparsers.add_parser("update", help="Update (pull + install) repository/repositories")
|
||||
add_identifier_arguments(update_parser)
|
||||
update_parser.add_argument("--system", action="store_true", help="Include system update commands")
|
||||
update_parser.add_argument("-q", "--quiet", action="store_true", help="Suppress warnings and info messages")
|
||||
|
||||
status_parser = subparsers.add_parser("status", help="Show status for repository/repositories or system")
|
||||
add_identifier_arguments(status_parser)
|
||||
@@ -495,7 +504,7 @@ if __name__ == "__main__":
|
||||
if args.command == "install":
|
||||
selected = all_repos_list if args.all or (not args.identifiers) else resolve_repos(args.identifiers, all_repos_list)
|
||||
selected = filter_ignored(selected)
|
||||
install_repos(selected, base_dir, BIN_DIR, all_repos_list, preview=args.preview)
|
||||
install_repos(selected, base_dir, BIN_DIR, all_repos_list, preview=args.preview, quiet=args.quiet)
|
||||
elif args.command == "pull":
|
||||
selected = all_repos_list if args.all or (not args.identifiers) else resolve_repos(args.identifiers, all_repos_list)
|
||||
selected = filter_ignored(selected)
|
||||
@@ -523,7 +532,7 @@ if __name__ == "__main__":
|
||||
elif args.command == "update":
|
||||
selected = all_repos_list if args.all or (not args.identifiers) else resolve_repos(args.identifiers, all_repos_list)
|
||||
selected = filter_ignored(selected)
|
||||
update_repos(selected, base_dir, BIN_DIR, all_repos_list, system_update=args.system, preview=args.preview)
|
||||
update_repos(selected, base_dir, BIN_DIR, all_repos_list, system_update=args.system, preview=args.preview, quiet=args.quiet)
|
||||
elif args.command == "status":
|
||||
selected = all_repos_list if args.all or (not args.identifiers) else resolve_repos(args.identifiers, all_repos_list)
|
||||
selected = filter_ignored(selected)
|
||||
|
||||
Reference in New Issue
Block a user