2024-08-10 17:37:04 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
##@Version : 202408091436-git
|
|
|
|
# @@Author : CasjaysDev
|
|
|
|
# @@Contact : CasjaysDev <docker-admin@casjaysdev.pro>
|
|
|
|
# @@License : MIT
|
|
|
|
# @@ReadME :
|
|
|
|
# @@Copyright : Copyright 2023 CasjaysDev
|
|
|
|
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023
|
|
|
|
# @@File : 04-users.sh
|
|
|
|
# @@Description : script to run users
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# shellcheck shell=bash
|
|
|
|
# shellcheck disable=SC2016
|
|
|
|
# shellcheck disable=SC2031
|
|
|
|
# shellcheck disable=SC2120
|
|
|
|
# shellcheck disable=SC2155
|
|
|
|
# shellcheck disable=SC2199
|
|
|
|
# shellcheck disable=SC2317
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Set bash options
|
2024-08-12 18:30:40 -04:00
|
|
|
set -o pipefail
|
2024-09-04 14:47:48 -04:00
|
|
|
set -o errexit
|
|
|
|
set -o verbose
|
|
|
|
set -o xtrace
|
2024-08-10 17:37:04 -04:00
|
|
|
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Set env variables
|
|
|
|
exitCode=0
|
2024-09-04 13:24:05 -04:00
|
|
|
AUR_UID="9000"
|
2024-09-04 12:51:12 -04:00
|
|
|
AUR_USER="${AUR_USER:-aur}"
|
2024-09-04 13:24:05 -04:00
|
|
|
AUR_GROUP="${AUR_GROUP:-$AUR_USER}"
|
2024-09-04 12:51:12 -04:00
|
|
|
AUR_HOME="${AUR_HOME:-/var/lib/aur}"
|
|
|
|
AUR_BUILD_DIR="${AUR_BUILD_DIR:-${AUR_HOME}/build}"
|
2024-09-04 14:51:13 -04:00
|
|
|
export GOFLAGS="-buildvcs=false" CGO_ENABLED=0 GOOS=linux
|
|
|
|
case "$(uname -m)" in x86_64) export GOARCH=amd64 ;; aarch64) export GOARCH=arm64 ;; esac
|
2024-08-10 17:37:04 -04:00
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Main script
|
2024-09-04 13:56:30 -04:00
|
|
|
rm -Rf "$AUR_BUILD_DIR/yay"
|
2024-09-04 13:24:05 -04:00
|
|
|
if ! grep -sq "^$AUR_GROUP:" /etc/group; then
|
|
|
|
echo "Creating group: $AUR_GROUP"
|
|
|
|
groupadd -r -g $AUR_UID $AUR_GROUP
|
|
|
|
fi
|
|
|
|
if ! grep -sq "^$AUR_USER:" /etc/passwd; then
|
|
|
|
echo "Creating user: $AUR_USER"
|
|
|
|
useradd -m -r -s /bin/bash -d "${AUR_HOME}" -u $AUR_UID -g $AUR_UID "$AUR_USER" && passwd -d "$AUR_USER"
|
|
|
|
fi
|
|
|
|
grep -sq "^$AUR_USER:" /etc/passwd && grep -sq "^$AUR_GROUP:" /etc/group && chown -Rf $AUR_USER:$AUR_GROUP "$AUR_HOME" || exit 1
|
|
|
|
if [ -n "$(type -P sudo)" ] && grep -sq "^$AUR_USER:" /etc/passwd; then
|
|
|
|
mkdir -p "/etc/sudoers.d"
|
|
|
|
echo ''$AUR_USER' ALL=(ALL) ALL' >"/etc/sudoers.d/$AUR_USER"
|
|
|
|
fi
|
|
|
|
mkdir -p "$AUR_BUILD_DIR/yay"
|
|
|
|
if ! grep -qs "standard-resolver" "$AUR_HOME/.gnupg/dirmngr.conf"; then
|
2024-09-04 13:44:30 -04:00
|
|
|
mkdir -p "$AUR_HOME/.gnupg"
|
2024-09-04 13:24:05 -04:00
|
|
|
echo 'standard-resolver' >"$AUR_HOME/.gnupg/dirmngr.conf"
|
|
|
|
fi
|
2024-09-04 12:51:12 -04:00
|
|
|
if [ -z "$(command -v yay 2>/dev/null)" ]; then
|
2024-09-04 13:24:05 -04:00
|
|
|
if cd "$AUR_BUILD_DIR/yay"; then
|
2024-09-04 12:51:12 -04:00
|
|
|
[ -n "$(type -P git)" ] && git config --global init.defaultBranch main
|
2024-09-04 14:03:26 -04:00
|
|
|
chmod -R 777 "$AUR_BUILD_DIR"
|
2024-09-04 14:38:29 -04:00
|
|
|
git clone --depth 1 "https://aur.archlinux.org/yay-bin" "." && rm -Rf ".git"
|
2024-09-04 15:01:48 -04:00
|
|
|
sudo -u "$AUR_USER" makepkg -sri --needed --noconfirm -si || exit 1
|
|
|
|
sudo -u "$AUR_USER" yay --afterclean --removemake --save && pacman -Qtdq | xargs -r pacman --noconfirm -Rcns
|
2024-09-04 14:44:38 -04:00
|
|
|
[ -d "$AUR_BUILD_DIR" ] && cd && rm -Rf "${AUR_BUILD_DIR:?}"/* "$AUR_HOME/.cache"/*
|
2024-09-04 12:51:12 -04:00
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2024-08-10 17:37:04 -04:00
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
# Set the exit code
|
|
|
|
exitCode=$?
|
|
|
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
|
exit $exitCode
|