forked from egbot/Symbiota
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Update setup.sh #1630
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e92697
Update setup.sh
GregoryPost 0e52c80
Merge branch 'Development' into setup_bash_improvements
GregoryPost 7b00353
Update setup.sh
GregoryPost 0e2845f
Update setup.sh
GregoryPost e2b9594
Update setup.sh
GregoryPost c9a48cd
Update setup.sh
GregoryPost 274240d
setup updates.
GregoryPost d5773a5
requested changes
GregoryPost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
||
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.