Skip to content

Commit

Permalink
FIRST ALPHA!!
Browse files Browse the repository at this point in the history
+ Clunky
+ Seems to work in Debian 12.
  • Loading branch information
iangullo committed Apr 19, 2023
1 parent 0409498 commit eef5851
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .fpm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
--depends 'libpq-dev > 12.0'
--depends 'nodejs > 12.0'
--depends 'nginx > 1.18'
--after-install src/scripts/mudclub-build.sh
--config-files src/config/mudclub
--after-install src/scripts/install.sh
--after-upgrade src/scripts/mudclub-update.sh
--before-remove src/scripts/mudclub-remove.sh
src/scripts/mudclub-start.sh=/usr/local/bin/mudclub-start
Expand Down
Binary file modified build/mudclub-server_0.1.0_all.deb
Binary file not shown.
14 changes: 14 additions & 0 deletions src/config/mudclub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# MudClub - Simple Rails app to manage a team sports club.
# Copyright (C) 2023 Iván González Angullo
#
# Configuration file - you may modify the options here to your
# system.

# Assuming this to be a production server
RAILS_ENV='production'

# Posstgresql connection parameters
DB_HOST='localhost'
DB_USERNAME='mudclub'
DB_PASSWORD='EtClausi'
DB_NAME='mudclub'
85 changes: 40 additions & 45 deletions src/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,70 +9,65 @@ export BUNDLE="~/bin/bundle"
export RAILS="~/bin/rails"
echo "MudClub: Rails server app for sports clubs..."
echo "============================================="
printf " * Creating '%s' folder in '%s'..." $MUDCLUB $MUDHOME
printf "* Creating '%s' folder in '%s'..." $MUDCLUB $MUDHOME
if mkdir -p $MUDHOME 2> /dev/null ; then
echo "OK"
cd $MUDHOME
printf " * Creating '$MUDCLUB' user..."
printf "* Creating '$MUDCLUB' user..."
adduser $MUDCLUB --disabled-password --gecos "" --quiet --home $MUDHOME --shell /bin/bash 2> /dev/null
chown -R $MUDCLUB $MUDHOME 2> /dev/null
echo "OK"
printf " * Getting source code..."
cd $SRVPATH
if su $MUDCLUB -c "git clone https://github.com/iangullo/mudclub.git 2> /dev/null"; then
printf "* "
if su $MUDCLUB -c "git clone https://github.com/iangullo/mudclub.git"; then
# prepare bash environment
printf "* Copying default configuration..."
su - $MUDCLUB -c 'cp /etc/skel/.profile .'
su - $MUDCLUB -c 'cp /etc/skel/.bashrc .'
su - $MUDCLUB -c 'echo "export PATH=$MUDHOME/vendor/bundle/ruby/3.1.0/bin:$MUDHOME/bin:/usr/bin:/usr/local/bin" >> .bashrc'
su - $MUDCLUB -c 'echo "export RAILS_ENV=production >> .bashrc'
su - $MUDCLUB -c 'echo "export DB_HOST=localhost" >> .bashrc'
su - $MUDCLUB -c 'echo "export DB_USERNAME=mudclub" >> .bashrc'
su - $MUDCLUB -c 'echo "export DB_PASSWORD=" >> .bashrc'
su - $MUDCLUB -c 'echo "export DB_NAME=mudclub" >> .bashrc'
ln -s /etc/mudclub $MUDHOME/.env
su - $MUDCLUB -c 'echo "# Override PATH" >> .bashrc'
su - $MUDCLUB -c 'echo PATH="~/vendor/bundle/ruby/3.1.0/bin:~/bin:/usr/bin:/usr/local/bin" >> .bashrc'
su - $MUDCLUB -c 'echo "# Load mudclub environment file" >> .bashrc'
su - $MUDCLUB -c 'echo "if [ -f .env ]; then" >> .bashrc'
su - $MUDCLUB -c 'echo " set -o allexport; source .env; set +o allexport" >> .bashrc'
su - $MUDCLUB -c 'echo "fi" >> .bashrc'
echo "OK"
printf "* Installing necesssary gems...\n "
su - $MUDCLUB -c "$BUNDLE config set --local path 'vendor/bundle' 2> /dev/null" 2> /dev/null
su - $MUDCLUB -c "$BUNDLE config set --local without 'development test' 2> /dev/null" 2> /dev/null
su - $MUDCLUB -c "$BUNDLE install 2> /dev/null" 2> /dev/null
# rails server preparation
printf "* Creating secrets..."
RAILS_SEC=`su - $MUDCLUB -c "$RAILS secret"`
su - $MUDCLUB -c "printf \" %s\n\" $RAILS_SEC >> ~/config/secrets.yml"
echo "OK"
printf " * Installing necesssary gems...\n\t"
su - $MUDCLUB -c "$BUNDLE config set --local path 'vendor/bundle'" 2> /dev/null
su - $MUDCLUB -c "$BUNDLE config set --local without 'development test'" 2> /dev/null
su - $MUDCLUB -c "$BUNDLE install" 2> /dev/null
#echo "OK"
# gem install pleaserun
# check postgresql port
#PG_PORT=`pg_conftool show port | cut -d \= -f 2 | xargs`
#if $PG_PORT
#fi
# ensure postgresql user exists
VAL=`su - postgres -c "psql -t -c '\du'" | cut -d \| -f 1 | grep $MUDCLUB`
if ! [[ $VAL ]] ; then
printf " * Creating database user..."
su - postgres -c "createuser -s -d $MUDCLUB -W"
VAL=`su - postgres -c "psql -t -c '\du'" | cut -d \| -f 1 | grep -w $MUDCLUB`
if [ -z $VAL ] ; then
printf "* Creating database user..."
su - postgres -c "psql -c \"CREATE USER $MUDCLUB SUPERUSER LOGIN PASSWORD '$MUDPASS';\""
echo "OK"
fi
# ensure database $MUDCLUB exists
VAL=`su - postgres -c "psql -lqt | cut -d \| -f 1 | grep $MUDCLUB`
if ! [[ $VAL ]] ; then
printf " * Creating database..."
su - postgres -c "createdb $MUDCLUB --owner=$MUDCLUB"
su - mudclub -c "psql create extension unaccent"
VAL=`su - postgres -c "psql -lqt | cut -d \| -f 1 | grep -w $MUDCLUB"`
if [ -z $VAL ] ; then
printf "* Creating database..."
su - mudclub -c "rails db:create 2> /dev/null" 2> /dev/null
su - mudclub -c "psql create extension unaccent 2> /dev/null" 2> /dev/null
echo "OK"
fi
# rails server preparation
printf " * Creating secrets..."
RAILS_SEC=`su - $MUDCLUB -c "$RAILS secret"`
RAILS_SEC="secret_key_base: $RAILS_SEC"
su - $MUDCLUB -c "echo $RAILS_SEC >> .bashrc"
echo "OK"
# rails server preparation
printf " * Migrating database..."
su - $MUDCLUB -c "$RAILS db:migrate"
echo "OK"
printf " * Compiling assets..."
su - $MUDCLUB -c "$RAILS assets:precompile"
echo "OK"
printf " * Adding site to Nginx..."
printf "* Migrating database..."
su - $MUDCLUB -c "$RAILS db:migrate 2> /dev/null" 2> /dev/null
su - $MUDCLUB -c "$RAILS db:seed 2> /dev/null" 2> /dev/null
echo "OK"
rm /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/mudclub /etc/nginx/sites-enabled/mudclub
nginx -t && systemctl reload nginx
printf "* Compiling assets..."
su - $MUDCLUB -c "npm install flowbite 2> /dev/null" 2> /dev/null
su - $MUDCLUB -c "$RAILS assets:precompile 2> /dev/null" 2> /dev/null
printf "* Adding site to Nginx..."
rm /etc/nginx/sites-enabled/default 2> /dev/null
ln -s /etc/nginx/sites-available/mudclub /etc/nginx/sites-enabled/mudclub 2> /dev/null
nginx -t && systemctl reload nginx 2> /dev/null
# pleaserun --name $MUDCLUB --user $MUDCLUB --overwrite --description "MudClub service definition" --chdir $MUDHOME /bin/bash -lc 'rails server -e production'
echo "================================"
echo "MudClub: Successfully built!"
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/mudclub-remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ nginx -t 2> /dev/null && systemctl reload nginx 2> /dev/null
echo "OK"
cd $MUDHOME
printf " * Deleting database..."
su - postgres -c "dropdb $MUDCLUB\_$RAILS_ENV"
if (su - postgres -c "psql -t -c '\du'" | cut -d \| -f 1 | grep -qw $MUDCLUB) ; then
su - $MUDCLUB -c "rails db:drop"
VAL=`su - postgres -c "psql -t -c '\du'" | cut -d \| -f 1 | grep -w $MUDCLUB`
if [ ! -z $VAL ] ; then
su - postgres -c "dropuser $MUDCLUB"
fi
echo "OK"
Expand Down
33 changes: 15 additions & 18 deletions src/scripts/mudclub-update.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
#!/bin/bash
# Update script for MudClub - pulls from git and rebuilds application
MUDCLUB=mudclub
MUDHOME=/srv/rails/$MUDCLUB
export MUDCLUB="mudclub"
export MUDHOME="/srv/rails/$MUDCLUB"
echo "MudClub: Trying to update..."
puts "================================"
echo "================================"
cd $MUDHOME
print " * Pulling code..."
if git pull
puts "OK"
print " * Checking necesssary gems..."
bundle --without 'development' 'test'
puts "OK"
print " * Migrating database..."
rails db:migrate -e production
puts "OK"
print " * Compiling assets..."
rails assets:precompile
puts "OK"
print " * Restarting service..."
if su - $MUDCLUB -c "git pull" ; then
printf "* Checking necesssary gems...\n "
su - $MUDCLUB -c "bundle"
printf "* Migrating database..."
su - $MUDCLUB -c "rails db:migrate -e production" 2> /dev/null
echo "OK"
printf "* Compiling assets..."
su - $MUDCLUB -c "rails assets:precompile" 2> /dev/null
echo "OK"
printf "* Restarting service..."
systemctl restart $MUDCLUB.service
puts "OK"
puts "================================"
echo "OK"
echo "================================"
echo >&2 "MudClub: Successfully updated!"
exit 0
else
Expand Down

0 comments on commit eef5851

Please sign in to comment.