Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
woutervh committed Jun 21, 2024
1 parent 7c41ef9 commit 624f397
Show file tree
Hide file tree
Showing 4 changed files with 225 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bin/uv-create-venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


# create a new python-venv in {{directory}} with python {{python}
uv-create-venv directory=".venv" python="3.9":
#!/usr/bin/env bash
# set -euxo pipefail
set -euo pipefail

# Check if VIRTUAL_ENV is set
if [[ -n "${VIRTUAL_ENV:-}" ]]; then
# Unset the VIRTUAL_ENV environment variable
unset VIRTUAL_ENV
echo "VIRTUAL_ENV was set and has been unset."
fi

# Check if the directory name ends with ".venv"
if [[ {{directory}} != *.venv ]]; then
# If it doesn't end with ".venv", append it
venv_dir="{{directory}}/.venv"
else
venv_dir="{{directory}}"
fi

uv venv $venv_dir --python={{python}} --seed
cd $venv_dir/..
ln -rsf .venv/bin
ln -rsf .venv/lib
ln -rsf .venv/pyvenv.cfg
cd -
1 change: 1 addition & 0 deletions grm
101 changes: 101 additions & 0 deletions postgres/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Just is a crossplatform task-runner, similar to make.
# And justfiles are equivalent to makefiles.
#
# Official docs:
# - https://just.systems/man/en
#
# Usage:
# > just --help
# > just <taskname>
#
# Notes:
# - Comments immediately preceding a recipe will appear in just --list:

# load environment variables from .env file
set dotenv-filename := ".env"
set dotenv-load := true


TMPDIR := absolute_path('var/tmp')
VERSION := "16"


# Help target
help:
@ just --list --unsorted


# clean all
clean:
@ rm -fr bin
@ rm -fr var


# full install postgres
install: create-dirs add-repo install-postgres init-db version

# create directories
create-dirs:
@ mkdir -p bin
@ mkdir -p etc
@ mkdir -p var/tmp

# add repo for postgres
add-repo:
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# https://www.tecmint.com/install-postgresql-rocky-linux/
# sudo dnf -qy module disable postgresql


# install postgres via dnf
install-postgres:
sudo dnf install -y postgresql{{VERSION}} postgresql{{VERSION}}-server

# fix pg_config
fix-pg-config:
sudo alternatives --install /usr/bin/pg_config pgsql-pg_config /usr/pgsql-16/bin/pg_config 930

# run initdb for postgres
init-db:
sudo /usr/pgsql-{{VERSION}}/bin/postgresql-{{VERSION}}-setup initdb

# show version psql
version:
@ echo -e "Version psql:"
@ psql --version

set:
sudo su - postgres && psql

# enable postgres
postgres-enable:
sudo systemctl enable postgresql-{{VERSION}}


# run postgres command (status|start|stop)
postgres cmd='status':
sudo systemctl {{cmd}} postgresql-{{VERSION}}


# show status of postgres
# postgres-status:
# sudo systemctl status postgresql-{{VERSION}}

# # start postgres
# postgres-start cmd='status':
# sudo systemctl start postgresql-{{VERSION}}

# # stop postgres
# postgres-stop:
# sudo systemctl stop postgresql-{{VERSION}}


# change password for postgres user
change-password:
# sudo -u postgres psql -c "SELECT 1"
sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '123'"

# start psql-session
psql:
sudo -u postgres psql
94 changes: 94 additions & 0 deletions uv/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Just is a crossplatform task-runner, similar to make.
# And justfiles are equivalent to makefiles.
#
# Official docs:
# - https://just.systems/man/en
#
# Usage:
# > just --help
# > just <taskname>
#
# Notes:
# - Comments immediately preceding a recipe will appear in just --list:

# load environment variables from .env file
set dotenv-filename := ".env"
set dotenv-load := true

# search for justfiles in parent directories
set fallback

TMPDIR := `realpath var/tmp`


SED := `command -v gsed || command -v sed`
SED1 := `command -v sed`

CMD := `realpath bin/uv`
CMD1 := `shell realpath bin/uv`

# Help target
help:
@ just --list --unsorted


show:
@ echo -e ${SED1}
@ echo -e ${CMD1}


# remove generated files & dirs
clean:
@ rm -fr bin include lib lib64 pyvenv.cfg
@ rm -fr var

# create files and directories
create-dirs:
@ mkdir -p etc
@ mkdir -p var/cache
@ mkdir -p var/tmp

# run all install-steps
install: create-dirs create-venv upgrade-pip install-packages install-dotenv install-symlinks version
@ echo -e "\nAll steps succesfully executed.\n"

# update the current installation
update: freeze upgrade-pip install-packages version

# revert to frozen requirements
revert:
bin/python -m pip install -r etc/requirements.txt

# freeze current requirements
freeze: create-dirs
bin/python -m pip freeze > etc/requirements.txt

# create a virtual python-environment
create-venv:
python3 -m venv .

# upgrade pip itself
upgrade-pip:
bin/python -m pip install --upgrade pip

# install python-packages via pip
install-packages:
bin/pip install --upgrade uv autoread-dotenv

# generate .dotenv from template
install-dotenv:
@ echo -e "Copying .env.template to .env"
@ cp -n .env.template .env
@ echo "Please review the config in .env"
@ echo -e "Replacing string __CWD__ -> $(PWD)"
@ $(SED) -i 's@__CWD__@'"$(PWD)"'@' .env

# generate symlinks
install-symlinks:
@ echo -e "Symlink ${CMD} to ${HOME}/bin/"
@ cd ~/bin && ln -sf ${CMD}

# show current version
version:
@ echo -e "\nCurrent version is:"
@ bin/uv --version

0 comments on commit 624f397

Please sign in to comment.