Permalink
Browse files

Merge branch 'master' of github.com:staticsafe/useful-scripts

  • Loading branch information...
2 parents 0a3ab70 + d7510c9 commit 3d38bc87d0bfedffdcf44a32a067b67df01ad9f8 @staticsafe committed May 12, 2012
Showing with 380 additions and 352 deletions.
  1. +1 −5 README → LICENSE
  2. +18 −0 README.md
  3. +13 −13 VideoThumbnailerInstaller
  4. +3 −3 antichinarulesgen.sh
  5. +7 −2 block_china.pl
  6. +1 −1 flushmemcache
  7. +1 −1 mkcvr
  8. +1 −1 mkscr
  9. +1 −1 { → obsolete}/olddevenvsetup
  10. +1 −1 { → obsolete}/oldwebservsetup
  11. +75 −67 webservermove.py
  12. +258 −257 webserversetup.py
View
@@ -1,7 +1,3 @@
-This git repo basically contains scripts that I may write for doing various tasks.
-
-None of these scripts have explicit licenses so I'll do a blanket license in this README. This applies to existing scripts and any other scripts that may be added to this git repo.
-
Copyright (c) <2011-~>, <staticsafe>
All rights reserved.
@@ -11,4 +7,4 @@ Redistributions of source code must retain the above copyright notice, this list
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
@@ -0,0 +1,18 @@
+useful scripts
+====================
+
+### VideoThumbnailerInstaller
+
+A bash script that installs [mtn](http://moviethumbnail.sourceforge.net/) with a little helper script (mkscr) that makes things easier.
+
+### antichinarulesgen
+Creates a file called access.list with a set of iptables rules for blocking Chinese subnets.
+
+### block_china
+Reads access.list created by antichinarulesgen and implements rules
+
+### flushmemcache
+A script to flush memcache, designed to be used as a cron job.
+
+### webserversetup
+Installs LAMP/LEMP packages for various distros.
View
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# written by staticsafe, ze, jayms, chris and ckpro
# fixed various nasty things (thanks neurolysis)
@@ -15,35 +15,35 @@ if [[ ! -d ~/bin ]]; then
mkdir ~/bin || die 'Failed to create ~/bin.'
fi
-
-if [[ "$SHELL" == "/usr/bin/zsh" || "$SHELL" == "/bin/zsh" ]]
- printf '%s\n' 'export PATH=$HOME/bin:$PATH' >> ~/.zshenv
-elif [[ "$SHELL" == "/bin/bash" ]]
- printf '%s\n' 'PATH="$HOME/bin:$PATH"' >> ~/.bashrc
-else
- printf '%s\n' 'The script does not support your default shell. Please add $HOME/bin to your path manually'
-fi
-
-
case "${arch}" in
i686|i586) wget -O ~/bin/mtn http://dl.dropbox.com/u/34659045/mtn-32 || die 'Failed to download mtn.' ;;
x86_64) wget -O ~/bin/mtn http://dl.dropbox.com/u/34659045/mtn-64 || die 'Failed to download mtn.' ;;
*) die "Unknown arch '${arch}', aborting." ;;
esac
-chmod a+x ~/bin/mtn
# Get font
wget -O ~/bin/Terminus.ttf http://files.ax86.net/terminus-ttf/4.36/TerminusMedium-4.36.ttf
# Create mkscr bash script
cat > ~/bin/mkscr << 'EOF'
-#!/bin/bash
+#!/usr/bin/env bash
for arg; do
mtn -f ~/bin/Terminus.ttf -c 4 -r 8 -w 1280 -b 0.6 -D6 -T "Screens for hey.fux0r.eu" "${arg}"
done
EOF
+chmod a+x ~/bin/mtn
chmod a+x ~/bin/mkscr
+if [[ "$SHELL" == "/usr/bin/zsh" || "$SHELL" == "/bin/zsh" ]]; then
+ printf '%s\n' 'export PATH=$HOME/bin:$PATH' >> ~/.zshenv
+ exec zsh
+elif [[ "$SHELL" == "/bin/bash" ]]; then
+ printf '%s\n' 'PATH="$HOME/bin:$PATH"' >> ~/.bashrc
+ exec bash
+else
+ printf '%s\n' 'The script does not support your default shell. Please add $HOME/bin to your path manually'
+fi
+
printf '%s\n' 'Done. Happy screenshotting!'
View
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Name : antichinarulesgen.sh
-# Purpose : Generates a nice little anti-China rules list that can be used with iptables-restore or cafejunkie's block_china.pl
+# Purpose : Generates a nice little anti-China rules list that can be used with cafejunkie's block_china.pl
# a die function as always
die() {
@@ -19,7 +19,7 @@ else
fi
# sed operations
-cat chinacidr.txt | sed -e '1,4d' | sed -e 's/China//' | sed -e 's/^/INPUT -s /' | sed -e 's/^\(.*\) .*/\1/' | sed -e 's/$/-p tcp -j DROP/' > access.list
+cat chinacidr.txt | sed -e '1,4d;s/China//;s/^/INPUT -s /;s/^\(.*\) .*/\1/;s/$/-p tcp -j DROP/' > access.list
# add some rules for psad, you may omit this if you don't need it
printf '%s\n' 'INPUT -j LOG' >> access.list
View
@@ -1,10 +1,15 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
# Originally written by cafejunkie, modified by staticsafe
my @RULES = ( );
-open( LIST, "< ./access.list" );
+if ( -e "./access.list" ) {
+ open( LIST, "< ./access.list" );
+}
+else {
+ die "access.list does not exist, terminating.\n"
+}
while( <LIST> ){
next if $_ =~ /^\#/ || $_ =~ /^$/;
View
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
#Small script to flush Memcached
View
2 mkcvr
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Creates a image from a single frame of a video file
if [ $# != 1 ]; then
View
2 mkscr
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
while [ $# -gt 0 ]; do
mtn -f ~/Terminus.ttf -c 4 -r 8 -w 1280 -b 0.6 -D6 -T "Screens for site" "$1"
shift
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
#Sets up a fully working development environment for Caffeine Linux developers on Debian based systems
#WARNING : THIS SCRIPT IS NOW OBSOLETE! Please refer to the caffeine-linux git repo for the current version!
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
#Sets up webserver on a Debian based server
View
@@ -1,91 +1,99 @@
#!/usr/bin/env python
-# This script helps in the moving process of two remote (script run from srcserver) web servers (files, databases)
-# I realize this script could be written in a better way but Fabric is annoying and cba coding using it.
-
-import ConfigParser, os, requests
+# This script helps in the moving process of two remote
+# (script run from srcserver) web servers (files, databases)
+# I realize this script could be written in a better way,
+# but Fabric is annoying and cba coding using it.
+
+import ConfigParser
+import os
+import requests
from subprocess import call
# global vars
currentdir = os.getcwd()
configfile = os.path.join(currentdir, "webservermove.ini")
-def getdefaultconfig():
- # Downloads a example config
- r = requests.get("https://raw.github.com/staticsafe/useful-scripts/master/webservermove.ini")
-
- file_name = "webservermove.ini"
- f = open(file_name, wb)
- f.write(r.content)
- f.close()
+def getdefaultconfig():
+ # Downloads a example config
+ r = requests.get("http://goo.gl/S4kQN")
+ file_name = "webservermove.ini"
+ f = open(file_name, wb)
+ f.write(r.content)
+ f.close()
+ print "Config file downloaded!"
+ main()
- print "Config file downloaded!"
- main()
def setvalues():
- # global vars...again
- global srcusername
- global srcpassword
- global srchostname
- global srcfiledir
- global srcdbname
- global srcmysqlrootpw
-
- global destusername
- global destpassword
- global desthostname
- global destfiledir
- global destdbdir
-
- # Get values from config file
- srcconfig = ConfigParser.ConfigParser()
- srcconfig.read('webservermove.ini')
-
- srcusername = srcconfig.get('SOURCEHOST', 'srcusername')
- #srcpassword = srcconfig.get('SOURCEHOST', 'srcpassword')
- #srchostname = srcconfig.get('SOURCEHOST', 'srchostname')
- srcfiledir = srcconfig.get('SOURCEHOST', 'srcfiledir')
- srcdbname = srcconfig.get('SOURCEHOST', 'srcdbname')
- srcmysqlrootpw = srcconfig.get('SOURCEHOST', 'srcmysqlrootpw')
-
- destconfig = ConfigParser.ConfigParser()
- destconfig.read('webservermove.ini')
-
- destusername = destconfig.get('DESTHOST', 'destusername')
- destpassword = destconfig.get('DESTHOST', 'destpassword')
- desthostname = destconfig.get('DESTHOST', 'desthostname')
- destfiledir = destconfig.get('DESTHOST', 'destfiledir')
- destdbdir = destconfig.get('DESTHOST', 'destdbdir')
+ # global vars...again
+ global srcusername
+ global srcpassword
+ global srchostname
+ global srcfiledir
+ global srcdbname
+ global srcmysqlrootpw
+ global destusername
+ global destpassword
+ global desthostname
+ global destfiledir
+ global destdbdir
+
+ # Get values from config file
+ srcconfig = ConfigParser.ConfigParser()
+ srcconfig.read('webservermove.ini')
+ srcusername = srcconfig.get('SOURCEHOST', 'srcusername')
+ #srcpassword = srcconfig.get('SOURCEHOST', 'srcpassword')
+ #srchostname = srcconfig.get('SOURCEHOST', 'srchostname')
+ srcfiledir = srcconfig.get('SOURCEHOST', 'srcfiledir')
+ srcdbname = srcconfig.get('SOURCEHOST', 'srcdbname')
+ srcmysqlrootpw = srcconfig.get('SOURCEHOST', 'srcmysqlrootpw')
+
+ destconfig = ConfigParser.ConfigParser()
+ destconfig.read('webservermove.ini')
+
+ destusername = destconfig.get('DESTHOST', 'destusername')
+ destpassword = destconfig.get('DESTHOST', 'destpassword')
+ desthostname = destconfig.get('DESTHOST', 'desthostname')
+ destfiledir = destconfig.get('DESTHOST', 'destfiledir')
+ destdbdir = destconfig.get('DESTHOST', 'destdbdir')
def filemove():
- print "Mirroring your files now!"
- scpcall = call("scp -r " + srcfiledir + " " + destusername + "@" + desthostname + ":" + destfiledir, shell=True)
+ print "Mirroring your files now!"
+ scpcall = call("scp -r " + srcfiledir + " "
+ + destusername + "@" + desthostname + ":" + destfiledir, shell=True)
+
def dbmove():
- print "Dumping database now!"
- dbdump = call ("mysqldump --opt -Q -uroot -p" + srcmysqlrootpw + " " + srcdbname + " " + ">" + " " + currentdir, + srcdbname + ".sql", shell=True)
- scpcall = call ("scp " + currentdir + srcdbname + ".sql" + " " + destusername + "@" + desthostname + ":" + destdbdir, shell=True)
+ print "Dumping database now!"
+ dbdump = call("mysqldump --opt -Q -uroot -p" + srcmysqlrootpw
+ + " " + srcdbname + " " + ">" + " "
+ + currentdir, + srcdbname + ".sql", shell=True)
+ scpcall = call("scp " + currentdir + srcdbname + ".sql" + " "
+ + destusername + "@" + desthostname + ":" + destdbdir, shell=True)
+
def checks():
- if os.path.isdir(srcfiledir) == False:
- print "Your source file dir does not exist! Exiting."
- raise SystemExit
- else:
- filemove()
+ if os.path.isdir(srcfiledir) == False:
+ print "Your source file dir does not exist! Exiting."
+ raise SystemExit
+ else:
+ filemove()
+
def main():
- # check existence of config file
- if os.path.isfile(configfile) == False:
- print "A config file does not exist, downloading a example config now!"
- getdefaultconfig()
- else:
- print "Config file exists, using it!"
+ # check existence of config file
+ if os.path.isfile(configfile) == False:
+ print "A config file does not exist, downloading a example config now!"
+ getdefaultconfig()
+ else:
+ print "Config file exists, using it!"
- setvalues()
- filemove()
- dbmove()
+ setvalues()
+ filemove()
+ dbmove()
if __name__ == "__main__":
- main()
+ main()
Oops, something went wrong.

0 comments on commit 3d38bc8

Please sign in to comment.