106 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Plaintext
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env ground
 | |
| 
 | |
| # dig package manager
 | |
| # this is a simple package manager for the Ground programming language
 | |
| 
 | |
| extern "request"
 | |
| extern "file"
 | |
| extern "exec"
 | |
| 
 | |
| set &rootURL "https://ground.chookspace.com/pkgs/"
 | |
| 
 | |
| getlistsize *args &size
 | |
| greater $size 0 &cond
 | |
| if $cond %checkArgs
 | |
| 
 | |
| stdlnout "Dig package manager"
 | |
| stdlnout "Type 'digpkg install pkgname' to install a package or 'digpkg help' for more information"
 | |
| end 1
 | |
| 
 | |
| @checkArgs
 | |
| 
 | |
| getlistat *args 0 &instruction
 | |
| 
 | |
| equal $instruction "install" &cond
 | |
| if $cond %install
 | |
| 
 | |
| equal $instruction "init" &cond
 | |
| if $cond %init
 | |
| 
 | |
| equal $instruction "run" &cond
 | |
| if $cond %run
 | |
| 
 | |
| equal $instruction "help" &cond
 | |
| if $cond %help
 | |
| 
 | |
| @install
 | |
| greater $size 1 &cond
 | |
| if $cond %installcontinue
 | |
| stdlnout "Usage: digpkg install pkgname"
 | |
| end 1
 | |
| 
 | |
| @installcontinue
 | |
| 
 | |
| # Download the package
 | |
| getlistat *args 1 &pkgname
 | |
| stdout "Downloading "
 | |
| stdlnout $pkgname
 | |
| 
 | |
| add $pkgname ".tar" &pkgfile
 | |
| add $rootURL $pkgfile &url
 | |
| add "/tmp/" $pkgfile &tmpstorage
 | |
| 
 | |
| pusharg $url
 | |
| pusharg $tmpstorage
 | |
| call !saveContents &status
 | |
| 
 | |
| if $status %downloadSuccess
 | |
| stdlnout "Download not successful"
 | |
| end 1
 | |
| 
 | |
| @downloadSuccess
 | |
| 
 | |
| # Extract using tar on the system
 | |
| stdout "Extrating "
 | |
| stdlnout $pkgname
 | |
| add "tar -xf " $tmpstorage &cmd
 | |
| add $cmd " -C /usr/lib/ground" &cmd
 | |
| 
 | |
| pusharg $cmd
 | |
| call !exec &status
 | |
| equal 0 $status &cond
 | |
| 
 | |
| if $cond %extractSuccess
 | |
| stdlnout "Extraction not successful"
 | |
| end 1
 | |
| 
 | |
| @extractSuccess
 | |
| 
 | |
| # Report success to the user
 | |
| stdlnout "Success!"
 | |
| end 0
 | |
| 
 | |
| @init
 | |
| 
 | |
| stdlnout "Working on it"
 | |
| end 0
 | |
| 
 | |
| @run
 | |
| 
 | |
| stdlnout "Working on it"
 | |
| end 0
 | |
| 
 | |
| @help
 | |
| stdlnout "dig package manager"
 | |
| stdlnout "This allows easier use of the Ground programming language"
 | |
| stdlnout "Usage:"
 | |
| stdlnout "    digpkg install (package name)"
 | |
| stdlnout "        Installs a package to /usr/lib/ground (requires sudo/root access)"
 | |
| stdlnout "    digpkg init"
 | |
| stdlnout "        Initialises a Ground project in a directory, creating a Digfile and src/main.grnd"
 | |
| stdlnout "    digpkg run"
 | |
| stdlnout "        Runs a Ground program, if there is a Digfile in the current directory"
 | |
| stdlnout "    digpkg help"
 | |
| stdlnout "        Prints this error message"
 | |
| end 0
 |