Skip to content

Commit

Permalink
initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
silvernode committed Oct 22, 2015
0 parents commit 895d2d0
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
42 changes: 42 additions & 0 deletions PkgMgrs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env ruby

#Add your package managers here

$debianBased="apt-get"
$archLinux="pacman"
$voidLinux="xbps"

#command binding methods for different package managers
def pacman()
$installCmd = "pacman -S"
$searchCmd = "pacman -Ss"
$updateCmd = "pacman -Su"
$syncCmd = "pacman -Sy"
$syncANDupdateCmd = "pacman -Syu"
$refreshSyncCmd = "pacman -Syy"
$removeCmd = "pacman -R"
$recursiveRemoveCmd = "pacman -Rdd"
$checkUpdatesCmd = "checkupdates"
end

def apt_get()
$installCmd = "apt-get install"
$searchCmd = "apt-cache search"
$updateCmd = "apt-get upgrade"
$syncCmd = "apt-get update"
$syncANDupdateCmd = "apt-get update;apt-get upgrade"
$refreshSyncCmd = "apt-get update"
$removeCmd = "apt-get remove"
$recursiveRemoveCmd = "apt-get --purge remove"
end

def xbps_install()
$installCmd = "xbps-install"
$searchCmd = "xbps-query -Rs"
$updateCmd = "xbps-install -u"
$syncCmd = "xbps-install -S"
$syncANDupdateCmd = "xbps-install -Su"
$refreshSyncCmd = "xbps-instal -f -S"
$removeCmd = "xbps-remove"
$recursiveRemoveCmd = "xbps-remove -f"
end
125 changes: 125 additions & 0 deletions tux
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env ruby
require_relative 'which'
require_relative 'PkgMgrs'


args=ARGV
argsShift=[]

for i in args do
argsShift.push(i)
end

argsShift.shift

for i in argsShift do
pkgArgs = "#{pkgArgs} #{i}"
end

#package managers to check for
pkgMgrs = ["#{$debianBased}",
"#{$archLinux}",
"#{$voidLinux}"]

#iterate over list of package managers
#pass this to which(), take result and set it to pkgMgr
for i in pkgMgrs do
if which(i) then
pkgMgr=i
break
end
end

# since some package managers have hyphens
# and since methods can't have hyphens,
# we take out any existing hyphens and replace them with underscores
pkgMgr = pkgMgr.tr('-', '_')

# check for and execute methods with the same name as pkgMgr contains
send(pkgMgr)


#pull variables from currently loaded method, e.g pacman()
install = "#{$installCmd} #{pkgArgs}"
search = "#{$searchCmd} #{pkgArgs}"
update = "#{$updateCmd} #{pkgArgs}"
remove = "#{$removeCmd} #{pkgArgs}"
sync = "#{$syncCmd} #{pkgArgs}"
supdate = "#{$syncANDupdateCmd} #{pkgArgs}"



case args[0]

# Install Options
when
"i",
"-i",
"-S",
"get",
"install"; system ("sudo #{install}")

# Search options
when
"s",
"se",
"-s",
"-Ss",
"find",
"search"; system (search)

# Update options (without syncing)
when
"u",
"up",
"-u",
"-Su",
"upgrade"; system ("sudo #{update}")

# Remove options
when
"r",
"rm",
"-R",
"remove",
"delete"; system ("sudo #{remove}")

# Sync options
when
"sy",
"-Sy",
"sync",
"refresh"; system ("sudo #{sync}")

# Update options (with syncing)
when
"sup",
"-Syu",
"syncup"; system ("sudo #{supdate}")

when
"-v",
"--version"; puts """
tux v0.1 - Universal package manager wrapper
\u00A9 2015 Justin Moore
"""

else
puts """
Usage : tux [options] [arguments]
Options:
i, -S, install Install a package
r, -R, remove Remove a package
s, -Ss, search Search remote repository
sy, -Sy, sync Sync package list from remote repository
u, -Su, upgrade Upgrade packages on the system
su, -Syu, sup Sync package list and upgrade system
-v, --version Show current version
"""

end
14 changes: 14 additions & 0 deletions which.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end

0 comments on commit 895d2d0

Please sign in to comment.