├── .gitignore ├── README.md ├── addprinters.ps1 ├── addprinters.sh ├── delprinters.ps1 ├── delprinters.sh ├── hackcu-printing.txt ├── hp-laserjet-9050-Darwin.ppd ├── hp-laserjet-9050-Linux.ppd ├── printers.conf └── scraper.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ninja-Unix 2 | 3 | Add printers from Columbia's ninja print system to any UNIX/Linux system. 4 | 5 | ## Directions 6 | 7 | First install CUPS, the Common Unix Printing System. On Mac OS X, Ubuntu, and 8 | other "User-Friendly" Unices, this should be installed by default. This package 9 | is generally named "cups" in most distribution package repositories. If you 10 | install CUPS manually, make sure the cups daemon is started and running. 11 | 12 | To add all the printers, run the command 13 | 14 | sudo ./addprinters.sh 15 | 16 | This will most likely take a long time. If you want to add a specific printer 17 | supply an argument to the program. For instance 18 | 19 | sudo ./addprinters.sh butler 20 | 21 | will add only the printers in butler library, whereas 22 | 23 | sudo ./addprinters.sh butler301a 24 | 25 | will add a specific printer in butler. 26 | 27 | There is also a delprinters.sh script which is used in the same way, but 28 | deletes printers instead of adding them. 29 | 30 | ## Mac Executables 31 | 32 | [Add and delete printer apps located here.](https://www.dropbox.com/s/t2s0thy1yvryvaq/ColumbiaPrinters.zip) 33 | 34 | ## Missing Printers 35 | 36 | If you think any printers are missing, run the scraper script to add all available ninja printers 37 | 38 | python scraper.py 39 | 40 | This will update the printers.conf file that the add printers script uses. 41 | -------------------------------------------------------------------------------- /addprinters.ps1: -------------------------------------------------------------------------------- 1 | function addninja 2 | { 3 | $name = $args[0] 4 | $port = $args[1] 5 | $location = $args[2] 6 | Write-Host ('adding {0}' -f $name) 7 | 8 | Remove-PrinterPort -Name $name *> null 9 | Add-PrinterPort -Name $name -LprHostAddress $port -LprQueueName public -LprByteCounting 10 | Remove-Printer -Name $name *> null 11 | Add-Printer -Name $name -DriverName 'HP LaserJet 9050 PS Class Driver' -PortName $name 12 | } 13 | 14 | Add-PrinterDriver -Name 'HP LaserJet 9050 PS Class Driver' 15 | 16 | $content = Get-Content printers.conf 17 | $search = $args[0] 18 | 19 | if ($search -eq $null) { 20 | $search = '' 21 | } 22 | 23 | foreach ($line in $content) { 24 | $arr = $line -split '\s+', 3 25 | $printername = $arr[0] 26 | $printerport = $arr[1] 27 | $printerloc = $arr[2] 28 | 29 | if ($printername.ToLower().StartsWith($search.ToLower())) { 30 | addninja $printername $printerport $printerloc 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /addprinters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function check_exists { 4 | which $1 &> /dev/null 5 | } 6 | 7 | function download { 8 | URL=$1 9 | FILE=`basename $1` 10 | 11 | if check_exists wget; then 12 | wget "$URL" 13 | elif check_exists curl; then 14 | curl "$URL" -o "$FILE" 15 | else 16 | echo "Please install either wget or curl" 17 | fi 18 | } 19 | 20 | if [ ! -f printers.conf ]; then 21 | URL=https://raw.github.com/adicu/ninja-unix/master/printers.conf 22 | echo "No printers.conf. Attempting to download." 23 | download $URL 24 | fi 25 | 26 | PPD="hp-laserjet-9050-$(uname).ppd" 27 | 28 | if [ ! -f $PPD ]; then 29 | URL=https://raw.github.com/adicu/ninja-unix/master/$PPD 30 | echo "No ppd file. Attempting to download." 31 | download $URL 32 | fi 33 | 34 | LPADMIN=`which lpadmin` 35 | 36 | if [ -z $LPADMIN ]; then 37 | echo "Could not find the lpadmin program." 38 | echo "Either you have not installed CUPS, or lpadmin is not on your PATH" 39 | exit 40 | fi 41 | 42 | add_ninja(){ 43 | $LPADMIN -p $1 -E -v lpd://$2/public -P $PPD -L $3 44 | } 45 | 46 | read_config(){ 47 | while read name address location 48 | do 49 | echo "Adding $name" 50 | add_ninja $name $uni@$address $location 51 | done 52 | } 53 | 54 | echo "What is your UNI?" 55 | read uni 56 | 57 | if [ -z $1 ]; then 58 | read_config < printers.conf 59 | else 60 | exists=`grep $1 printers.conf | head -n 1` 61 | if [ -z "$exists" ]; then 62 | echo "Could not find printer matching this pattern" 63 | exit 64 | fi 65 | grep $1 printers.conf | read_config 66 | fi 67 | -------------------------------------------------------------------------------- /delprinters.ps1: -------------------------------------------------------------------------------- 1 | function delninja 2 | { 3 | $name = $args[0] 4 | $port = $args[1] 5 | $location = $args[2] 6 | Write-Host ('removing {0}' -f $name) 7 | 8 | Remove-PrinterPort -Name $name *> $null 9 | Remove-Printer -Name $name *> $null 10 | } 11 | 12 | Add-PrinterDriver -Name 'HP LaserJet 9050 PS Class Driver' 13 | 14 | $content = Get-Content printers.conf 15 | $search = $args[0] 16 | 17 | if ($search -eq $null) { 18 | $search = '' 19 | } 20 | 21 | foreach ($line in $content) { 22 | $arr = $line -split '\s+', 3 23 | $printername = $arr[0] 24 | $printerport = $arr[1] 25 | $printerloc = $arr[2] 26 | 27 | if ($printername.ToLower().StartsWith($search.ToLower())) { 28 | delninja $printername $printerport $printerloc 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /delprinters.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function download { 4 | URL=$1 5 | FILE=`basename $1` 6 | if [ -z `which wget` ]; then 7 | if [ -z `which curl` ]; then 8 | echo "Please install either wget or curl" 9 | else 10 | curl $URL > $FILE 11 | fi 12 | else 13 | wget $URL 14 | fi 15 | } 16 | 17 | LPADMIN=`which lpadmin` 18 | 19 | if [ -z $LPADMIN ]; then 20 | echo "Could not find the lpadmin program." 21 | echo "Either you have not installed CUPS, or lpadmin is not on your PATH" 22 | fi 23 | 24 | if [ ! -f printers.conf ]; then 25 | URL=https://raw.github.com/adicu/ninja-unix/master/printers.conf 26 | echo "No printers.conf. Attempting to download." 27 | download $URL 28 | fi 29 | 30 | read_config(){ 31 | while read name address location 32 | do 33 | echo "Deleting $name" 34 | lpadmin -x $name 35 | done 36 | } 37 | 38 | if [ -z $1 ]; then 39 | read_config < printers.conf 40 | else 41 | exists=`grep $1 printers.conf | head -n 1` 42 | if [ -z "$exists" ]; then 43 | echo "Could not find printer matching this pattern" 44 | exit 45 | fi 46 | grep $1 printers.conf | read_config 47 | fi 48 | -------------------------------------------------------------------------------- /hackcu-printing.txt: -------------------------------------------------------------------------------- 1 | If you are using Linux, like me, you may have been frustrated by the lack of 2 | documentation for adding printers from Columbia's Ninja printing system to your 3 | computer. Well, this post will show you an easy-peasy way to set up printing on 4 | your Linux system. As an added bonus, this method should work on Mac OS X 5 | as well! 6 | 7 | Downloading: 8 | 9 | Get the script from https://raw.github.com/adicu/ninja-unix/master/addprinters.sh. 10 | 11 | Adding Printers: 12 | 13 | Running the script like so, 14 | 15 | sudo ./addprinters.sh 16 | 17 | without any arguments will add all the printers in the NINJA system to your 18 | computer. This will take a long time, so you may only want to add a subset. 19 | You can supply an argument to the script to restrict the printers installed. 20 | For instance. 21 | 22 | ./addprinters.sh butler 23 | 24 | will add all printers in Butler library. 25 | 26 | ./addprinters.sh butler301a 27 | 28 | adds a specific printer. 29 | 30 | Deleting printers: 31 | 32 | To delete a specific printer, run the command 33 | 34 | lpadmin -x printername 35 | 36 | where printername is the name of the printer. Alternatively, you can use the 37 | CUPS web interface by navigating to http://localhost:631 in your webbrowser 38 | and removing the printer from there. 39 | 40 | If you need to delete many printers at once. You can use the delprinters.sh 41 | script, available at https://raw.github.com/adicu/ninja-unix/master/addprinters.sh. 42 | The usage is the same as the addprinters.sh script. 43 | 44 | 45 | Printing from the Command Line: 46 | 47 | You may be thinking: "I'm a Linux user dammit, how do I print from the command line". 48 | 49 | This is easy enough, just do 50 | 51 | lpr -d printername filename 52 | 53 | Where printername is the name of the NINJA printer and filename is the name of a PostScript, PDF, or Image File. 54 | 55 | Possible problems: 56 | 57 | If you see the error message "Could not find the lpadmin program", you do not have the Common Unix Printing System (CUPS) installed. In most distributions, CUPS can be found in a package called, well "cups". 58 | 59 | If you see the message "Could not find foomatic-ppdfile", you do not have the foomatic database installed. Foomatic is a database containing the driver information for many different printer types. In most distros, foomatic is generally composed of two packages "foomatic-db" and "foomatic-db-engine". 60 | 61 | If you see "lpadmin: could not read ppd file", something may have gone wrong during installation, delete the printer and try again. 62 | -------------------------------------------------------------------------------- /printers.conf: -------------------------------------------------------------------------------- 1 | avery200a avery200a-ninja.atg.columbia.edu Avery 2 | avery200b avery200b-ninja.atg.columbia.edu Avery 3 | bclibrary100a bclibrary100a-ninja.barnard.edu Barnard 4 | bclibrary200a bclibrary200a-ninja.barnard.edu Barnard 5 | broadway100a broadway100a-ninja.atg.columbia.edu Residence Halls 6 | broadway304a broadway304a-ninja.atg.columbia.edu Residence Halls 7 | brooks100a brooks100a-ninja.barnard.edu Barnard 8 | brooks100b brooks100b-ninja.barnard.edu Barnard 9 | burke100a burke100a-ninja.atg.columbia.edu Burke 10 | burke300a burke300a-ninja.atg.columbia.edu Burke 11 | butler209a butler209a-ninja.atg.columbia.edu Butler 12 | butler209b butler209b-ninja.atg.columbia.edu Butler 13 | butler213a butler213a-ninja.atg.columbia.edu Butler 14 | butler213b butler213b-ninja.atg.columbia.edu Butler 15 | butler213c butler213c-ninja.atg.columbia.edu Butler 16 | butler213color butler213color-ninja.atg.columbia.edu Mudd 17 | butler300a butler300a-ninja.atg.columbia.edu Butler 18 | butler300b butler300b-ninja.atg.columbia.edu Butler 19 | butler305a butler305a-ninja.atg.columbia.edu Butler 20 | butler401a butler401a-ninja.atg.columbia.edu Butler 21 | butler403a butler403a-ninja.atg.columbia.edu Butler 22 | butler501a butler501a-ninja.atg.columbia.edu Butler 23 | butler606a butler606a-ninja.atg.columbia.edu Butler 24 | campbell505a campbell505a-ninja.atg.columbia.edu Baker Athletics Complex 25 | carlton100a carlton100a-ninja.atg.columbia.edu Residence Halls 26 | carlton100b carlton100b-ninja.atg.columbia.edu Residence Halls 27 | carman103b carman103b-ninja.atg.columbia.edu Residence Halls 28 | ccsa ccsa-ninja.atg.columbia.edu Career Services 29 | claremntb01a claremntb01a-ninja.atg.columbia.edu Residence Halls 30 | dcc413a dcc413a-ninja.barnard.edu Barnard 31 | dcc413b dcc413b-ninja.barnard.edu Barnard 32 | diana307a diana307a-ninja.barnard.edu Barnard 33 | diana307b diana307b-ninja.barnard.edu Barnard 34 | diana307c diana307c-ninja.barnard.edu Barnard 35 | diana307d diana307d-ninja.barnard.edu Barnard 36 | dodgeart412a dodgeart412a-ninja.atg.columbia.edu Dodge 37 | dodgeart412b dodgeart412b-ninja.atg.columbia.edu Dodge 38 | dodgeart701a dodgeart701a-ninja.atg.columbia.edu Dodge 39 | dodgeart701b dodgeart701b-ninja.atg.columbia.edu Dodge 40 | ec01a ec01a-ninja.atg.columbia.edu Residence Halls 41 | ec10a ec10a-ninja.atg.columbia.edu Residence Halls 42 | ec10b ec10b-ninja.atg.columbia.edu Residence Halls 43 | ec18a ec18a-ninja.atg.columbia.edu Residence Halls 44 | et251a et251a-ninja.atg.columbia.edu Mudd 45 | et251b et251b-ninja.atg.columbia.edu Mudd 46 | et251c et251c-ninja.atg.columbia.edu Mudd 47 | furnald107a furnald107a-ninja.atg.columbia.edu Residence Halls 48 | harmony100a harmony100a-ninja.atg.columbia.edu Residence Halls 49 | hartley111a hartley111a-ninja.atg.columbia.edu Residence Halls 50 | hartley111b hartley111b-ninja.atg.columbia.edu Residence Halls 51 | iab215a iab215a-ninja.atg.columbia.edu International Affairs 52 | iab310a iab310a-ninja.atg.columbia.edu International Affairs 53 | iab323a iab323a-ninja.atg.columbia.edu International Affairs 54 | iab323a iab323a-ninja.atg.columbia.edu International Affairs 55 | iab323b iab323b-ninja.atg.columbia.edu International Affairs 56 | iab323color iab323color-ninja.atg.columbia.edu International Affairs 57 | iab509a iab509a-ninja.atg.columbia.edu International Affairs 58 | johnjay100a johnjay100a-ninja.atg.columbia.edu Lerner 59 | johnjay100b johnjay100b-ninja.atg.columbia.edu Lerner 60 | kent300a kent300a-ninja.atg.columbia.edu Kent 61 | kent300b kent300b-ninja.atg.columbia.edu Kent 62 | lehman018a lehman018a-ninja.barnard.edu Barnard 63 | lerner200a lerner200a-ninja.atg.columbia.edu Lerner 64 | lerner200b lerner200b-ninja.atg.columbia.edu Lerner 65 | lerner300a lerner300a-ninja.atg.columbia.edu Lerner 66 | lerner300b lerner300b-ninja.atg.columbia.edu Lerner 67 | lewisohn300a lewisohn300a-ninja.atg.columbia.edu Lewisohn 68 | lewisohn300b lewisohn300b-ninja.atg.columbia.edu Lewisohn 69 | math303a math303a-ninja.atg.columbia.edu Math 70 | mcbain100a mcbain100a-ninja.atg.columbia.edu Residence Halls 71 | mcbain100b mcbain100b-ninja.atg.columbia.edu Residence Halls 72 | mudd422a mudd422a-ninja.atg.columbia.edu Mudd 73 | mudd422b mudd422b-ninja.atg.columbia.edu Mudd 74 | nwcb400a nwcb400a-ninja.atg.columbia.edu Northwest Corner Building 75 | nwcb400b nwcb400b-ninja.atg.columbia.edu Northwest Corner Building 76 | nwcb600a nwcb600a-ninja.atg.columbia.edu Northwest Corner Building 77 | nwcb600b nwcb600b-ninja.atg.columbia.edu Northwest Corner Building 78 | plimpton100a plimpton100a-ninja.barnard.edu Barnard 79 | plimpton100b plimpton100b-ninja.barnard.edu Barnard 80 | riverb01a riverb01a-ninja.atg.columbia.edu Residence Halls 81 | ruggles100a ruggles100a-ninja.atg.columbia.edu Residence Halls 82 | russell100a russell100a-ninja.tc.columbia.edu Teachers College 83 | russell100b russell100b-ninja.tc.columbia.edu Teachers College 84 | schapiro108a schapiro108a-ninja.atg.columbia.edu Residence Halls 85 | schapiro108b schapiro108b-ninja.atg.columbia.edu Residence Halls 86 | schermerhorn558a schermerhorn558a-ninja.atg.columbia.edu Schermerhorn 87 | schermerhorn601a schermerhorn601a-ninja.atg.columbia.edu Schermerhorn 88 | sicb01a sicb01a-ninja.atg.columbia.edu SIC 89 | six00w113a six00w113a-ninja.atg.columbia.edu Residence Halls 90 | sixsixteen100a sixsixteen100a-ninja.barnard.edu Barnard 91 | sixsixteen100b sixsixteen100b-ninja.barnard.edu Barnard 92 | socialwork105a socialwork105a-ninja.atg.columbia.edu Social Work 93 | socialwork105b socialwork105b-ninja.atg.columbia.edu Social Work 94 | socialwork105c socialwork105c-ninja.atg.columbia.edu Social Work 95 | socialwork105d socialwork105d-ninja.atg.columbia.edu Social Work 96 | socialwork105e socialwork105e-ninja.atg.columbia.edu Social Work 97 | socialwork202a socialwork202a-ninja.atg.columbia.edu Social Work 98 | socialwork202a socialwork202a-ninja.atg.columbia.edu Social Work 99 | socialwork207a socialwork207a-ninja.atg.columbia.edu Social Work 100 | socialwork207a socialwork207a-ninja.atg.columbia.edu Social Work 101 | socialwork214a socialwork214a-ninja.atg.columbia.edu Social Work 102 | socialwork309a socialwork309a-ninja.atg.columbia.edu Social Work 103 | socialwork401a socialwork401a-ninja.atg.columbia.edu Social Work 104 | socialwork721a socialwork721a-ninja.atg.columbia.edu Social Work 105 | socialwork821a socialwork821a-ninja.atg.columbia.edu Social Work 106 | socialwork900a socialwork900a-ninja.atg.columbia.edu Social Work 107 | stat902a stat902a-ninja.atg.columbia.edu Statistics 108 | sulzberger100a sulzberger100a-ninja.barnard.edu Barnard 109 | uris130a uris130a-ninja.atg.columbia.edu Uris 110 | uris130b uris130b-ninja.atg.columbia.edu Uris 111 | uris130c uris130c-ninja.atg.columbia.edu Uris 112 | uris130d uris130d-ninja.atg.columbia.edu Uris 113 | watson8 watson8-ninja.atg.columbia.edu Watson 114 | watson811a watson811a-ninja.atg.columbia.edu Watson 115 | watt100a watt100a-ninja.atg.columbia.edu Residence Halls 116 | wien211a wien211a-ninja.atg.columbia.edu Residence Halls 117 | wien211b wien211b-ninja.atg.columbia.edu Residence Halls 118 | woodbridge100a woodbridge100a-ninja.atg.columbia.edu Residence Halls 119 | -------------------------------------------------------------------------------- /scraper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #Moses Nakamura & Nate Brennand 3 | import urllib 4 | 5 | 6 | #all of the js files that have the information we need 7 | links=["http://www.columbia.edu/acis/facilities/printers/ninja/acis/js/printers.js", 8 | "http://www.columbia.edu/acis/facilities/printers/ninja/barnard/js/printers.js", 9 | "http://www.columbia.edu/acis/facilities/printers/ninja/cait/js/printers.js", 10 | "http://www.columbia.edu/acis/facilities/printers/ninja/lso/js/printers.js", 11 | "http://www.columbia.edu/acis/facilities/printers/ninja/meche/js/printers.js", 12 | "http://www.columbia.edu/acis/facilities/printers/ninja/old_pcd/js/printers.js", 13 | "http://www.columbia.edu/acis/facilities/printers/ninja/soa/js/printers.js", 14 | "http://www.columbia.edu/acis/facilities/printers/ninja/ssw/js/printers.js"] 15 | 16 | lst=[] 17 | #scrapes the files, puts the information into lists in lists 18 | for link in links: 19 | filep = urllib.urlopen(link) 20 | for line in filep: 21 | if line.count('[') == 2: 22 | line = line.replace('"', '') # removing double quotations from strings 23 | line = line[line.rfind('[')+1 : line.rfind(']')-1] 24 | lst.append(line.split(",")) 25 | 26 | #organizes the information nicely 27 | towrite = [] 28 | 29 | for line in sorted(lst): 30 | towrite.append("{} {} {}\n".format(line[0], line[1], line[3])) 31 | 32 | #writes it into the correct format in newprinter.yaml file 33 | filep = open("printers.conf","w") 34 | filep.writelines(towrite) 35 | 36 | --------------------------------------------------------------------------------