Skip to content

Commit dcd3bb5

Browse files
authored
Merge pull request #154 from mitre/develop
Develop
2 parents eff3801 + 7a80693 commit dcd3bb5

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

cmd/root.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package cmd
1717

1818
import (
19+
"fmt"
1920
"os"
2021

2122
"github.com/mattrbianchi/twig"
@@ -48,10 +49,11 @@ func init() {
4849

4950
viper.SetEnvPrefix(flags.EnvPrefix)
5051
viper.AutomaticEnv()
52+
flags.BinaryName = "fusera"
5153
}
5254

5355
var rootCmd = &cobra.Command{
54-
Use: "fusera",
56+
Use: flags.BinaryName,
5557
Short: "A FUSE interface to the NCBI Sequence Read Archive (SRA) - " + flags.Version,
5658
Long: ``,
5759
Version: flags.Version,
@@ -60,6 +62,10 @@ var rootCmd = &cobra.Command{
6062
// Execute runs the main command of fusera, which has no action of its own,
6163
// so it evaluates which subcommand should be executed.
6264
func Execute() {
65+
if os.Geteuid() == 0 {
66+
fmt.Println("Running Fusera as root is not supported. This causes problems with mounting the filesystem using FUSE.")
67+
os.Exit(1)
68+
}
6369
if err := rootCmd.Execute(); err != nil {
6470
prettyPrintError(err)
6571
os.Exit(1)

flags/flags.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var (
1414
EnvPrefix = "dbgap"
1515
// Version should be set at compile time to `git describe --tags --abbrev=0`
1616
Version string
17+
// BinaryName should be set on init in order to know what binary is using the flags library.
18+
BinaryName string
1719

1820
LocationName = "location"
1921
AccessionName = "accession"
@@ -50,10 +52,10 @@ var (
5052
EndpointMsg = "ADVANCED: Change the endpoint used to communicate with SDL API.\nEnvironment Variable: [$DBGAP_ENDPOINT]"
5153
AwsBatchMsg = "ADVANCED: Adjust the amount of accessions put in one request to the SDL API when using an AWS location.\nEnvironment Variable: [$DBGAP_AWS-BATCH]"
5254
GcpBatchMsg = "ADVANCED: Adjust the amount of accessions put in one request to the SDL API when using a GCP location.\nEnvironment Variable: [$DBGAP_GCP-BATCH]"
53-
AwsProfileMsg = "The desired AWS credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_AWS-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files through fusera."
54-
GcpProfileMsg = "The desired GCP credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_GCP-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files through fusera. These credentials should be in the AWS supported format that Google provides in order to work with their AWS compatible API."
55-
SilentMsg = "Fusera prints nothing, most useful for using fusera in scripts."
56-
VerboseMsg = "Fusera prints everything, most useful for troubleshooting."
55+
AwsProfileMsg = "The desired AWS credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_AWS-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files."
56+
GcpProfileMsg = "The desired GCP credentials profile in ~/.aws/credentials to use for instances when files require the requester (you) to pay for accessing the file.\nEnvironment Variable: [$DBGAP_GCP-PROFILE]\nNOTE: This account will be charged all cost accrued by accessing these certain files. These credentials should be in the AWS supported format that Google provides in order to work with their AWS compatible API."
57+
SilentMsg = "Prints nothing, most useful when running in scripts."
58+
VerboseMsg = "Prints everything, most useful for troubleshooting."
5759
)
5860

5961
// ResolveLocation attempts to resolve the location on GCP and AWS.

sdl/sdl.go

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (c *Client) makeRequest(accessions []string, meta bool) ([]*fuseralib.Acces
9393
if err != nil {
9494
return nil, errors.New("can't create request to SDL API")
9595
}
96+
req.Header.Set("User-Agent", flags.BinaryName+"-"+flags.Version)
9697
req.Header.Set("Content-Type", writer.FormDataContentType())
9798
if flags.Verbose {
9899
reqdump, err := httputil.DumpRequestOut(req, true)

sracp/cmd/root.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ func init() {
9393

9494
viper.SetEnvPrefix("dbgap")
9595
viper.AutomaticEnv()
96+
97+
flags.BinaryName = "sracp"
9698
}
9799

98100
var rootCmd = &cobra.Command{
99-
Use: "sracp",
101+
Use: flags.BinaryName,
100102
Short: "A tool similar to cp that allows a user to download accessions - " + flags.Version,
101103
Long: ``,
102104
Version: flags.Version,
@@ -148,6 +150,12 @@ var rootCmd = &cobra.Command{
148150
}
149151
}
150152
path := args[0]
153+
// Test whether we can write to this location. If not, fail here.
154+
err = os.MkdirAll(filepath.Join(path, ".test"), 0755)
155+
if err != nil {
156+
fmt.Printf("It seems like sracp cannot make directories under %s. Please check that you have correct permissions to write to that path.\n", path)
157+
os.Exit(1)
158+
}
151159
batch := flags.ResolveBatch(platform.Name, awsBatch, gcpBatch)
152160

153161
var accessions []*fuseralib.Accession
@@ -298,6 +306,10 @@ var rootCmd = &cobra.Command{
298306

299307
// Execute runs the root command of sracp, which copies files from the cloud to a local file system.
300308
func Execute() {
309+
if os.Geteuid() == 0 {
310+
fmt.Println("Running sracp as root is not supported. The tool should not require root.")
311+
os.Exit(1)
312+
}
301313
if err := rootCmd.Execute(); err != nil {
302314
fmt.Println(err)
303315
os.Exit(1)

0 commit comments

Comments
 (0)