Commit b477de83 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Initial commit

parents
language: rust
rust:
- nightly
sudo: false
notifications:
email: false
[root]
name = "pkgutils"
version = "0.1.0"
dependencies = [
"octavo 0.1.1 (git+https://github.com/libOctavo/octavo)",
"termion 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "generic-array"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.17"
source = "git+https://github.com/redox-os/liblibc.git?branch=new_kernel#e1481692c25d9be513f2f8bf8c77cce2573a6e9f"
[[package]]
name = "libc"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
replace = "libc 0.2.17 (git+https://github.com/redox-os/liblibc.git?branch=new_kernel)"
[[package]]
name = "octavo"
version = "0.1.1"
source = "git+https://github.com/libOctavo/octavo#d94d924616dca83b9c6cfc815062276c5908713a"
dependencies = [
"octavo-digest 0.1.2 (git+https://github.com/libOctavo/octavo)",
]
[[package]]
name = "octavo-digest"
version = "0.1.2"
source = "git+https://github.com/libOctavo/octavo#d94d924616dca83b9c6cfc815062276c5908713a"
dependencies = [
"byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"static-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "static-buffer"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typenum"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855"
"checksum generic-array 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3406a3975bc944fdd85b7964d53296a0ff11f4b6c4704fa4972c9a7c8ba27367"
"checksum libc 0.2.17 (git+https://github.com/redox-os/liblibc.git?branch=new_kernel)" = "<none>"
"checksum libc 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "044d1360593a78f5c8e5e710beccdc24ab71d1f01bc19a29bcacdba22e8475d8"
"checksum octavo 0.1.1 (git+https://github.com/libOctavo/octavo)" = "<none>"
"checksum octavo-digest 0.1.2 (git+https://github.com/libOctavo/octavo)" = "<none>"
"checksum static-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6da6a96247d4b372d3ed90dec2c129ab57c934359ac4c6adbaa5871cd0737437"
"checksum termion 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce9884af069456867e19fd5648b8908d5c9378f586b2659aaa6f3a4088fdb867"
"checksum typenum 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20f316d9057bedfb465699a77d63d37d3eeef53a63ec835d715abd3bd3a87b5e"
[package]
name = "pkgutils"
version = "0.1.0"
[[bin]]
name = "pkg"
path = "src/pkg/main.rs"
[dependencies]
termion = "*"
[dependencies.octavo]
git = "https://github.com/libOctavo/octavo"
default-features = false
features = ["digest"]
[replace]
"libc:0.2.17" = { git = "https://github.com/redox-os/liblibc.git", branch = "new_kernel" }
"rustc-serialize:0.3.19" = { git = "https://github.com/redox-os/rustc-serialize.git" }
The MIT License (MIT)
Copyright (c) 2016 The Redox developers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Redox OS userutils
This repository contains utilities for user and group management for Redox. Additional related tools are included.
[![Travis Build Status](https://travis-ci.org/redox-os/userutils.svg?branch=master)](https://travis-ci.org/redox-os/userutils)
**Currently included:**
- `getty`
- `id`
- `login`
- `sudo`
extern crate octavo;
use std::{env, str};
use std::fs::File;
use std::io::{self, stderr, Read, Write};
use std::net::TcpStream;
use std::process::{self, Command};
fn install(package: &str) -> io::Result<()> {
let host = "static.redox-os.org";
let port = 80;
let path = format!("pkg/{}.tar", package);
write!(stderr(), "* Connecting to {}:{}\n", host, port)?;
let mut stream = TcpStream::connect((host, port))?;
write!(stderr(), "* Requesting {}\n", path)?;
let request = format!("GET /{} HTTP/1.1\r\nHost: {}\r\nConnection: close\r\n\r\n", path, host);
stream.write(request.as_bytes())?;
stream.flush()?;
write!(stderr(), "* Waiting for response\n")?;
let mut response = Vec::new();
loop {
let mut buf = [0; 65536];
let count = stream.read(&mut buf)?;
if count == 0 {
break;
}
response.extend_from_slice(&buf[.. count]);
}
write!(stderr(), "* Received {} bytes\n", response.len())?;
let mut header_end = 0;
while header_end < response.len() {
if response[header_end..].starts_with(b"\r\n\r\n") {
break;
}
header_end += 1;
}
let mut status = (0, String::new());
for line in unsafe { str::from_utf8_unchecked(&response[..header_end]) }.lines() {
if line.starts_with("HTTP/1.1 ") {
let mut args = line.split(' ').skip(1);
if let Some(arg) = args.next() {
if let Ok(status_code) = arg.parse::<usize>() {
status.0 = status_code;
}
}
status.1 = args.collect::<Vec<&str>>().join(" ");
}
write!(stderr(), "> {}\n", line)?;
}
match status.0 {
200 => {
write!(stderr(), "* Success {} {}\n", status.0, status.1)?;
let path = format!("{}.tar", package);
let mut file = File::create(&path)?;
file.write(&response[header_end + 4 ..])?;
Command::new("tar")
.arg("tf")
.arg(&path)
.spawn()?
.wait()?;
},
_ => {
write!(stderr(), "* Failure {} {}\n", status.0, status.1)?;
}
}
Ok(())
}
fn main() {
let mut args = env::args().skip(1);
if let Some(op) = args.next() {
match op.as_str() {
"install" => {
let packages: Vec<String> = args.collect();
if ! packages.is_empty() {
for package in packages.iter() {
if let Err(err) = install(package) {
let _ = write!(io::stderr(), "pkg: install: {}: failed: {}\n", package, err);
} else {
let _ = write!(io::stderr(), "pkg: install: {}: succeeded\n", package);
}
}
} else {
let _ = write!(io::stderr(), "pkg: install: no packages specified\n");
process::exit(1);
}
},
_ => {
let _ = write!(io::stderr(), "pkg: {}: unknown operation\n", op);
process::exit(1);
}
}
} else {
let _ = write!(io::stderr(), "pkg: no operation\n");
process::exit(1);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment