@ -28,10 +28,24 @@ fn list(dir: &str) -> Vec<String> {
dirs
dirs
}
}
pub fn aur_install ( a : Vec < String > , options : Options ) {
fn mktemp ( ) -> String {
let tempdir = Command ::new ( "mktemp" )
. args ( & [ "-d" , "/tmp/ame.XXXXXX.tmp" ] )
. output ( )
. unwrap ( )
. stdout ;
String ::from_utf8 ( tempdir ) . unwrap ( ) . trim ( ) . to_string ( )
}
pub fn aur_install ( a : Vec < String > , options : Options , cachedir : String ) {
// Initialise variables
// Initialise variables
let url = crate ::internal ::rpc ::URL ;
let url = crate ::internal ::rpc ::URL ;
let cachedir = format! ( "{}/.cache/ame/" , env ::var ( "HOME" ) . unwrap ( ) ) ;
let cachedir = if ! options . toplevel {
cachedir
} else {
mktemp ( )
} ;
let verbosity = options . verbosity ;
let verbosity = options . verbosity ;
let noconfirm = options . noconfirm ;
let noconfirm = options . noconfirm ;
@ -155,43 +169,59 @@ pub fn aur_install(a: Vec<String>, options: Options) {
if ! noconfirm {
if ! noconfirm {
// Prompt user to view PKGBUILD
// Prompt user to view PKGBUILD
let p1 = prompt ! ( default false ,
let p0 = prompt ! ( default false , "Would you like to review and/or edit {}'s PKGBUILD (and any adjacent build files if present)?" , pkg ) ;
"Would you like to review {}'s PKGBUILD (and any .install files if present)?" ,
if p0 {
pkg
info ! ( "This will drop you into a standard `bash` shell in the package's cache directory. If any changes are made, you will be prompted whether to save them to your home directory. To stop reviewing/editing, just run `exit`" ) ;
) ;
let p1 = prompt ! ( default true ,
let editor : & str = & env ::var ( "PAGER" ) . unwrap_or_else ( | _ | "less" . parse ( ) . unwrap ( ) ) ;
"Continue?"
) ;
if p1 {
// Open PKGBUILD in pager
if p1 {
Command ::new ( editor )
let cdir = env ::current_dir ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
. arg ( format! ( "{}/PKGBUILD" , pkg ) )
set_current_dir ( Path ::new ( & format! ( "{}/{}" , & cachedir , pkg ) ) ) . unwrap ( ) ;
. spawn ( )
. unwrap ( )
Command ::new ( "bash" ) . spawn ( ) . unwrap ( ) . wait ( ) . unwrap ( ) ;
. wait ( )
. unwrap ( ) ;
set_current_dir ( Path ::new ( & cdir ) ) . unwrap ( ) ;
// Check if any .install files are present
// Prompt user to save changes
let status = ShellCommand ::bash ( )
let p2 = prompt ! ( default false ,
. arg ( "-c" )
"Save changes to package {}?" ,
. arg ( format! ( "ls {}/*.install &> /dev/null" , pkg ) )
pkg
. wait ( )
) ;
. silent_unwrap ( AppExitCode ::Other ) ;
if p2 {
// Save changes to ~/.local/share
if status . success ( ) {
let dest = format! (
// If so, open them too
"{}-saved-{}" ,
ShellCommand ::bash ( )
pkg ,
. arg ( "-c" )
chrono ::Local ::now ( )
. arg ( format! ( "{} {}/*.install" , editor , pkg ) )
. naive_local ( )
. wait ( )
. format ( "%Y-%m-%d_%H-%M-%S" )
. silent_unwrap ( AppExitCode ::Other ) ;
) ;
}
Command ::new ( "cp" )
. arg ( "-r" )
// Prompt user to continue
. arg ( format! ( "{}/{}" , cachedir , pkg ) )
let p2 = prompt ! ( default true , "Would you still like to install {}?" , pkg ) ;
. arg ( format! (
if ! p2 {
"{}/.local/share/ame/{}" ,
// If not, crash
env ::var ( "HOME" ) . unwrap ( ) ,
fs ::remove_dir_all ( format! ( "{}/{}" , cachedir , pkg ) ) . unwrap ( ) ;
dest
crash ! ( AppExitCode ::UserCancellation , "Not proceeding" ) ;
) )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
// Alert user
info ! ( "Saved changes to ~/.local/share/ame/{}" , dest ) ;
} ;
// Prompt user to continue
let p3 = prompt ! ( default true , "Would you still like to install {}?" , pkg ) ;
if ! p3 {
// If not, crash
fs ::remove_dir_all ( format! ( "{}/{}" , cachedir , pkg ) ) . unwrap ( ) ;
crash ! ( AppExitCode ::UserCancellation , "Not proceeding" ) ;
} ;
}
}
}
}
}
}
@ -203,13 +233,13 @@ pub fn aur_install(a: Vec<String>, options: Options) {
crate ::operations ::install ( sorted . repo , newopts ) ;
crate ::operations ::install ( sorted . repo , newopts ) ;
}
}
if ! sorted . aur . is_empty ( ) {
if ! sorted . aur . is_empty ( ) {
crate ::operations ::aur_install ( sorted . aur , newopts );
crate ::operations ::aur_install ( sorted . aur , newopts , cachedir . clone ( ) );
}
}
if ! md_sorted . repo . is_empty ( ) {
if ! md_sorted . repo . is_empty ( ) {
crate ::operations ::install ( md_sorted . repo , newopts ) ;
crate ::operations ::install ( md_sorted . repo , newopts ) ;
}
}
if ! md_sorted . aur . is_empty ( ) {
if ! md_sorted . aur . is_empty ( ) {
crate ::operations ::aur_install ( md_sorted . aur , newopts );
crate ::operations ::aur_install ( md_sorted . aur , newopts , cachedir . clone ( ) );
}
}
// Build makepkg args
// Build makepkg args
@ -270,14 +300,25 @@ pub fn aur_install(a: Vec<String>, options: Options) {
. unwrap ( )
. unwrap ( )
. wait ( )
. wait ( )
. unwrap ( ) ;
. unwrap ( ) ;
// Remove everything from cachedir
crate ::init ( options ) ;
}
}
}
}
// If any packages failed to build, warn user with failed packages
// If any packages failed to build, warn user with failed packages
if ! failed . is_empty ( ) {
if ! failed . is_empty ( ) {
warn ! ( "Failed to build packages {}" , failed . join ( ", " ) ) ;
warn ! (
"Failed to build packages {}, keeping cache directory at {} for manual inspection" ,
failed . join ( ", " ) ,
cachedir
) ;
Command ::new ( "mv" )
. args ( & [ & cachedir , & format! ( "{}.failed" , cachedir ) ] )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
} else if options . toplevel {
rm_rf ::remove ( & cachedir ) . unwrap_or_else ( | e |
crash ! ( AppExitCode ::Other , "Could not remove cache directory at {}: {}. This could be a permissions issue with fakeroot, try running `sudo rm -rf {}`" , cachedir , e , cachedir )
) ;
}
}
}
}