mirror of
https://codeberg.org/Mo8it/dotfiles.git
synced 2024-12-02 23:33:05 +00:00
Compare commits
6 commits
bda8425aac
...
c21b092d8d
Author | SHA1 | Date | |
---|---|---|---|
c21b092d8d | |||
7618016ef7 | |||
8ca149ee44 | |||
37da2ab864 | |||
c408b116ed | |||
eb44bdf56d |
6 changed files with 4 additions and 303 deletions
|
@ -11,7 +11,7 @@
|
|||
],
|
||||
"plugins": [
|
||||
"https://plugins.dprint.dev/json-0.19.3.wasm",
|
||||
"https://plugins.dprint.dev/markdown-0.17.1.wasm",
|
||||
"https://plugins.dprint.dev/markdown-0.17.2.wasm",
|
||||
"https://plugins.dprint.dev/toml-0.6.2.wasm"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ if status is-interactive
|
|||
zoxide init fish | source
|
||||
## Starship
|
||||
starship init fish | source
|
||||
## fnm
|
||||
fnm env --shell fish | source
|
||||
|
||||
# Abbreviations
|
||||
## Replacements
|
||||
|
@ -40,9 +42,9 @@ if status is-interactive
|
|||
alias ll "ls -l"
|
||||
alias cat bat
|
||||
alias gu gitui
|
||||
alias zola "flatpak run org.getzola.zola"
|
||||
alias julia "JULIA_NUM_THREADS=16 ~/.juliaup/bin/julia"
|
||||
alias tb "toolbox run fish"
|
||||
alias todo "hx ~/todo.md"
|
||||
|
||||
# Private config
|
||||
set -l private_config ~/.config/fish/private_config.fish
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
theme = "Dark"
|
||||
scale = 1.5
|
||||
|
||||
[font-options]
|
||||
regular-font = "Cantarell"
|
||||
monospace-font = "Cantarell"
|
|
@ -1,131 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
from os import environ
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run(command, **kwargs):
|
||||
return subprocess.run(command, shell=True, check=True, **kwargs)
|
||||
|
||||
|
||||
def cap_run(command, **kwargs):
|
||||
return run(
|
||||
command, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, **kwargs
|
||||
).stdout.strip()
|
||||
|
||||
|
||||
def rpm_ostree_packages(output_dir):
|
||||
out = cap_run("rpm-ostree status --json")
|
||||
json_out = json.loads(out)
|
||||
|
||||
deployments = json_out["deployments"]
|
||||
booted_deployment = deployments[0]
|
||||
|
||||
if not booted_deployment["booted"]:
|
||||
for depl in deployments:
|
||||
if depl["booted"]:
|
||||
booted_deployment = depl
|
||||
break
|
||||
|
||||
removals = booted_deployment["requested-base-removals"]
|
||||
additions = booted_deployment["requested-packages"]
|
||||
|
||||
file = output_dir / "rpm-ostree.sh"
|
||||
with file.open("w") as f:
|
||||
f.write("rpm-ostree override remove")
|
||||
for removal in removals:
|
||||
f.write(" " + removal)
|
||||
|
||||
f.write("\nrpm-ostree install")
|
||||
for addition in additions:
|
||||
f.write(" " + addition)
|
||||
|
||||
|
||||
def flatpak_packages(output_dir):
|
||||
out = cap_run("flatpak list --app --columns=application")
|
||||
apps = out.split()
|
||||
|
||||
file = output_dir / "flatpak.sh"
|
||||
with file.open("w") as f:
|
||||
f.write("flatpak install")
|
||||
for app in apps:
|
||||
f.write(" " + app)
|
||||
|
||||
|
||||
def cargo_packages(output_dir):
|
||||
out = cap_run("cargo install --list")
|
||||
|
||||
pattern = r"(.+) .+:.*"
|
||||
crates = re.findall(pattern, out)
|
||||
|
||||
file = output_dir / "cargo.sh"
|
||||
with file.open("w") as f:
|
||||
f.write("cargo install")
|
||||
for crate in crates:
|
||||
f.write(" " + crate)
|
||||
|
||||
|
||||
def npm_packages(output_dir):
|
||||
out = cap_run("npm list --json --location=global")
|
||||
json_out = json.loads(out)
|
||||
deps = json_out["dependencies"].keys()
|
||||
deps = [dep for dep in deps if dep != "npm"]
|
||||
|
||||
file = output_dir / "npm.sh"
|
||||
with file.open("w") as f:
|
||||
f.write("npm config set prefix '~/.npm-global'\n")
|
||||
f.write("npm install --location=global npm\n")
|
||||
f.write("~/.npm-global/bin/npm install --location=global")
|
||||
for dep in deps:
|
||||
f.write(" " + dep)
|
||||
|
||||
|
||||
def pipx_packages(output_dir):
|
||||
out = cap_run("pipx list --json")
|
||||
json_out = json.loads(out)
|
||||
|
||||
venvs = json_out["venvs"]
|
||||
|
||||
packages = []
|
||||
injections = {}
|
||||
for ind, venv_key in enumerate(venvs.keys()):
|
||||
metadata = venvs[venv_key]["metadata"]
|
||||
package = metadata["main_package"]["package_or_url"]
|
||||
packages.append(package)
|
||||
|
||||
package_injections = metadata["injected_packages"].keys()
|
||||
if len(package_injections) > 0:
|
||||
injections[package] = package_injections
|
||||
|
||||
file = output_dir / "pipx.sh"
|
||||
with file.open("w") as f:
|
||||
for package in packages:
|
||||
f.write(f"pipx install {package}\n")
|
||||
|
||||
f.write("\n")
|
||||
|
||||
for package in injections.keys():
|
||||
for injection in injections[package]:
|
||||
f.write(f"pipx inject {package} {injection}\n")
|
||||
|
||||
|
||||
def main():
|
||||
output_dir = Path(f"{environ['HOME']}/bk/installed_packages_info")
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
rpm_ostree_packages(output_dir)
|
||||
|
||||
flatpak_packages(output_dir)
|
||||
|
||||
pipx_packages(output_dir)
|
||||
|
||||
cargo_packages(output_dir)
|
||||
|
||||
# npm_packages(output_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,157 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
from getpass import getpass
|
||||
from os import environ
|
||||
from pathlib import Path
|
||||
|
||||
CONFIG_PATH = Path.home() / ".config/restic_bk/"
|
||||
|
||||
|
||||
def run(command: str, **kwargs):
|
||||
return subprocess.run(command, shell=True, **kwargs)
|
||||
|
||||
|
||||
def decorated_print(str: str):
|
||||
print(f"\n<<-<>==={str}===<>->>\n")
|
||||
|
||||
|
||||
def write_home_visible_includes():
|
||||
home_visible_content = set(
|
||||
run("fd -d 1 '.*' ~", check=True, stdout=subprocess.PIPE, text=True)
|
||||
.stdout.strip()
|
||||
.split()
|
||||
)
|
||||
|
||||
home_visible_excludes = []
|
||||
with open(CONFIG_PATH / "home_visible_excludes.txt") as f:
|
||||
for line in f:
|
||||
home_visible_excludes.append(line.strip())
|
||||
|
||||
home_visible_includes = home_visible_content.difference(home_visible_excludes)
|
||||
|
||||
with open(CONFIG_PATH / "home_visible_includes.txt", "w") as f:
|
||||
for line in home_visible_includes:
|
||||
f.write(line + "\n")
|
||||
|
||||
|
||||
def mounted_backup_drive():
|
||||
mounted_drives_path = Path("/run/media") / environ["USER"]
|
||||
if not mounted_drives_path.is_dir():
|
||||
raise Exception("No drives mounted!")
|
||||
|
||||
known_backup_drives = []
|
||||
with open(CONFIG_PATH / "known_backup_drives.txt") as f:
|
||||
for line in f:
|
||||
known_backup_drives.append(line.strip())
|
||||
|
||||
mounted_backup_drives = []
|
||||
for path in mounted_drives_path.iterdir():
|
||||
if path.is_dir():
|
||||
drive_name = path.parts[-1]
|
||||
if drive_name in known_backup_drives:
|
||||
mounted_backup_drives.append(drive_name)
|
||||
|
||||
if len(mounted_backup_drives) == 0:
|
||||
raise Exception("No known backup drives found!")
|
||||
|
||||
ind = 0
|
||||
if len(mounted_backup_drives) > 1:
|
||||
decorated_print("Found multiple known backup drives")
|
||||
|
||||
for i, drive in enumerate(mounted_backup_drives):
|
||||
print(f"{i}: {drive}")
|
||||
|
||||
ind = int(input("Enter index: "))
|
||||
|
||||
return mounted_drives_path / mounted_backup_drives[ind]
|
||||
|
||||
|
||||
def get_parent_snapshot(env):
|
||||
snapshots_json = run(
|
||||
"restic snapshots -q --latest 1 --json",
|
||||
env=env,
|
||||
check=True,
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
).stdout.strip()
|
||||
|
||||
return json.loads(snapshots_json)[-1]["id"]
|
||||
|
||||
|
||||
def pre_backup():
|
||||
password = getpass("Restic repo password: ")
|
||||
|
||||
write_home_visible_includes()
|
||||
|
||||
repo = mounted_backup_drive() / "restic"
|
||||
init_repo = False
|
||||
if not repo.is_dir():
|
||||
decorated_print(f"No repo found at {repo} !!")
|
||||
|
||||
ans = input("Initialize repo? [Y/n]: ")
|
||||
if ans.strip().lower() not in ("", "y"):
|
||||
raise Exception("No repo to work with!")
|
||||
else:
|
||||
init_repo = True
|
||||
|
||||
with open(CONFIG_PATH / "pre_backup_scripts.txt") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
decorated_print(f"Running {line}")
|
||||
run(f"python {line}", stderr=subprocess.DEVNULL)
|
||||
|
||||
run("restic self-update", stderr=subprocess.DEVNULL)
|
||||
|
||||
env = environ.copy()
|
||||
env["RESTIC_REPOSITORY"] = repo
|
||||
env["RESTIC_PASSWORD"] = password
|
||||
env["RESTIC_COMPRESSION"] = "auto"
|
||||
|
||||
if init_repo:
|
||||
run("restic init", env=env, check=True)
|
||||
parent_snapshot = None
|
||||
else:
|
||||
parent_snapshot = get_parent_snapshot(env)
|
||||
|
||||
decorated_print(f"Parent snapshot: {parent_snapshot}")
|
||||
|
||||
return env, parent_snapshot
|
||||
|
||||
|
||||
def backup(env, parent_snapshot):
|
||||
home_visible_includes = CONFIG_PATH / "home_visible_includes.txt"
|
||||
includes = CONFIG_PATH / "includes.txt"
|
||||
excludes = CONFIG_PATH / "excludes.txt"
|
||||
|
||||
if parent_snapshot is not None:
|
||||
parent_arg = "--parent " + parent_snapshot
|
||||
else:
|
||||
parent_arg = ""
|
||||
|
||||
run(
|
||||
f"restic backup -v {parent_arg} --files-from {home_visible_includes} --files-from {includes} --exclude-file {excludes}",
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def post_backup(env):
|
||||
run("restic check", env=env, check=True)
|
||||
|
||||
run("restic snapshots --compact", env=env)
|
||||
|
||||
|
||||
def main():
|
||||
env, parent_snapshot = pre_backup()
|
||||
|
||||
backup(env, parent_snapshot)
|
||||
|
||||
post_backup(env)
|
||||
|
||||
decorated_print("DONE")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/fish
|
||||
|
||||
if test (gsettings get org.gnome.desktop.peripherals.touchpad send-events) = "'enabled'"
|
||||
gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
|
||||
else
|
||||
gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
|
||||
end
|
Loading…
Reference in a new issue