Created
April 14, 2013 19:36
-
-
Save esoupy/5383901 to your computer and use it in GitHub Desktop.
Create MongoDB links in /usr/local/bin
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
#!/bin/bash | |
MongoInstPath=/usr/local/mongodb | |
localbin=/usr/local/bin | |
USAGE="$(basename $0) [ remove | help ]" | |
HELP=" remove : uninstall the MongoDB symlinks in $localbin \n | |
help : this message" | |
MongoFiles="bsondump | |
mongo | |
mongod | |
mongodump | |
mongoexport | |
mongofiles | |
mongoimport | |
mongooplog | |
mongoperf | |
mongorestore | |
mongos | |
mongosniff | |
mongostat | |
mongotop" | |
function verify_localbin() { | |
# verify files dont exist in $localbin | |
echo -n "Verifying Mongo bin files in $localbin:" | |
for f in $MongoFiles; do | |
[ -e $localbin/$f ] && Failed=true | |
if [ $Failed ]; then | |
echo "[failed]" | |
echo "$f already exists in $localbin" | |
exit 1 | |
else | |
echo -n "." | |
fi | |
done | |
echo "[OK]" | |
} | |
function verify_mongofiles() { | |
# verify files exist in $MongoInstPath | |
echo -n "Verifying Mongo bin files in $MongoInstPath/bin:" | |
for f in $MongoFiles; do | |
[ -f $MongoInstPath/bin/$f ] || Failed=true | |
if [ $Failed ]; then | |
echo "[failed]" | |
echo "Did not locate $MongoInstPath/bin/$f" | |
exit 1 | |
else | |
echo -n "." | |
fi | |
done | |
echo "[OK]" | |
} | |
function remove_mongodblinks() { | |
# remove symlinks in $localbin | |
for f in $MongoFiles; do | |
echo -n "removing mongodb symlink $localbin/$f .. " | |
[ -L $localbin/$f ] && \rm -f $localbin/$f && echo "[OK]" || echo "[skipped]" | |
done | |
echo "Done." | |
} | |
function create_links() { | |
# create links | |
for f in $MongoFiles; do | |
echo -n "creating link: $f in $localbin .. " | |
ln -s $MongoInstPath/bin/$f $localbin || Failed=true | |
if [ $Failed ]; then | |
echo "[failed]" | |
exit 1 | |
else | |
echo "[OK]" | |
fi | |
done | |
echo "Success." | |
} | |
## Main ## | |
if [ $1 ]; then | |
case $1 in | |
h|-h|help|--help|-?) echo $USAGE | |
echo -e $HELP | |
;; | |
remove) remove_mongodblinks | |
;; | |
*) echo "unknown option $1" | |
echo $USAGE | |
;; | |
esac | |
else | |
verify_localbin | |
verify_mongofiles | |
create_links | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment