Created
December 17, 2015 03:03
-
-
Save mertsalik/a6b2a92517cf9ddd5e96 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#### FUNCTIONS & DEFINITIONS | |
local_setup_base_dir="/Users/kutumubu/Kutumubu/" | |
#local_setup_base_dir="/Users/mertsalik/Desktop/setuptest" | |
local_setup_destination="$local_setup_base_dir/source" | |
local_compiled_source_destination="$local_setup_base_dir/server_compiled/*" | |
local_production_destination="$local_setup_base_dir/server/" | |
version_file_on_server="/Volumes/home/Kutumubu/version.txt" | |
version_file_on_localhost="$local_setup_base_dir/version.txt" | |
source_mount_point="/Volumes/home" | |
source_path="/Volumes/home/Kutumubu/server/*" | |
#### START | |
echo "THIS IS THE SET-UP SCRIPT FOR KUTUMUBU SERVERS. Use carefully!" | |
echo -n Username: | |
read username | |
echo -n Password: | |
read -s password | |
echo "" | |
sofyo_nas_home_dir="afp://$username:[email protected]/home" | |
mkdir $source_mount_point | |
if [ $? -ne 0 ] ; then | |
# ok we already created the folder before ... | |
echo "Seems already connected before, un-mounting." | |
umount $source_mount_point | |
mkdir $source_mount_point | |
else | |
echo "Created mount point at $source_mount_point ..." | |
fi | |
will_setup=0 | |
mount_afp $sofyo_nas_home_dir $source_mount_point | |
if [ $? -ne 0 ] ; then | |
echo $? | |
echo "Cant mount the sofyo-nas. Check Internet connections!" | |
else | |
echo "Successfully mounted the sofyo-nas!" | |
# Compare version files | |
server_version=`cat $version_file_on_server` | |
echo "Server Version:$server_version" | |
touch $version_file_on_localhost | |
local_version=`cat $version_file_on_localhost` | |
echo "Local Version:$local_version" | |
if [ "$server_version" == "$local_version" ]; then | |
# up to date ;) | |
echo "System up to date!" | |
else | |
# found new version on server - have to update | |
echo "Update available!" | |
rsync -r $source_path $local_setup_destination | |
if [ $? -ne 0 ] ; then | |
echo "Rsync failed, try copy-paste :)" | |
else | |
echo "Rsync completed!" | |
will_setup=1 | |
umount $source_mount_point | |
fi | |
fi | |
fi | |
if [ $will_setup -ne 0 ] ; then | |
# get setup folder and paste it into local_setup_base_dir | |
echo "Initializing for the compilation" | |
setup_bootstrappers="$local_setup_destination/setup/*" | |
rsync -r $setup_bootstrappers $local_setup_base_dir | |
if [ $? -ne 0 ] ; then | |
echo "Failed to start compilation! Check the server immediately ..." | |
else | |
# rsync successful just compile it | |
go_command="$local_setup_base_dir/compile.command" | |
chmod +x $go_command | |
sh $go_command | |
mkdir -p $local_production_destination | |
rsync -r $local_compiled_source_destination $local_production_destination | |
if [ $? -ne 0 ] ; then | |
# failed | |
echo "Failed to synchronize local running path, contact to administrator!" | |
else | |
source_folder_to_delete="$local_setup_base_dir/server_compiled" | |
rm -rf $source_folder_to_delete | |
source_folder_to_delete="$local_setup_base_dir/source" | |
rm -rf $source_folder_to_delete | |
source_folder_to_delete="$local_setup_base_dir/compile.command" | |
rm -rf $source_folder_to_delete | |
source_folder_to_delete="$local_setup_base_dir/lib" | |
rm -rf $source_folder_to_delete | |
echo "$server_version" > $version_file_on_localhost | |
echo "Update completed." | |
fi | |
fi | |
else | |
# bybye | |
echo "Bye!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment