From 30d92802ad5f77fd6a16c593d5e0052238dfe3a0 Mon Sep 17 00:00:00 2001 From: Brian Zalewski <59970525+ProfessorManhattan@users.noreply.github.com> Date: Sun, 14 Jan 2024 05:48:00 +0000 Subject: [PATCH] Latest --- home/dot_config/shell/exports.sh.tmpl | 1 + home/dot_local/bin/executable_installx | 94 ++++++++++++++++++++++++++ software.yml | 10 +++ 3 files changed, 105 insertions(+) create mode 100644 home/dot_local/bin/executable_installx diff --git a/home/dot_config/shell/exports.sh.tmpl b/home/dot_config/shell/exports.sh.tmpl index 0ed4d8a0..9e456b97 100644 --- a/home/dot_config/shell/exports.sh.tmpl +++ b/home/dot_config/shell/exports.sh.tmpl @@ -195,6 +195,7 @@ export PATH="$PATH:$DETA_INSTALL/bin" ### Docker export DOCKER_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/docker" +export DOCKER_HOST="unix:///var/run/docker.sock" export MACHINE_STORAGE_PATH="${XDG_DATA_HOME:-$HOME/.local/share}/docker-machine" export PATH="$DOCKER_CONFIG/cli-plugins:$PATH" diff --git a/home/dot_local/bin/executable_installx b/home/dot_local/bin/executable_installx new file mode 100644 index 00000000..4eb2623e --- /dev/null +++ b/home/dot_local/bin/executable_installx @@ -0,0 +1,94 @@ +#!/usr/bin/env zx +import osInfo from 'linux-os-info' + +let archType, osId, osType + +async function getOsInfo() { + return osInfo({ mode: 'sync' }) +} + +function getPkgData(pref, pkg) { + if (pkg[`${pref}:${this.osType()}:${this.osArch()}`]) { + // Handles case like `pipx:windows:x64:` + return `${pref}:${this.osType()}:${this.osArch()}` + } else if (pkg[`${pref}:${this.osId()}:${this.osArch()}`]) { + // Handles case like `pipx:debian:x64:` + return `${pref}:${this.osId()}:${this.osArch()}` + } else if (pkg[`${pref}:${this.osType()}`]) { + // Handles case like `pipx:darwin:` + return `${pref}:${this.osType()}` + } else if (pkg[`${pref}:${this.osId()}`]) { + // Handles case like `pipx:fedora:` + return `${pref}:${this.osType()}` + } else if (pkg[`${pref}`]) { + // Handles case like `pipx:` + return `${pref}` + } +} + +async function getSoftwareDefinitions() { + try { + return YAML.parse(fs.readFileSync(`${os.homedir()}/.local/share/chezmoi/software.yml`, 'utf8')) + } catch (e) { + throw Error('Failed to load software definitions', e) + } +} + +async function getSystemType() { + if (process.platform === "win32") { + return "windows" + } else if (process.platform === "linux") { + if (which.sync('apk')) { + return "apk" + } else if (which.sync('apt-get')) { + return "apt" + } else if (which.sync('dnf')) { + return "dnf" + } else if (which.sync('pacman')) { + return "pacman" + } else if (which.sync('zypper')) { + return "zypper" + } else { + return "linux" + } + } else { + return process.platform + } +} + + +async function main() { + const initData = await Promise.all([getOsInfo(), getSoftwareDefinitions(), getSystemType()]) + archType = initData[0].arch + osId = process.platform === 'win32' ? 'win32' : (process.platform === 'linux' ? initData[0].id : process.platform) + osType = process.platform === 'win32' ? 'windows' : process.platform + const installOrder = initData[1].installOrderPreferences + const softwarePackages = initData[1].softwarePackages + const sysType = initData[2] + const installKeys = argv._ + const installInstructions = softwarePackages + .filter(i => installKeys.includes(i)) + .filter(async i => { + const binField = getPkgData('_bin', i) + const whenField = getPkgData('_when', i) + const binCheck = i[binField] && await which(i[binField], { nothrow: true }) + const whenCheck = i[whenField] && await $`${i[whenField]}`.exitCode == 0 + return (i[binField] && !binCheck) || (i[whenField] && whenCheck) + }) + .map(i => { + for (const pref of installOrder) { + const pkgData = getPkgData(pref, i) + if (pkgData) { + return { + ...x, + installKey + } + } + } + return false + }) + .filter(i => !!i) + console.log(installInstructions) +} + +main() diff --git a/software.yml b/software.yml index e425a8d3..313bcbb5 100644 --- a/software.yml +++ b/software.yml @@ -94,6 +94,7 @@ installerPreference: - cargo - npm - pipx + - pip - gem - appimage - script @@ -110,6 +111,7 @@ installerPreference: - cargo - npm - pipx + - pip - gem - pkg-darwin - script @@ -126,6 +128,7 @@ installerPreference: - cargo - npm - pipx + - pip - gem - appimage - script @@ -151,6 +154,7 @@ installerPreference: - cargo - npm - pipx + - pip - gem - appimage - script @@ -167,6 +171,7 @@ installerPreference: - cargo - npm - pipx + - pip - gem - appimage - script @@ -3252,6 +3257,11 @@ softwarePackages: fi logg info 'Headlessly authenticating with DockerHub registry' && echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin > /dev/null && logg success 'Successfully authenticated with DockerHub registry' fi + + ### Symlink on macOS + if [ -f "$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock" ]; then + logg info 'Symlinking /var/run/docker.sock to macOS Library location' && sudo ln -s "$HOME/Library/Containers/com.docker.docker/Data/docker.raw.sock" /var/run/docker.sock + fi apt: https://desktop.docker.com/linux/main/amd64/docker-desktop-4.16.2-amd64.deb cask: docker choco: docker-desktop