rsnk96 / Ubuntu-Setup-Scripts

Scripts to help you set up your Ubuntu quickly, especially if you're in any subfield of Data Science or AI!
Apache License 2.0
126 stars 76 forks source link

1-BasicSetUp.Sh can only be run once #44

Closed aswinkumar1999 closed 5 years ago

aswinkumar1999 commented 5 years ago

It seems the script ( 1-BasicSetup.sh) can be run only once after ZSH gets installed . I interrupted the 1-BasicSetUp.sh after the zsh was installed , When i ran it for the second time , It compiled zsh from source and interrupted the script with the following error.

fatal: destination path '/opt/.zsh/zim' already exists and is not an empty directory.

Upon manually removing it and running the script again , i ended up with

fatal: destination path '/opt/.zsh/zsh-autosuggestions' already exists and is not an empty directory.

Now , I deleted both the zim and zsh-autosuggestions folders and ran the script again and it worked.

There are two ways to overcome it. One way is to remove the folders everytime you run the script as it builds it from source everytime. In that case I guess Adding these lines before installing zsh would help it to check if there are empty folder and delete them and go ahead with the installation without breaking the script.

target=/opt/.zsh/
if find "$target" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then
   rm -r /opt/.zsh/*
fi

Here is where i referred the code from : https://stackoverflow.com/questions/20456666/bash-checking-if-folder-has-contents?noredirect=1&lq=1

Or the other way is to Skip the Installation of zsh and move on with the next command. ( Which i am sceptical because the code could have copied data files in there but could have been interrupted midway zsh installation ) .

rajat2004 commented 5 years ago

Well, none of the scripts are made to be run more than once (at least not without cleaning up or commenting out some lines before running it again). You'll face things like errors about existing directories, downloads happening again, repositories being added multiple times, etc.

That said, checking for whether /opt/.zsh exists before running mkdir could be added. But I don't feel that this is the best way to handle the matter. Suppose the zsh installation has completed successfully and then the user stops the scripts, then going by this way would rebuild zsh. Maybe if the directory exists, then the user can be asked whether they would like to rebuild zsh from scratch again or keep it as it is?

But then another matter pops up as to we don't know where the script has been stopped. Suppose it stopped while zim or zsh-autosuggestions was being cloned, that would cause problems if the user chooses to leave it as it is. @rsnk96 Your opinion as to the best way to handle this?

@aswinkumar1999 Re how to check if the directory exists or not, there are other ways also such as something like if [[ -d "folder" ]], there would be many instances of this in the scripts itself, you can look in openCV.sh or ML-Build.sh

rsnk96 commented 5 years ago

The easiest option is to delete and rebuild. I agree that it may be additional effort, but it's a sure shot solution, so I'd recommend doing that

@aswinkumar1999 are you up for trying it out and submitting a PR? It'd definitely be a value add

rajat2004 commented 5 years ago

45 has been merged, so closing this