|
1 | 1 | #!/bin/bash |
2 | 2 |
|
| 3 | +TMP="/tmp/project" |
| 4 | +PROJECT_HOME="/lab" |
| 5 | + |
3 | 6 | # If no command line parameters given, provide usage banner |
4 | 7 | if [ $# -eq 0 ] |
5 | 8 | then |
6 | 9 | cat <<-____HERE |
7 | 10 | Usage: setup |
8 | | - setup Extract project to file system |
| 11 | + setup Extract project to $PROJECT_HOME |
9 | 12 | ... Future utility options TBD |
10 | 13 |
|
11 | 14 | ____HERE |
12 | 15 | exit |
13 | 16 | fi |
14 | 17 |
|
15 | | - |
| 18 | +# Parameter check |
16 | 19 | if [ "$1" != "setup" ]; then |
17 | 20 | echo "Unrecognized parameter. Run with no parameters for help." |
18 | 21 | exit |
19 | 22 | fi |
20 | 23 |
|
| 24 | +# Clear temporary directory just to be sure |
| 25 | +rm -rf "$TMP" |
| 26 | + |
| 27 | +# Check if expansion target directory has anything in it |
| 28 | +if [ "$(ls -A $PROJECT_HOME)" ]; then |
| 29 | + # Confirm deletion of contents of project folder |
| 30 | + read -p "> $PROJECT_HOME is not empty (includes hidden files). Delete contents before extracting project [y/n]? " -n 1 -r |
| 31 | + if [[ $REPLY =~ ^[Yy]$ ]] |
| 32 | + then |
| 33 | + echo "> Clearing $PROJECT_HOME ..." |
| 34 | + rm -rf "$PROJECT_HOME"/* |
| 35 | + else |
| 36 | + echo "> Project extraction cancelled." |
| 37 | + exit |
| 38 | + fi |
| 39 | +fi |
21 | 40 |
|
22 | 41 | # Extract archive listing and regex to determine base directory of files |
23 | | -basedir=`unzip -l /home/drsurly/awesomesauce2.zip | grep -E -o 'mvandervoord[^/]+' | head -1` |
| 42 | +BASEDIR=`unzip -l /home/drsurly/awesomesauce2.zip | grep -E -o 'mvandervoord[^/]+' | head -1` |
24 | 43 |
|
25 | 44 | # Extract the archive |
26 | | -echo "Extracting project" |
27 | | -unzip -q /home/drsurly/awesomesauce2.zip -d /tmp |
| 45 | +echo "> Extracting project..." |
| 46 | +unzip -q /home/drsurly/awesomesauce2.zip -d $TMP |
28 | 47 |
|
29 | 48 | # Delete any git junk -- first files and then directories |
30 | | -find /tmp -type f -iname ".git*" -delete |
31 | | -find /tmp -type d -name ".git" -exec rm -rf "{}" \; |
| 49 | +find $TMP -type f -iname ".git*" -delete |
| 50 | +find $TMP -type d -name ".git" -exec rm -rf "{}" \; |
32 | 51 |
|
33 | 52 | # Move extracted contents below $basedir to new base directory of /lab |
34 | | -mv /tmp/$basedir/* /lab |
| 53 | +mv "$TMP/$BASEDIR"/* "$PROJECT_HOME" |
| 54 | + |
| 55 | +chmod +x "$PROJECT_HOME"/start_lab |
35 | 56 |
|
36 | | -# Clean up /tmp |
37 | | -rm -rf /tmp/* |
| 57 | +# Clean up temporary directory |
| 58 | +rm -rf "$TMP" |
38 | 59 |
|
39 | | -echo "Done" |
40 | | -echo "See project contents in /lab" |
| 60 | +echo "> Done." |
| 61 | +echo "> See project contents in $PROJECT_HOME" |
0 commit comments