Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup.sh #1630

Merged
merged 8 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions config/setup.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/bin/bash
# Written by Greg Post

# Global variables
# Do not change these values unless you know what you are doing
TEMPLATE_SUFFIX='_template'
TEMPLATE_PATHS=('../config/' '../' '../includes/')
WRITABLE_PATHS=('../temp' '../content' '../api/storage/framework' '../api/storage/logs')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are any _template files in the /content directory anymore. Except for the labeljson_template.php, but that is converted dynamically via the user interface, rather than needing to be converted on setup. You should be able to remove /content from the WRIATABLE_PATHS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /content folder is not searched for _template files. It is however in the array to be made writable by the webserver.


FORCEWRITE=0
TESTMODE=0
VERBOSE=0
BASHTOOOLD=0

options=$(getopt -o fhtv -l force,test,help,verbose -n "$SCRIPTNAME" -- "$@")

#sanity checks

if ((BASH_VERSINFO[0] < 3))
then
BASHTOOOLD=1
elif ((BASH_VERSINFO[0] < 5))
then
if ((BASH_VERSINFO[1] < 4))
then
BASHTOOOLD=1
fi
fi

if [[ "$BASHTOOOLD" == "1" ]]
then
echo "Sorry, you need at least bash-4.4 to run this script. Please use setup_pre_4.4.bash"
exit 1
fi

currentDir=${PWD##*/}
if [ "$currentDir" != "config" ]
then
echo "This script should be executed in the 'Symbiota'/config folder"
exit 1
fi

#functions
usage(){ # Function: Print a help message.
echo " Usage: $SCRIPTNAME [-h|--help -t|--test -f|--force -v|--verbose]" 1>&2
}

printHelp(){
echo
echo 'Symbiota setup script'
echo
usage
cat <<End-of-message

This script creates initial files that can then be customized/configured as desired

Optional paramters:

-h |--help Print this help screen
-t |--test Test execution - makes no changes
-f |--force Force overwrite - will not prompt if a file will be overwritten **DANGER**
-v |--verbose More verbose output
End-of-message
exit 0
}

copyFromTemplate(){

local destinationPath="${1}"
local regX='(.*)'"$TEMPLATE_SUFFIX"'(.*)'
local templateArray

echo
echo "Searching ${destinationPath} for templates"
readarray -d '' templateArray < <(find "${destinationPath}" -maxdepth 1 -name '*'"${TEMPLATE_SUFFIX}"'*' -print0)
for i in "${templateArray[@]}"
do
echo "found file: $i"
if [[ $i =~ $regX ]]
then
local destinationFile=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
else
echo "Error: Could not calculate target filename"
exit 1
fi

if [ -f "${destinationFile}" ]
then
echo "File ${destinationFile} already exists"
if [ "$FORCEWRITE" -eq "0" ]
then
continue
fi
fi

if [ "$TESTMODE" -eq "1" ]
then
echo "cp ${i} ${destinationFile}"
continue
fi

if cp "${i}" "${destinationFile}"
then
echo "Copied ${i} to ${destinationFile}"
else
echo "Error copying ${i} to ${destinationFile}"
fi

done
}

# Main

eval set -- "${options}"
unset options

for var in "$@"
do
case "$var" in
-f | --force )
FORCEWRITE=1; shift ;;
-t | --test )
TESTMODE=1; shift ;;
-v | --verbose )
VERBOSE=1; shift ;;
-h | --help )
printHelp; shift ;;
esac
done

if [[ "$FORCEWRITE" == "1" && "$TESTMODE" == "1" ]]
then
echo
echo 'Error: Cannot set both "test" and "force" modes at the same time.'
usage
exit 1
fi

if [[ "$TESTMODE" == "1" ]]
then
echo
echo '*******'
echo 'Test Mode - no changes will be made'
echo
echo '*******'
fi

# Iterate over list of paths that contain template files
echo
echo "** Copying template files to destination"
for relPath in "${TEMPLATE_PATHS[@]}"
do
if ! copyFromTemplate "${relPath}"
then
echo "An error occured when processing ${relPath}"
fi
done

#Adjust file permission to give write access to certain folders and files
echo
echo "** Adjusting file permissions"

for wPath in "${WRITABLE_PATHS[@]}"
do
echo
echo "Setting subdirectories of ${wPath} to be writable"

readarray -d '' writableDirs < <(find "${wPath}" -type d -print0)

for wDir in ${writableDirs[@]}
do
if [[ "$VERBOSE" == "1" ]]
then
echo "chmod 777 $wDir"
fi

if [[ "$TESTMODE" == "1" ]]
then
continue
fi

if ! chmod 777 "$wDir"
then
echo "Error setting permission on $wDir"
fi
done
done


exit 0

File renamed without changes.
78 changes: 43 additions & 35 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,22 @@
1. Download Symbiota code from GitHub repository
- (https://github.com/BioKIC/Symbiota)
- Command line checkout (recommended): git clone https://github.com/BioKIC/Symbiota.git
2. Install Symbiota database schema
2. Configure the Symbiota Portal
1. Run /config/setup.bash (e.g. sudo bash setup.bash)
This scripts will attempt to:
- find all _template.* files and copy them to a new file at the same location without the '_template' suffix
- set ACL permisions on folders that need to be writable by the web server:
- /api/storage/framework
- /api/storage/logs
- /content/collections/
- /content/collicon/
- /content/dwca/
- /content/geolocate/
- /content/logs/
- /temp/
2. Symbiota initialization configuration
- Modify variables within config/symbini.php to match your project environment. See Symbiota configuration help page for more information on this subject.
3. Install Symbiota database schema
1. Create new database (e.g. CREATE SCHEMA symbdb CHARACTER SET utf8 COLLATE utf8_general_ci)
2. Create read-only and read/write users for Symbiota database
- CREATE USER 'symbreader'@'localhost' IDENTIFIED BY 'password1';
Expand All @@ -26,40 +41,33 @@
3. Load base database schema from scripts: <SymbiotaBaseFolder>/config/schema/3.0/db_schema-3.0.sql
- Run db_schema-3.0.sql to install the core table structure
- From MySQL commandline: SOURCE <BaseFolderPath>/config/schema/3.0/db_schema-3.0.sql
4. If needed, run database patch scripts to bring database up to current structure
- Make sure to run the scripts in the correct order e.g. db_schema_patch-3.1.sql, db_schema_patch-3.2.sql, etc.
- From MySQL commandline: SOURCE /BaseFolderPath/config/schema/3.0/patches/db_schema_patch-3.x.sql
3. Configure the Symbiota Portal - modify following configuration files; running /config/setup.sh will create the following required files and permissions
1. Symbiota configuration
- rename /config/symbini_template.php to /config/symbini.php.
- Modify variables within to match your project environment. See Symbiota configuration help page for more information on this subject.
2. Database connection
- Rename /config/dbconnection_template.php to /config/dbconnection.php.
- Modify with readonly and read/write logins, passwords, and schema names.
3. Homepage
- Rename /index_template.php to index.php. This is your home page to which will need introductory text, graphics, etc.
4. Layout - Within the /includes directory, rename header_template.php to header.php, and
footer_template.php to footer.php. The header.php and footer.php files are used by all
pages to establish uniform layout. left_menu.php is needed if a left menu is preferred.
- header.php: Within file, change /images/layout/defaultheader.jpg
to /images/layout/header.jpg. Add your header to /images/layout/
folder. Establishing the header using an image is easy, yet more
complex header configurations are possible.
- footer.php: modify as you did with header.php file.
5. Files for style control - Within the /includes directory, rename head_template.php to head.php
The head.php file is included within the <head> tag of each page.
Thus, you can modify this file to globally change design of portal.
6. Misc: rename usagepolicy_template.php to usagepolicy.php, and modify as needed
4. File permissions - the web server needs write access to the following files and their subdirectories (e.g. sudo chmod -R 777 temp/)
- /api/storage/framework
- /api/storage/logs
- /content/collections/
- /content/collicon/
- /content/dwca/
- /content/geolocate/
- /content/logs/
- /temp/
5. Misc configurations and recommendations
4. Modify config/dbconnection.php with readonly and read/write logins, passwords, and schema (DB) names.
5. If needed, run database patch scripts to bring database up to current structure
- Method 1: Using a web browser
- Navigate to <SymbiotaServer>/admin/schemamanager.php
- Follow the prompts provided by the database schema assistant
- Method 2: MySQL commandline
- From MySQL commandline run each schema patch: SOURCE /BaseFolderPath/config/schema/3.0/patches/db_schema_patch-3.x.sql
- Make sure to run the scripts in the correct order e.g. db_schema_patch-3.1.sql, db_schema_patch-3.2.sql, etc.

`NOTE: At this point you should have an operational "out of the box" Symbiota portal.`

6. Homepage
- Modify index.php. This is your home page or landing page to which will need introductory text, graphics, etc.
7. Layout - Within the /includes directory the header.php and footer.php files are used by all
pages to establish uniform layout.
- header.php: determines the content of the global page header and menu navigation.
- footer.php: determines the content of the global page footer.
8. Files for style control - Within the css/symbiota folder there are two files you can modify to change the appearance of the portal:
- variables.css - Modify this file to set global values used across the portal
- customization.css - Add css selectors to this file to override Symbiota's default styling on specific html elemments
- NOTE: Do not modify any other css files as these files may be over written in future updates
9. Customize language tags
- Overide existing language tags or create new tags by modifying the override files in content/lang/templates/
- Example: modify content/lang/templates/header.es.override.php to replace the defualt values used when browsing the portal in spanish.
10. Misc:
- Modify usagepolicy.php as needed
4. Misc configurations and recommendations
- Install robots.txt file within root directory - The robots.txt file is a standard method used by websites to indicate to visiting web crawlers and other web robots which portions of the website they are allowed to visit and under what conditions. A robots.txt template can be found within the /includes directory. This file should be moved into the domain's root directory, which may or may not be the Symbiota root directory. The file paths listed within the file should be adjusted to match the portal installation path (e.g., start with $CLIENT_ROOT). See links below for more information:
- https://developers.google.com/search/docs/crawling-indexing/robots/create-robots-txt
- https://en.wikipedia.org/wiki/Robots.txt
Expand Down