1
0

Clean up old scripts I don't use anymore

This commit is contained in:
Noah 2015-04-27 17:56:26 -07:00
parent 9b5c738550
commit a788aa5d37
16 changed files with 2 additions and 668 deletions

View File

@ -1,59 +0,0 @@
#!/usr/bin/perl
# browser-wrap: Set this as your default browser to open certain links with
# certain browsers.
#
# To get `xdg-open` to use this, put this in your ~/.profile (update the path
# to match where you installed the script to):
#
# if [ -n "$DISPLAY" ]; then
# BROWSER=/home/kirsle/bin/browser-wrap
# fi
#
# --Kirsle
# http://sh.kirsle.net/
use 5.14.0;
use strict;
use warnings;
#------------------------------------------------------------------------------#
# Configuration Section #
#------------------------------------------------------------------------------#
# Define your browser rules here.
my $rules = {
# These are domain names to match. Use a regular expression.
qr/(facebook|fbcdn)\.(com|net)/ => "google-chrome",
};
# Default browser for links that don't have rules that match.
my $default = "firefox";
#------------------------------------------------------------------------------#
# End Configuration Section #
#------------------------------------------------------------------------------#
# Get the URL passed in.
my $url = shift(@ARGV);
my $browser = $default;
# Looks okay?
if ($url =~ /^https?:\/\/([^\/]+)\/?/i) {
print "Domain: $1\n";
my $domain = $1;
# Look for the best rule.
my @sorted = sort { length($b) <=> length($a) } keys %{$rules};
foreach my $rule (@sorted) {
if ($domain =~ /$rule/i) {
# Matched!
$browser = $rules->{$rule};
last;
}
}
}
# Launch the browser.
my ($app, @args) = split(/\s+/, $browser);
exec($app, @args, $url, @ARGV);

View File

@ -1,55 +0,0 @@
#!/usr/bin/perl -w
# chmodfix - automagically fix file permissions, recursively, to their sane
# default values:
#
# CGI scripts = 0755
# directories = 0755
# normal files = 0644
#
# usage: chmodfix <start-directory>
#
# --Kirsle
# http://sh.kirsle.net/
if (scalar(@ARGV)) {
foreach my $dir (@ARGV) {
if (-d $dir) {
print "#####################\n";
print "Fix: $dir\n";
print "#####################\n";
&scanDir($dir);
}
}
}
else {
print "Usage: chmodfix <directories>\n";
exit(0);
}
sub scanDir {
my $dir = shift;
opendir (DIR, $dir);
foreach my $file (readdir(DIR)) {
next if $file eq ".";
next if $file eq "..";
if (-d "$dir/$file") {
print "chmod directory: 0755 ($dir/$file)\n";
chmod (0755, "$dir/$file");
&scanDir ("$dir/$file");
}
else {
if ($file =~ /\.(cgi|pl)$/i) {
print "chmod CGI file: 0755 ($dir/$file)\n";
chmod (0755, "$dir/$file");
}
else {
print "chmod file: 0644 ($dir/$file)\n";
chmod (0644, "$dir/$file");
}
}
}
closedir (DIR);
}

View File

@ -1,49 +0,0 @@
#!/usr/bin/perl -w
# chmodweb - Like chmodfix except regular files are chmodded 0666 instead of
# 0644. See chmodfix.
#
# --Kirsle
# http://sh.kirsle.net/
if (scalar(@ARGV)) {
foreach my $dir (@ARGV) {
if (-d $dir) {
print "#####################\n";
print "Fix: $dir\n";
print "#####################\n";
&scanDir($dir);
}
}
}
else {
print "Usage: chmodfix <directories>\n";
exit(0);
}
sub scanDir {
my $dir = shift;
opendir (DIR, $dir);
foreach my $file (readdir(DIR)) {
next if $file eq ".";
next if $file eq "..";
if (-d "$dir/$file") {
print "chmod directory: 0755 ($dir/$file)\n";
chmod (0755, "$dir/$file");
&scanDir ("$dir/$file");
}
else {
if ($file =~ /\.(cgi|pl|php)$/i) {
print "chmod CGI file: 0755 ($dir/$file)\n";
chmod (0755, "$dir/$file");
}
else {
print "chmod file: 0666 ($dir/$file)\n";
chmod (0666, "$dir/$file");
}
}
}
closedir (DIR);
}

View File

@ -1,33 +0,0 @@
#!/usr/bin/perl -w
# dodos2unix - A stupid-simple recursive dos2unix front end.
#
# This script starts recursively scanning the current working directory (.) and
# runs dos2unix on every text file (extensions PL, PHP, CGI, HTM, HTML, TXT,
# INC, and PM).
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
&scanDir (".");
sub scanDir {
my $dir = shift;
opendir (DIR, $dir);
foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {
if (-d "$dir/$file") {
&scanDir ("$dir/$file");
}
else {
if ($file =~ /\.(pl|php|cgi|htm|html|txt|inc|pm|cml)$/i) {
print "dos2unix $dir/$file\n";
`dos2unix $dir/$file`;
}
}
}
closedir (DIR);
}

View File

@ -1,33 +0,0 @@
#!/usr/bin/perl -w
# dodos2unix - A stupid-simple recursive dos2unix front end.
#
# This script starts recursively scanning the current working directory (.) and
# runs dos2unix on every text file (extensions PL, PHP, CGI, HTM, HTML, TXT,
# INC, and PM).
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
&scanDir (".");
sub scanDir {
my $dir = shift;
opendir (DIR, $dir);
foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {
if (-d "$dir/$file") {
&scanDir ("$dir/$file");
}
else {
if ($file =~ /\.(pl|php|cgi|htm|html|txt|inc|pm|cml)$/i) {
print "dos2unix $dir/$file\n";
`perl -pi -e 's/\\r\\n/\\n/;' $dir/$file`;
}
}
}
closedir (DIR);
}

View File

@ -1,29 +0,0 @@
#!/usr/bin/perl -w
# dounix2dos - Like dodos2unix except it runs unix2dos instead. See dodos2unix
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
&scanDir (".");
sub scanDir {
my $dir = shift;
opendir (DIR, $dir);
foreach my $file (sort(grep(!/^\./, readdir(DIR)))) {
if (-d "$dir/$file") {
&scanDir ("$dir/$file");
}
else {
if ($file =~ /\.(pl|php|cgi|htm|html|txt|inc|pm)$/i) {
print "unix2dos $dir/$file\n";
`unix2dos $dir/$file`;
}
}
}
closedir (DIR);
}

View File

@ -1,146 +0,0 @@
#!/usr/bin/perl
# ffnightly - Download the latest version of Firefox Nightly.
#
# Run this script to fetch the latest version of Firefox Nightly. By default,
# it will be installed into /opt/firefox-nightly with a symlink to run it at
# /usr/bin/firefox-nightly. Furthermore, it will show up in your applications
# menu as "Firefox Nightly".
#
# This script needs to be run as root (if you don't, it will attempt to sudo
# run itself). To run it from a cron job, use the --force option and it will
# skip prompting you to make sure Firefox is not running first.
#
# Usage: ffnightly [--force]
#
# --Kirsle
# http://sh.kirsle.net
use 5.14.0;
use strict;
use warnings;
use English;
use File::Basename;
use Time::Local;
chomp(my $ARCH = `uname -p`);
################################################################################
# Configuration #
################################################################################
# Where to install Firefox Nightly to.
my $INSTALL = "/opt/firefox-nightly";
# Where to install the launcher symlink to.
my $BIN = "/usr/bin/firefox-nightly";
# Where to install the launcher shortcut to.
my $LAUNCHER = "/usr/share/applications/firefox-nightly.desktop";
# Where are the Firefox nightlies kept?
my $NIGHTLY = sprintf("ftp://ftp.mozilla.org/pub/firefox/nightly/latest-trunk/firefox-14.0a1.en-US.linux-%s.tar.bz2", $ARCH);
################################################################################
# End Configuration #
################################################################################
# Base name of tarball.
my $TARBALL = basename($NIGHTLY);
# Mozilla plugins lib.
my $PLUGINS = "/usr/lib" . ($ARCH eq 'x86_64' ? '64' : '') . "/mozilla/plugins";
# Check for required tools.
my %t = check_required();
unless (@ARGV && $ARGV[0] eq '--force') {
say "Make sure you close Firefox before continuing.";
print "Is Firefox closed now? [yN] ";
chomp(my $ans = <STDIN>);
exit(0) unless $ans =~ /^y/;
}
# Needs to be root.
if ($EFFECTIVE_USER_ID != 0) {
say "You need to run this script as root.";
exec($t{sudo}, $0, '--force');
exit(1);
}
# Make a temp folder for it.
my $tmp = "/tmp/firefox-nightly-$$-" . time();
run("mkdir -p $tmp");
# Fetch Firefox Nightly.
chdir($tmp);
run("wget $NIGHTLY");
run("tar -xjvf $TARBALL");
# Move it to the destination.
run("rm -rf $INSTALL") if -d $INSTALL;
if (!-d $INSTALL) {
run("mkdir -p $INSTALL");
}
run("mv firefox/* $INSTALL/");
# Make the symlink.
if (-e $BIN) {
run("rm -f $BIN");
}
# Make the launcher.
open (my $launch, ">", $LAUNCHER);
print {$launch} <<"EOF";
[Desktop Entry]
Version=1.0
Name=Firefox Nightly
GenericName=Web Browser
Comment=Browse the Web
Exec=firefox-nightly %u
Icon=$INSTALL/icons/mozicon128.png
Terminal=false
Type=Application
StartupWMClass=Firefox-bin
MimeType=text/html;text/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;text/mml;x-scheme-handler/http;x-scheme-handler/https;
StartupNotify=true
Categories=Network;WebBrowser;
EOF
close ($launch);
# Link the binary.
run("ln -s $INSTALL/firefox $BIN");
# Flash plugins etc!
if (-d "$INSTALL/plugins") {
run("rm -rf $INSTALL/plugins");
}
run("ln -s $PLUGINS $INSTALL/plugins");
# Cleanup.
run("rm -rf $tmp");
say "You have updated to the latest Firefox Nightly. The binary is installed";
say "to: $BIN";
exit(0);
sub run {
my $cmd = shift;
say "\$ $cmd";
system($cmd);
}
sub check_required {
my @tools = qw(sudo wget tar);
my %paths = ();
foreach my $tool (@tools) {
chomp(my $path = `which $tool`);
if ($? == 0) {
$paths{$tool} = $path;
}
else {
say "This script requires `$tool`, which wasn't found in your \$PATH.";
exit(1);
}
}
return %paths;
}

View File

@ -1,71 +0,0 @@
#!/usr/bin/perl -w
# findtxt - Recursively scan a directory looking for a string inside every file
# inside. It's like a simple grep except it scans directories and all files.
#
# Usage: findtxt <strings to find> [directory]
use strict;
use warnings;
if (not scalar(@ARGV)) {
print "Usage: findtxt <strings to find> [directory]\n"
. "Example: findtxt \"hello world\" /home\n"
. " findtxt perl cgi /usr/lib\n";
exit(0);
}
my $base = `pwd`;
if (-d $ARGV[-1]) {
$base = pop(@ARGV);
}
$base = '' if $base eq '/';
print "Scanning... please wait...\n";
our $hits = 0;
my @files = &scanDir($base);
print "\n\nResults:\n"
. join ("\n",@files)
. "\n";
sub scanDir {
my $dir = shift;
my @files = ();
print "[$hits] Scan $dir/\n";
opendir (DIR, "$dir/") || warn "Can't read $dir: $!\n";
foreach my $file (readdir(DIR)) {
next if $file eq '.';
next if $file eq '..';
next if -l "$dir/$file"; # skip symlinks
if (-d "$dir/$file") {
next if ("$dir/$file") =~ /\/dev/i;
push (@files, &scanDir("$dir/$file"));
}
elsif (-f "$dir/$file") {
# read this file.
open (FILE, "$dir/$file") || do {
warn "Can't read $dir/$file: $!\n";
next;
};
while (<FILE>) {
foreach my $str (@ARGV) {
if ($_ =~ /$str/i) {
push (@files,"$dir/$file");
$hits++;
last;
}
}
}
}
select (undef,undef,undef,0.001);
}
closedir (DIR);
return @files;
}

View File

@ -1,35 +0,0 @@
#!/usr/bin/perl -w
# iphone-ringtone: convert MP3 tracks into M4R audio files for
# iPhone ringtones.
#
# Requires: mplayer, faac
#
# --Kirsle
# http://sh.kirsle.net/
# Get args.
scalar(@ARGV) or die "Usage: iphone-ringtone <track.mp3>";
my $mp3 = shift(@ARGV);
# Turn the mp3 name into an m4r name.
my $m4r = $mp3;
$m4r =~ s/\.mp3$/.m4r/i;
$m4r .= ".m4r" unless $m4r =~ /\.m4r$/i;
# Turn the m4r name into an m4a name (this is the name that
# faac will produce when run).
my $m4a = $m4r;
$m4a =~ s/\.m4r$/.m4a/i;
# Turn the m4r name into a .wav for mplayer.
my $wav = $m4r;
$wav =~ s/\.m4r$/.wav/i;
# Run the commands.
system("mplayer -vo null -vc null -ao pcm:fast:file=$wav $mp3");
system("faac -b 128 -c 44100 -w $wav");
rename($m4a,$m4r);
unlink($wav);
print "Done. Now scp the file to /Library/Ringtones/ on your iPhone.\n";

View File

@ -15,7 +15,7 @@ use Tk;
my $str = join (" ",@ARGV) || 'Preview'; my $str = join (" ",@ARGV) || 'Preview';
my $mw = MainWindow->new ( my $mw = MainWindow->new (
-title => "Cuvou.com", -title => "Title",
); );
$mw->optionAdd ('*highlightThickness',0); $mw->optionAdd ('*highlightThickness',0);
@ -28,6 +28,6 @@ $mw->Label (
-size => 12, -size => 12,
-family => 'Arial', -family => 'Arial',
], ],
)->pack (-padx => 5, -pady => 5); )->pack (-padx => 15, -pady => 15);
MainLoop; MainLoop;

View File

@ -1,23 +0,0 @@
#!/bin/bash
# Mount an encrypted loopback disk image.
# Setting this up:
# modprobe cryptoloop
# modprobe aes
# dd if=/dev/urandom of=.container.img bs=1M count=8192 # for an 8GB image
# losetup -e aes /dev/loop0 .container.img
# mkfs.ext4 /dev/loop0
# Then run this script to mount the image to /secure (create this folder in
# advance, or use a different folder). `umount /secure` to unmount.
# --Kirsle
# http://sh.kirsle.net/
sudo modprobe cryptoloop
sudo modprobe aes
sudo losetup /dev/loop0 ~/.container.img
echo "cryptsetup"
sudo cryptsetup -y luksOpen /dev/loop0 ~/.container.img
sudo mount -o loop,encryption=aes ~/.container.img /secure

View File

@ -1,27 +0,0 @@
#!/usr/bin/perl
# multistart - Spawn off multiple processes. Useful for a single click
# "autostart" for all your commonly used programs (IM, e-mail, etc).
#
# Usage: multistart <list of processes>
# Example: multistart thunderbird firefox "synergy -c syn.conf"
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
scalar(@ARGV) or usage();
foreach my $proc (@ARGV) {
my $fork = fork();
if ($fork == 0) {
exec($proc);
}
}
sub usage {
print "multistart - Spawn off multiple processes.\n"
. "Usage: multistart <list of processes>\n";
exit(1);
}

View File

@ -1,24 +0,0 @@
#!/usr/bin/perl -w
# openrand - Opens a random file in the current working directory.
#
# Requires GNOME desktop environment with `gnome-open` command.
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
my @files = ();
opendir (DIR, ".");
foreach my $file (readdir(DIR)) {
next unless -f $file;
next unless -r $file;
push (@files,$file);
}
closedir (DIR);
my $rnd = $files [ int(rand(scalar(@files))) ];
print "Exec gnome-open $rnd\n";
system ("gnome-open \"$rnd\" &");

View File

@ -1,56 +0,0 @@
#!/usr/bin/perl -w
# scale: Front-end to changing the AppleDisplayScaleFactor, for Hackintosh
# on netbooks where the screen resolution isn't tall enough for some windows.
#
# Set the scale factor for the session:
# scale 0.8
# !!! Remember to set it back to 1.0 when you're done !!!
#
# Set the scale just to launch a specific app, then set it back:
# scale 0.8 "Photo Booth"
# scale 0.8 /Applications/Photo\ Booth.app
#
# --Kirsle
# http://sh.kirsle.net/
unless (@ARGV) {
print "usage: scale <aspect-ratio> [app]\n"
. "ex: scale 0.8\n"
. " scale 0.8 /Applications/Photo\\ Booth.app\n"
. " scale 0.8 'Photo Booth'\n";
exit(1);
}
my $scale = shift(@ARGV);
if ($scale =~ /[^0-9\.]/) {
die "Scale factor must be a number!";
}
my $app = undef;
if (scalar(@ARGV)) {
$app = shift(@ARGV);
if (!-e $app) {
# Try a full path (e.g. Photo Booth -> /Applications/Photo Booth.app)
$app = "/Applications/$app.app";
if (!-e $app) {
die "Can't find $app: no such file.";
}
}
}
# set the scale
system("defaults write -g AppleDisplayScaleFactor $scale");
# launching an app too?
if (defined $app) {
system("open \"$app\"");
system("defaults write -g AppleDisplayScaleFactor 1.0");
print "$app launched with scale ratio of $scale\n";
exit(0);
}
else {
if (int($scale) != 1) {
print "Scale set to $scale for the session. Be sure to "
. "reset it to 1.0 when you're done!\n";
exit(0);
}
}

View File

@ -1,17 +0,0 @@
#!/usr/bin/perl -w
# suterm - A stupid simple way to get a root shell in GNOME. It requires you to
# have /etc/sudoers set up for your username with the NOPASSWD option.
#
# Create a launcher that runs this script and check "Open in Terminal". Then
# the launcher will open a root gnome-terminal, provided `sudo -i` normally
# doesn't require you to enter a password.
#
# --Kirsle
# http://sh.kirsle.net/
use strict;
use warnings;
system ("sudo -i");
exit(0);

View File

@ -1,9 +0,0 @@
#!/usr/bin/perl -w
# v4lskype - A simple front-end for Skype for Linux that loads the Video 4 Linux
# driver before launching Skype.
#
# If your Skype has problems with video, change the launcher to launch this
# script instead.
exec("LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype");