Last active
December 18, 2015 20:59
-
-
Save weirdbricks/5844056 to your computer and use it in GitHub Desktop.
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
#!/bin/csh | |
#06/24/2013 | |
#Lampros for WeirdBricks | |
#check if curl exists | |
if ( -e `which curl` ) then | |
echo "OK: Curl exists" | |
else | |
echo "ERROR:curl doesn't exist" | |
echo "Try: pkg_add -r curl" | |
endif | |
#get cassandra version from their ftp site | |
set cassandra_version=`curl ftp://apache.cs.utah.edu/apache.org/cassandra/ | grep 1.2 | awk '{print $9}'` | |
echo "Cassandra version found on FTP: $cassandra_version" | |
#set the url based on the version | |
set cassandra_url=ftp://apache.cs.utah.edu/apache.org/cassandra/$cassandra_version/apache-cassandra-$cassandra_version-bin.tar.gz | |
echo "OK: Using URL: $cassandra_url" | |
#get the md5 hash for the file | |
set cassandra_md5=`curl http://www.apache.org/dist/cassandra/1.2.5/apache-cassandra-1.2.5-bin.tar.gz.md5 | cat` | |
echo "OK: MD5 is: $cassandra_md5" | |
#check if file already exists | |
if ( -e /tmp/apache-cassandra-$cassandra_version-bin.tar.gz ) then | |
echo "OK: File already exists.. checking MD5" | |
set md5=`md5 -q /tmp/apache-cassandra-$cassandra_version-bin.tar.gz` | |
if ( $cassandra_md5 == $md5 ) then | |
echo "OK: MD5 seems correct - skipping redownloading" | |
else | |
echo "ERROR: Incorrect MD5 - deleting temporary file" | |
rm /tmp/apache-cassandra-$cassandra_version-bin.tar.gz | |
echo "Attempting to download: $cassandra_url" | |
cd /tmp;curl -O $cassandra_url | |
endif | |
else | |
echo "File not found - Attempting to download: $cassandra_url" | |
cd /tmp;curl -O $cassandra_url | |
endif | |
#check if /opt directory exists | |
if ( -d /opt ) then | |
echo "OK: /opt directory exists" | |
else | |
echo "ERROR:/opt directory doesn't exist - creating" | |
mkdir /opt | |
endif | |
#untar the file | |
printf "\n" | |
echo "Untarring in /opt/apache-cassandra-$cassandra_version dir" | |
tar -xzf apache-cassandra-$cassandra_version-bin.tar.gz -C /opt | |
echo "Untarring complete" | |
#check if the remaining cassandra directory exists - create them if they don't | |
set dir_var= (/opt/cassandra/data /opt/cassandra/commitlog /opt/cassandra/saved_caches /var/log/cassandra) | |
foreach x ($dir_var) | |
if ( -d $x ) then | |
echo "OK: $x directory exists" | |
else | |
echo "ERROR:$x directory doesn't exist - creating" | |
mkdir -p $x | |
endif | |
end | |
#edit cassandra.yaml config file | |
echo "Editing config file: /opt/apache-cassandra-$cassandra_version/conf/cassandra.yaml" | |
cd /opt/apache-cassandra-$cassandra_version/conf/ | |
awk '{ gsub("/var/lib/","/opt/" ) ; print }' cassandra.yaml > cassandra2.yaml | |
mv cassandra.yaml cassandra.yaml.original | |
echo "Backing up cassandra.yaml to cassandra.yaml.original" | |
mv cassandra2.yaml cassandra.yaml | |
echo "Editing config file complete" | |
#check for openjdk7 and paths | |
if ( `pkg_info | grep openjdk-7 | wc -l` == 0 ) then | |
echo "ERROR: OpenJDK 7 package not found! Installing.." | |
pkg_add -r openjdk7 | |
echo "Setting Paths.." | |
setenv JAVA_HOME /usr/local/openjdk7 | |
if ( `grep openjdk7 ~/.cshrc | wc -l ==0` ) then | |
echo "ERROR: OpenJDK 7 permanent path is not set .. setting up" | |
echo 'setenv JAVA_HOME /usr/local/openjdk7' >> ~/.cshrc | |
else | |
echo "OK: OpenJDK 7 permanent path is already set" | |
endif | |
else | |
echo "OK: OpenJDK 7 package found" | |
endif | |
#things to do: | |
#1.add check for OpenJDK7 --DONE | |
#2.mkdir /var/log/cassandra/ --DONE | |
#3.edit /opt/apache-cassandra-1.2.4/conf/log4j-server.properties --not needed | |
#4.set path temporarily --DONE | |
#5.set path permanently --DONE | |
#6.put boot script in github | |
#7.download boot script automatically | |
#8.add script in cron on reboot | |
#9.backup original cassandra.yaml --done | |
#10.set cassandra paths | |
#11.look into replacing curl with fetch | |
#12.profit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment