76 lines
2.2 KiB
Bash
Executable File
76 lines
2.2 KiB
Bash
Executable File
# Filesystem navigation.
|
|
alias l="ls -lhF --color=always"
|
|
alias ll="ls -AlhF --color=always"
|
|
alias lz="ls -AlhFZ --color=always"
|
|
|
|
mcd() {
|
|
mkdir -p "$1" && cd "$1"
|
|
}
|
|
cdl() {
|
|
cd "$1" && ls -lhF --color=always
|
|
}
|
|
cdll() {
|
|
cd "$1" && ls -AlhF --color=always
|
|
}
|
|
|
|
|
|
# Aliases for Python venv management.
|
|
alias activate="source .venv/bin/activate"
|
|
alias mkvenv="python3 -m venv .venv"
|
|
|
|
# Aliases for common podman/podman compose tasks.
|
|
alias pcup="podman-compose up"
|
|
alias pcupd="podman-compose up -d"
|
|
alias pcdown="podman-compose down"
|
|
alias pps="podman ps"
|
|
alias ccedit="nano container-compose.yaml"
|
|
|
|
# Enable/disable NGINX sites defined in /etc/nginx/sites-available
|
|
# by symlinking it to (or unlinking it from) /etc/nginx/sites-enabled.
|
|
nginx-enable(){
|
|
sudo ln -s "/etc/nginx/sites-available/$1.conf" "/etc/nginx/sites-enabled/$1.conf"
|
|
}
|
|
nginx-disable(){
|
|
sudo rm "/etc/nginx/sites-enabled/$1.conf"
|
|
}
|
|
|
|
# In a subdirectory of /srv/{USER}, run a command as USER.
|
|
alias srvdo='sudo -u $(pwd | cut -d "/" -f3) '
|
|
|
|
create-service-user(){
|
|
# Accepts input in service_name:uid format. Assumes gid=uid.
|
|
service=$(echo $1 | cut -d ':' -f1)
|
|
uid=$(echo $1 | cut -d ':' -f2)
|
|
echo "Creating service user $service ($uid)"
|
|
|
|
# Create group if not exists.
|
|
echo Running groupadd...
|
|
getent group $service || sudo groupadd --system --gid "$uid" "$service"
|
|
|
|
# Create user if not exists.
|
|
echo Running useradd...
|
|
getent passwd $service || sudo useradd --system --uid "$uid" --gid "$uid" \
|
|
--home-dir /var/lib/$service \
|
|
--create-home \
|
|
--shell /sbin/nologin \
|
|
"$service"
|
|
|
|
# Create a directory in /srv for the service.
|
|
echo Creating directory in /srv ...
|
|
sudo mkdir -p /srv/$service
|
|
sudo chown -R $service:$service /srv/$service
|
|
sudo chmod -R 770 /srv/$service
|
|
|
|
sudo loginctl enable-linger "$service"
|
|
|
|
# Add entries in /etc/sub*id; assumes these files are sorted.
|
|
echo Setting up subids...
|
|
last_subid_start=$(tail -1 /etc/subuid | cut -d ':' -f2)
|
|
last_subid_range=$(tail -1 /etc/subuid | cut -d ':' -f3)
|
|
let "next_subid = $last_subid_start + $last_subid_range"
|
|
cat /etc/subuid | grep $service || echo "$service:$next_subid:65536" | sudo tee -a /etc/subuid
|
|
cat /etc/subgid | grep $service || echo "$service:$next_subid:65536" | sudo tee -a /etc/subgid
|
|
|
|
echo Done!
|
|
}
|