|
1 | | -echo "Enter SDK name: " |
2 | | -read name |
| 1 | +# Store the start directory for later reference |
3 | 2 | STARTDIR=$PWD |
4 | | -cd sdks |
5 | | -if [ ! -d $PWD/hl2sdk-$name ]; then |
6 | | - mkdir $PWD/hl2sdk-$name |
7 | | -fi |
8 | | -cd hl2sdk-$name |
9 | | -hg init |
10 | | -hg revert --all |
11 | | -hg pull -u https://hg.alliedmods.net/hl2sdks/hl2sdk-$name |
12 | | -if [ -d $STARTDIR/patches/hl2sdk-$name ]; then |
13 | | - cd .. |
14 | | - cd .. |
15 | | - cd patches/hl2sdk-$name |
16 | | - cp -r * $STARTDIR/sdks/hl2sdk-$name |
17 | | -fi |
| 3 | + |
| 4 | +# Store the sdk directory for later reference |
| 5 | +SDKDIR=$STARTDIR/makefiles/sdk |
| 6 | + |
| 7 | +# A function to restart the process from |
| 8 | +ChooseSDK () { |
| 9 | + |
| 10 | + echo "Choose the SDK you wish to download:" |
| 11 | + echo. |
| 12 | + |
| 13 | + # Store a base counting variable |
| 14 | + num=0 |
| 15 | + |
| 16 | + # Loop through all sdks supported by the plugin |
| 17 | + for filepath in $(find $SDKDIR -type f -maxdepth 1) |
| 18 | + do |
| 19 | + |
| 20 | + # Increment the counter |
| 21 | + num=$(( $num + 1)) |
| 22 | + |
| 23 | + # Get the name of the file |
| 24 | + filename=${filepath##*/} |
| 25 | + file=${filename%.*} |
| 26 | + |
| 27 | + # Store the option by its number |
| 28 | + eval option_${num}=${file} |
| 29 | + |
| 30 | + # Print the current option |
| 31 | + echo -e "\t$num) $file" |
| 32 | + done |
| 33 | + |
| 34 | + echo. |
| 35 | + |
| 36 | + # Request a choice of sdk |
| 37 | + read choice |
| 38 | + |
| 39 | + # Was the choice invalid? |
| 40 | + if ! echo $choice | egrep -q '^[0-9]+$'; then |
| 41 | + ChooseSDK |
| 42 | + elif [ $choice -le 0 ] ; then |
| 43 | + ChooseSDK |
| 44 | + elif [ $choice -gt $num ] ; then |
| 45 | + ChooseSDK |
| 46 | + |
| 47 | + # The choice was valid |
| 48 | + else |
| 49 | + |
| 50 | + # Get the sdk chosen |
| 51 | + name=option_$choice |
| 52 | + name=${!name} |
| 53 | + |
| 54 | + # Navigate to the specific sdk folder (create it if it does not exist) |
| 55 | + cd sdks |
| 56 | + if [ ! -d $PWD/hl2sdk-$name ]; then |
| 57 | + mkdir $PWD/hl2sdk-$name |
| 58 | + fi |
| 59 | + cd hl2sdk-$name |
| 60 | + |
| 61 | + # Initialize the repo in case this is the first time this sdk is being downloaded |
| 62 | + hg init |
| 63 | + |
| 64 | + # Revert any changes. This is done to remove any patch changes which are pulled in later. |
| 65 | + hg revert --all |
| 66 | + |
| 67 | + # Pull the newest changeset from alliedmods.net |
| 68 | + hg pull -u https://hg.alliedmods.net/hl2sdks/hl2sdk-$name |
| 69 | + |
| 70 | + # Copy any patched files over if any exist for the specific sdk |
| 71 | + if [ -d $STARTDIR/patches/hl2sdk-$name ]; then |
| 72 | + cd $STARTDIR/patches/hl2sdk-$name |
| 73 | + cp -r * $STARTDIR/sdks/hl2sdk-$name |
| 74 | + fi |
| 75 | + fi |
| 76 | +} |
| 77 | + |
| 78 | +ChooseSDK |
0 commit comments