SHARE
TWEET

Untitled

a guest Apr 19th, 2019 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. clear
  4.  
  5. read -e -p $'\e[32mInstall docker? ("NO" by default):\e[0m ' INSTALL_DOCKER
  6.  
  7. if [ ! -z "$INSTALL_DOCKER" ]
  8. then
  9.     sudo apt update
  10.     echo -e "Installing \033[0;32docker.io\033[0m and \033[0;32mdocker-compose\033[0m"
  11.  
  12.     : '
  13.     Or use "sudo snap install docker" if Snappy installed
  14.  
  15.     For removing previouse version:
  16.     sudo apt purge \
  17.         docker.io \
  18.         docker-compose
  19.     OR
  20.     sudo snap remove docker
  21.     '
  22.  
  23.     sudo apt install \
  24.         docker.io \
  25.         docker-compose
  26.  
  27.     sudo groupadd docker
  28.     sudo usermod -aG docker $USER
  29.     sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
  30.     sudo chmod g+rwx "$HOME/.docker" -R
  31. fi
  32.  
  33. sudo cp icons8-docker.svg /usr/share/icons/hicolor/scalable/apps/
  34. echo -e "Copy \033[0;32micons8-docker.svg\033[0m to \033[0;32m/usr/share/icons/hicolor/scalable/apps\033[0m"
  35.  
  36. function join_by {
  37.     local IFS="$1"; shift; echo "$*";
  38. }
  39.  
  40. function select_shortcut_name {
  41.     case $(basename $1) in
  42.      "run.sh")      
  43.           SHORTCUT_NAME=$(sed 's|'$INSTALL_SCRIPT_DIR'||g; s|/run.sh||g; s|/|-|g;' <<< $RUN_SCRIPT_PATH)
  44.           ;;
  45.      "kill.sh")      
  46.           SHORTCUT_NAME=$(sed 's|'$INSTALL_SCRIPT_DIR'||g; s|/kill.sh|-kill|g; s|/|-|g;' <<< $RUN_SCRIPT_PATH)
  47.           ;;
  48.     esac
  49. }
  50.  
  51. function build_application_shortcuts {
  52.     while IFS=  read -r -d $'\0'; do
  53.         RUN_SCRIPT_PATH=$(realpath $REPLY)
  54.         SCRIPT_DIR=${RUN_SCRIPT_PATH%/*}
  55.         select_shortcut_name $RUN_SCRIPT_PATH
  56.        
  57.         ACTIONS_SCRIPTS=()
  58.         ACTIONS_NAMES=()
  59.        
  60.         while IFS=  read -r -d $'\0'; do
  61.             ACTIONS_SCRIPTS+=("$REPLY")
  62.             ACTIONS_NAMES+=($(echo "$REPLY" | sed -r "s/.+\/(.+)\..+/\1/"))
  63.         done < <(find $SCRIPT_DIR -maxdepth 1 -name "*.sh" -print0)
  64.        
  65.         ACTIONS=$(join_by \; "${ACTIONS_NAMES[@]};")
  66.         SHORTCUT="$(echo -e "$(sed 's|@1|'$SHORTCUT_NAME'|g; s|@2|'$RUN_SCRIPT_PATH'|g; s|@3|'$ACTIONS'|g;' <<< $SHORTCUT_ACTION_TEMPLATE)")\n"
  67.         for ((i=0;i<${#ACTIONS_NAMES[@]};++i)); do
  68.             SHORTCUT="${SHORTCUT}\n$(echo "$(sed 's|@1|'${ACTIONS_NAMES[i]}'|g; s|@2|'${ACTIONS_SCRIPTS[i]}'|g;' <<< $ACTION_TEMPLATE)")\n"
  69.         done
  70.         echo -e "$SHORTCUT" > "${APP_FOLDER}/${SHORTCUT_NAME}.desktop"
  71.         chmod +x ${APP_FOLDER}/${SHORTCUT_NAME}.desktop
  72.         echo -e "Created \033[0;32m${SHORTCUT_NAME}.desktop\033[0m shortcut in \033[0;32m${APP_FOLDER}\033[0m"
  73.     done < <(find $INSTALL_SCRIPT_DIR -regextype posix-egrep -regex ".*(${AVALIABLE_RUNNERS_REGEX})$" -print0)
  74. }
  75.  
  76. function build_desktop_shortcuts {
  77.     while IFS=  read -r -d $'\0'; do
  78.         RUN_SCRIPT_PATH=$(realpath $REPLY)
  79.         select_shortcut_name $RUN_SCRIPT_PATH
  80.         echo "$(sed 's|@1|'$SHORTCUT_NAME'|g; s|@2|'$RUN_SCRIPT_PATH'|g' <<< $SHORTCUT_TEMPLATE)" > "${DESK_FOLDER}/${SHORTCUT_NAME}.desktop"
  81.         chmod +x ${DESK_FOLDER}/${SHORTCUT_NAME}.desktop
  82.         echo -e "Created \033[0;32m${SHORTCUT_NAME}.desktop\033[0m shortcut in \033[0;32m${DESK_FOLDER}\033[0m"
  83.     done < <(find $INSTALL_SCRIPT_DIR -regextype posix-egrep -regex ".*(${AVALIABLE_RUNNERS_REGEX})$" -print0)
  84. }
  85.  
  86. echo -e "\033[0;32mSelect environment mode\033[0m"
  87.  
  88. ENV_MODES=("Application mode" "Desktop shortcuts mode")
  89. APP_FOLDER="${HOME}/.local/share/applications"
  90. DESK_FOLDER="${HOME}/Desktop"
  91.  
  92. select VALUE in "${ENV_MODES[@]}"
  93. do
  94.     case $VALUE in
  95.         "Application mode")
  96.             ENV_MODE=$VALUE
  97.             declare -a RUNNERS_NAMES=("run.sh")
  98.             break
  99.             ;;
  100.         "Desktop shortcuts mode")
  101.             ENV_MODE=$VALUE
  102.             read -e -p $'\e[32mGenerate kill shortcuts? ("YES" by default):\e[0m ' GENERATE_KILL_SHORTCUTS
  103.             if [ -z "$GENERATE_KILL_SHORTCUTS" ]
  104.             then
  105.                 declare -a RUNNERS_NAMES=("run.sh" "kill.sh")
  106.             else
  107.                 declare -a RUNNERS_NAMES=("run.sh")
  108.             fi
  109.             break
  110.             ;;
  111.         *) echo -e "\033[0;31mInvalid option $REPLY\033[0m";;
  112.     esac
  113. done
  114.  
  115. AVALIABLE_RUNNERS_REGEX=$(join_by \| "${RUNNERS_NAMES[@]}")
  116.  
  117. SHORTCUT_ACTION_TEMPLATE=$(cat <<-END
  118. [Desktop Entry]
  119. Version=1.0
  120. Type=Application
  121. Terminal=true
  122. Name[en_US]=@1
  123. Exec=@2
  124. Name=@1
  125. Icon=/usr/share/icons/hicolor/scalable/apps/icons8-docker.svg
  126.  
  127. Actions=@3
  128.  
  129. END
  130. )
  131.  
  132. SHORTCUT_TEMPLATE=$(cat <<-END
  133. [Desktop Entry]
  134. Version=1.0
  135. Type=Application
  136. Terminal=true
  137. Name[en_US]=@1
  138. Exec=@2
  139. Name=@1
  140. Icon=/usr/share/icons/hicolor/scalable/apps/icons8-docker.svg
  141. END
  142. )
  143.  
  144. ACTION_TEMPLATE=$(cat <<-END
  145. [Desktop Action @1]
  146. Exec=@2
  147. Name=@1
  148. Terminal=true
  149.  
  150. END
  151. )
  152.  
  153. INSTALL_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/"
  154.  
  155. if [ "$ENV_MODE" = "Application mode" ]
  156. then
  157.     build_application_shortcuts
  158. elif [ "$ENV_MODE" = "Desktop shortcuts mode" ]
  159. then
  160.     build_desktop_shortcuts
  161. fi
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top