diff --git a/setup.sh b/setup.sh index 10157c330823914d30336beaca46351f70d87d54..0ecb3364a57c93774ad93caf0104911fcff58389 100644 --- a/setup.sh +++ b/setup.sh @@ -1,57 +1,110 @@ #!/bin/sh -if [ ! -f "update.txt" ] -then - remote_branch=$(git rev-parse --abbrev-ref @{u}) +function initial_setup() { + clear - if [[ "$remote_branch" != "origin/"* ]] + 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 - echo "This script can only handle remotes named origin!" - exit -1 - fi + current_branch=$(git rev-parse --abbrev-ref HEAD) + branches_to_delete=$(git for-each-ref --format='%(refname:short)' refs/heads/) - remote_branch=${remote_branch#"origin/"} + for branch in $branches_to_delete + do + if [ "$branch" != "$current_branch" ] + then + git branch -d "$branch" + fi + done - repository_url=$(git remote get-url origin) - echo "$repository_url" + if [ "$current_branch" != "develop" ] + then + git checkout -b develop + git branch -d "$current_branch" + fi - echo "$repository_url" >> update.txt - echo "$remote_branch" >> update.txt -fi + + git add . + git commit -m "Initial commit" + git branch master -current_branch=$(git rev-parse --abbrev-ref HEAD) -branches_to_delete=$(git for-each-ref --format='%(refname:short)' refs/heads/) + 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 -for branch in $branches_to_delete -do - if [ "$branch" != "$current_branch" ] - then - git branch -d "$branch" + 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. Press enter to continue" + read temp fi -done - -if [ "$current_branch" != "develop" ] -then - git checkout -b develop - git branch -d "$current_branch" -fi - -git remote remove origin -git add . -git commit -m "Initial commit" -git branch master - -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!" \ No newline at end of file +} + +function manage_plugins() { + echo "Hello!" +} + +function show_main_menu() { + selection=0 + exit=false + + while [ $exit = false ] + do + clear + + echo "Select Task:" + echo "[Arrow Up/Down] Change Selection" + echo "[Enter] Select" + 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 + + 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 \ No newline at end of file