This commit is contained in:
jay 2024-04-20 10:23:30 +08:00
parent acab55b91e
commit 4464b3ad06
4 changed files with 166 additions and 0 deletions

View File

@ -0,0 +1,57 @@
#!/bin/bash
set -ex
if [ -z "$1" ]; then
echo "Usage: $0 <go-version>"
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"

View File

@ -0,0 +1,79 @@
#!/bin/bash
set -xe
if [ -z "$1" ]; then
echo "Usage: $0 <node-version>"
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"

30
root/usr/local/bin/sway-dbus.sh Executable file
View File

@ -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