Skip to content
Snippets Groups Projects
Select Git revision
  • 172ccb2722995bb8a5a0260b394d9aec03278605
  • master default protected
2 results

install-aws.sh

Blame
  • Forked from Sebastian Rieger / cloud-computing-msc-ai-examples
    Source project has a limited visibility.
    setup.sh 8.40 KiB
    #!/bin/sh
    
    function initial_setup() {
        clear
    
        echo "The setup will now delete all branches and remotes and create a default develop and master branch. Continue? [Y/n]"
        read cont
        if [ $cont == "y" ] || [ $cont == "Y" ] || [ $cont == "" ]
        then
            current_branch=$(git rev-parse --abbrev-ref HEAD)
            branches_to_delete=$(git for-each-ref --format='%(refname:short)' refs/heads/)
    
            for branch in $branches_to_delete
            do
                if [ "$branch" != "$current_branch" ]
                then
                    git branch -d "$branch"
                fi
            done
    
            if [ "$current_branch" != "develop" ]
            then
                git checkout -b develop
                git branch -d "$current_branch"
            fi
    
            
            git add .
            git commit -m "Initial commit"
            git branch master
    
            git remote | xargs -n1 git remote remove
            echo "Enter URL of the project's git repository (Leave empty to skip this step):"
            read new_remote
    
            if [ -n "$new_remote" ]
            then
                echo "Setting up repository..."
                git remote add origin $new_remote
                git push -u origin develop
                git checkout master
                git push -u origin master
                git checkout develop
            fi
            echo "Done!"
        else
            echo "Skipping setup."
        fi
    }
    
    function manage_plugins() {
        plugins=(
            "likert scale plugin"
            "Logging Plugin"
            "nDisplayExtensions"
            "NDisplay Launch Button"
            "UniversalLogging"
            "Unreal Cave Overlay"
            "Unreal-Study-Framework"
            "Unreal VA Plugin"
            "UnrealVisPlugin"
            "Widget Interaction Plugin"
        )
    
        plugin_repositories=(
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/likert-scale-plugin.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/logging-plugin.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/ndisplayextensions.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/NDisplayLaunchButton.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/universallogging.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/unreal-cave-overlay.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/unreal-study-framework.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/unreal-va-plugin.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/unrealvisplugin.git"
            "https://devhub.vr.rwth-aachen.de/VR-Group/unreal-development/widgetinteraction.git"
        )
    
        if [ "$1" == "initial_setup" ]
        then
            plugin_branches=(
                ""
                ""
                "master"
                ""
                ""
                "master"
                ""
                ""
                ""
                ""
            )
        else
            plugin_branches=(
                ""
                ""
                ""
                ""
                ""
                ""
                ""
                ""
                ""
                ""
            )
    
            
            for i in ${!plugins[@]}
            do
                repo_name_with_extension=${plugin_repositories[$i]##*/}
                repo_name=${repo_name_with_extension%*.git}
    
                path=$(git config -f .gitmodules --get "submodule.Plugins/${repo_name}.path")
                if [ $? == 0 ]
                then
                    branch=$(git config -f .gitmodules --get "submodule.Plugins/${repo_name}.branch")
                    if [ $? -ne 0 ]
                    then
                        plugin_branches[$i]="master"
                    else
                        plugin_branches[$i]="$branch"
                    fi
                fi
            done
        fi
    
        function toggle_branch() {
            case ${plugin_branches[$1]} in
                "") plugin_branches[$1]="master" ;;
                "master") plugin_branches[$1]="develop" ;;
                "develop") plugin_branches[$1]="" ;;
                *) >&2; plugin_branches[$1]="" ;;
            esac
        }
    
        selection=0
        exit=false
        cancel=false
        num_plugins_minus_one=${#plugins[@]}
        let num_plugins_minus_one-=1
    
        while [ $exit == "false" ]
        do
            clear
    
            echo "Select plugins to install:"
            echo ""
    
            for i in ${!plugins[@]}
            do
                if [ $i == $selection ]
                then
                    printf "\e[7m"
                fi
    
                if [ -z ${plugin_branches[$i]} ]
                then
                    echo " [ ] ${plugins[$i]}"
                else
                    echo " [X] ${plugins[$i]}: ${plugin_branches[$i]}"
                fi
    
                if [ $i == $selection ]
                then
                    printf "\e[0m"
                fi
            done
    
            
            echo ""
            echo "[Arrow Up/Down] Select Plugin"
            echo "[Space]         Toggle branch"
            echo "[Enter]         Continue"
            echo "[Esc]           Cancel"
    
            IFS=''
            escape_char=$(printf "\u1b")
            escape=false
            read -rsn1 mode # get 1 character
            if [[ $mode == $escape_char ]]; then
                escape=true
                read -rsn2 -t 0.1 mode # read 2 more chars
            fi
            case $mode in
                "") if [ "$escape" == true ]; then cancel=true; fi; exit=true ;;
                " ") toggle_branch $selection ;;
                "[A") if [ "$selection" -gt "0" ]; then let selection-=1; fi ;;
                "[B") if [ "$selection" -lt "$num_plugins_minus_one" ]; then let selection+=1; fi ;;
                *) >&2 ;;
            esac
        done
    
        if [ "$cancel" != true ]
        then
            clear
            mkdir -p Plugins
            cd Plugins
            echo "Adding/updating plugins..."
    
            for i in ${!plugins[@]}
            do
                # Check if plugin is already present
                repo_name_with_extension=${plugin_repositories[$i]##*/}
                repo_name=${repo_name_with_extension%*.git}
                path=$(git config -f .gitmodules --get "submodule.Plugins/${repo_name}.path")
                if [ $? -ne 0 ]
                then
                    plugin_present=true
                else
                    plugin_present=false
                fi
    
                if [ -n "${plugin_branches[$i]}" ]
                then
                    if [ "$plugin_present" == false ]
                    then
                        # Plugin was not yet added, call git submodule add
                        echo "Add new plugin: ${plugins[$i]}"
                        git submodule add -b ${plugin_branches[$i]} ${plugin_repositories[$i]}
                    else
                        # Updating existing plugin
                        echo "Update plugin: ${plugins[$i]}"
                        cd $repo_name
                        git fetch
                        git checkout ${plugin_branches[$i]}
                        git pull
                        cd ..
                    fi
                else
                    if [ "$plugin_present" == true ]
                    then
                        # Remove plugin!
                        git submodule deinit -f "$repo_name"
                        git rm -f "$repo_name"
    
                        git config -f ../.gitmodules --remove-section "submodule.Plugins/${repo_name}"
                        if [ -z "$(cat ../.gitmodules)" ]; then
                            git rm -f ../.gitmodules
                        fi
                    fi
                fi
            done
            cd ..
        fi
    }
    
    function show_main_menu() {
        selection=0
        exit=false
    
        while [ $exit = false ]
        do
            clear
    
            echo "Select Task:"
            echo ""
    
            items=("InitialSetup" "ManagePlugins" "Exit")
    
            for i in ${!items[@]}
            do
                if [ $i == $selection ]
                then
                    printf "\e[7m* "
                else
                    printf "  "
                fi
    
                echo "${items[$i]}"
    
                if [ $i == $selection ]
                then
                    printf "\e[0m"
                fi
            done
    
            echo ""
            echo "[Arrow Up/Down] Change Selection"
            echo "[Enter]         Select"
    
            IFS=''
            escape_char=$(printf "\u1b")
            read -rsn1 mode # get 1 character
            if [[ $mode == $escape_char ]]; then
                read -rsn2 mode # read 2 more chars
            fi
            case $mode in
                "") exit=true ;;
                "[A") if [ "$selection" -gt "0" ]; then let selection-=1; fi ;;
                "[B") if [ "$selection" -lt "3" ]; then let selection+=1; fi ;;
                *) >&2;;
            esac
        done
    
        case $selection in
            0) initial_setup; show_main_menu ;;
            1) manage_plugins; show_main_menu ;;
            2) ;;
            *) >&2;;
        esac
    }
    
    show_main_menu