From 4464b3ad0634ca8bcde8c7f23c47d6ac9675cc2c Mon Sep 17 00:00:00 2001 From: jay Date: Sat, 20 Apr 2024 10:23:30 +0800 Subject: [PATCH] update --- home/bin/executable_install-go.sh.tmpl | 57 +++++++++++++ home/bin/executable_install-node.sh.tmpl | 79 +++++++++++++++++++ root/usr/local/bin/sway-dbus.sh | 30 +++++++ .../local/bin/{sway.sh => sway-systemd.sh} | 0 4 files changed, 166 insertions(+) create mode 100644 home/bin/executable_install-go.sh.tmpl create mode 100644 home/bin/executable_install-node.sh.tmpl create mode 100755 root/usr/local/bin/sway-dbus.sh rename root/usr/local/bin/{sway.sh => sway-systemd.sh} (100%) diff --git a/home/bin/executable_install-go.sh.tmpl b/home/bin/executable_install-go.sh.tmpl new file mode 100644 index 0000000..f53ac50 --- /dev/null +++ b/home/bin/executable_install-go.sh.tmpl @@ -0,0 +1,57 @@ +#!/bin/bash + +set -ex + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# chezmoi will replace the OS and ARCH variables +ARCH="{{ .chezmoi.arch }}" +OS="{{ .chezmoi.os }}" + +if [ ! -d "$HOME/apps" ]; then + if ! mkdir -p "$HOME/apps"; then + >&2 echo "Failed to create $HOME/apps" + exit 1 + fi +fi + +deleteTmpDir() { + if [ -d "$1" ]; then + rm -rf "$1" + fi +} + +TMP_DIR=$(mktemp -d) + +trap 'deleteTmpDir '"$TMP_DIR"'' EXIT + +install_go() { + + local url="https://go.dev/dl/go$1.$OS-$ARCH.tar.gz" + + if ! wget -O "$TMP_DIR/go.tar.gz" "$url"; then + >&2 echo "Failed to download $url" + return 1 + fi + + if ! tar zxf "$TMP_DIR/go.tar.gz" -C "$TMP_DIR"; then + >&2 echo "Failed to extract $TMP_DIR/go.tar.gz" + return 1 + fi + + mv "$TMP_DIR/go" "$HOME/apps/go-$1" + + # relink go folder to the new version + if [ -L "$HOME/apps/go" ]; then + unlink "$HOME/apps/go" + fi + + ln -s "$HOME/apps/go-$1" "$HOME/apps/go" + + return 0 +} + +install_go "$1" diff --git a/home/bin/executable_install-node.sh.tmpl b/home/bin/executable_install-node.sh.tmpl new file mode 100644 index 0000000..8a7d64a --- /dev/null +++ b/home/bin/executable_install-node.sh.tmpl @@ -0,0 +1,79 @@ +#!/bin/bash + +set -xe + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +# chezmoi will replace the OS and ARCH variables +ARCH="{{ .chezmoi.arch }}" +OS="{{ .chezmoi.os }}" + +if [ ! -d "$HOME/apps" ]; then + if ! mkdir -p "$HOME/apps"; then + >&2 echo "Failed to create $HOME/apps" + exit 1 + fi +fi + +deleteTmpDir() { + if [ -d "$1" ]; then + rm -rf "$1" + fi +} + +TMP_DIR=$(mktemp -d) + +trap 'deleteTmpDir '"$TMP_DIR"'' EXIT + +install_nodejs() { + local arch="" + + NODE_VERSION=$1 + + case "$ARCH" in + "amd64") + arch="x64" + ;; + "arm64") + arch="arm64" + ;; + *) + >&2 echo "arch ($ARCH) not support" + return 1 + ;; + esac + + local url="https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-${OS}-${arch}.tar.xz" + + if ! wget -O "$TMP_DIR/node.tar.xz" "$url"; then + >&2 echo "Failed to download $url" + return 1 + fi + + if ! tar xf "$TMP_DIR/node.tar.xz" -C "$TMP_DIR"; then + >&2 echo "Failed to extract $TMP_DIR/node.tar.xz" + return 1 + fi + + dirs=$(find "$TMP_DIR" -maxdepth 1 -type d -name "node*") + + if [ -z "$dirs" ]; then + >&2 echo "Failed to find node folder" + return 1 + fi + + mv "$dirs" "$HOME/apps/node-v$NODE_VERSION" + + if [ -L "$HOME/apps/node" ]; then + unlink "$HOME/apps/node" + fi + + ln -s "$HOME/apps/node-v$NODE_VERSION" "$HOME/apps/node" + + return 0 +} + +install_nodejs "$1" diff --git a/root/usr/local/bin/sway-dbus.sh b/root/usr/local/bin/sway-dbus.sh new file mode 100755 index 0000000..c102643 --- /dev/null +++ b/root/usr/local/bin/sway-dbus.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +set -eu + +export XDG_CURRENT_DESKTOP=sway # xdg-desktop-portal +export XDG_SESSION_DESKTOP=sway # systemd +export XDG_SESSION_TYPE=wayland # xdg/systemd + +#if command -v dbus-update-activation-environment >/dev/null; then +# dbus-update-activation-environment XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE +#fi +# without this, systemd starts xdg-desktop-portal without these environment variables, +# and the xdg-desktop-portal does not start xdg-desktop-portal-wrl as expected +# https://github.com/emersion/xdg-desktop-portal-wlr/issues/39#issuecomment-638752975 +#systemctl --user import-environment XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE + +# use systemd-run here, because systemd units inherit variables from ~/.config/environment.d +# shellcheck disable=SC2068 +#systemd-run --quiet --unit=sway --user --wait sway $@ +#systemctl --user stop sway-session.target + +#systemctl --user unset-environment DISPLAY SWAYSOCK WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE +#if command -v dbus-update-activation-environment >/dev/null; then +# dbus-update-activation-environment XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE +#fi +#dbus-launch --exit-with-session sway +dbus-run-session sway + +# this teardown makes it easier to switch between compositors +unset DISPLAY SWAYSOCK WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_TYPE diff --git a/root/usr/local/bin/sway.sh b/root/usr/local/bin/sway-systemd.sh similarity index 100% rename from root/usr/local/bin/sway.sh rename to root/usr/local/bin/sway-systemd.sh