#!/usr/bin/ruby #packom by Miles Sandlar - miles@bladdo.net - www.bladdo.net #Place this script in /usr/bin/ and rename it packom to run it freely #Script to more easily use opkg/ipkg in conjunction with it's config file so you don't have to edit it everytime you want to install or remove something #Designed for use with jLime #Distribute freely, just give credit $manager = "opkg" #Specify opkg or ipkg $confLoc = "/etc/opkg.conf" #Location of your config file, usually /etc/opkg.conf def installPkg(package) #Uncomment source enableSource(package[0].chr.downcase) puts "Attempting to install package: " + package #Update packages puts `#{$manager} update` #Run opkg to install the requested package puts `#{$manager} install #{package}` #Disable source disableSource(package[0].chr.downcase) end def removePkg(package) puts "Attempting to remove package: " + package #Run opkg to install the requested package puts `#{$manager} remove #{package}` end def enableSource(source) #Uncomment the Source we need File.open($confLoc, 'r+') do |config| lines = config.readlines lines.each do |line| if (line =~ /#src \w+-#{source}/) line.gsub!(/#src/, 'src') puts "Enabled Source: " + line.split(/ /)[1] end end config.pos = 0 config.print lines config.truncate(config.pos) end end def disableSource(source) #Recomment the Source File.open($confLoc, 'r+') do |config| lines = config.readlines lines.each do |line| if (line =~ /^src \w+-#{source}/) line.gsub!(/src/, '#src') puts "Disabled Source: " + line.split(/ /)[1] end end config.pos = 0 config.print lines config.truncate(config.pos) end end if (!ARGV.length == 2 || !ARGV[0] =~ /^-/) puts "Usage:\nInstall a Package:\tpackom -i package\nRemove a Package:\tpackom -r package\nEnable a source:\tpackom -e letter\nDisable a source:\tpackom -d letter\n" exit end case ARGV[0] when "-i" installPkg(ARGV[1]) when "-r" removePkg(ARGV[1]) when "-e" enableSource(ARGV[1][0].chr.downcase) when "-d" disableSource(ARGV[1][0].chr.downcase) else puts "Usage:\nInstall a Package:\tpackom -i package\nRemove a Package:\tpackom -r package\nEnable a source:\tpackom -e letter\nDisable a source:\tpackom -d letter\n" exit end