Simple bash script creates apache2 virtualhost config for subdomainIs this shell script for copying files...

Can an insurance company drop you after receiving a bill and refusing to pay?

Can we use the stored gravitational potential energy of a building to produce power?

Citing paywalled articles accessed via illegal web sharing

Can a hotel cancel a confirmed reservation?

Is it a fallacy if someone claims they need an explanation for every word of your argument to the point where they don't understand common terms?

Explain the objections to these measures against human trafficking

figures in a grid with multiple line of texts

What to do when being responsible for data protection in your lab, yet advice is ignored?

What kind of hardware implements Fourier transform?

How would one buy a used TIE Fighter or X-Wing?

Adding a new switch to a C9300 stack

Contest math problem about crossing out numbers in the table

Program that converts a number to a letter of the alphabet

Caruana vs Carlsen game 10 (WCC) why not 18...Nxb6?

Every character has a name - does this lead to too many named characters?

What is the wife of a henpecked husband called?

Why did other German political parties disband so fast when Hitler was appointed chancellor?

Does fast page mode apply to ROM?

Broken patches on a road

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Can you earn endless XP using a Flameskull and its self-revival feature?

Slow moving projectiles from a hand-held weapon - how do they reach the target?

Why did this image turn out darker?

How to apply float precision (type specifier) in a conditional f-string?



Simple bash script creates apache2 virtualhost config for subdomain


Is this shell script for copying files sensible, readable?bash script for printer administrationUpdating an Nginx config file for SSLSimple Bash log backup scriptSublime Text 2 R Build System (source file, send selection to interactive session)Raspberry Pi headless server using bash and USB automountingBackup MySQL database for Django projectsNginx-WordPress installer for DebianRead integers from text file and write to CSV fileScript to clean up old files that should only run one instance













5












$begingroup$


Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost".



Tested on Ubuntu, but should work where dependency met.



Not for production, for development purposes only.



Use zenity for gui and pkexec for root permissions, so can be run without terminal, however some terminal output persist.



/etc/hosts file looks like: (so allowing add any subdomain)



127.0.0.1 localhost *.localhost


Note the wildcard, script doesn't create domains.



I'm not very experienced at bash scripting. Review and improve security, compatibility, maybe also some features with domains.



It's also on GitHub:(Updated) https://github.com/LeonidMew/CreateVirtualHost



#!/bin/bash

WEBROOT="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
APACHEHOST="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
A2ENSITE="050-" # short prefix for virtualhost config file
TMPHOST="/tmp/a2host-" # tmp prefix for virtualhost config while editing or rejecting

if ((`which zenity|wc -w` == 0)) # check dependency
then
echo "Error: zenity not installed."
exit
fi

if [ "$USER" == "root" ]
then
zenity --error --text="You should not run this script as root but as user going to edit web files."
exit
fi

HOST=`zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)'`
words=$( wc -w <<<"$HOST" )

if (($words == "0" || $words > 1)) # this not check for fully qualified sub domain name. ".localhost" added
then
zenity --error --text="More then one word for sub domain or empty"
exit
fi

HOSTFILE="$APACHEHOST$HOST"
HOSTFILE=$HOSTFILE".conf" # apache virtualhost config file
DIR="$WEBROOT$HOST" # folder used as document root for virtualhost

# virtualhost template
cat >$TMPHOST$HOST <<EOF
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot $DIR
ServerName $HOST.localhost
ServerAlias $HOST.localhost
<Directory "$DIR">
AllowOverride All
Require local
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
LogLevel warn
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
EOF

# edit virtualhost config
TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
words=$( wc -w <<<"$TEXT" )
if (($words == 0))
then
echo "Cancel"
rm $TMPHOST$HOST
exit
fi
echo "$TEXT" > $TMPHOST$HOST

A2ENSITE=$A2A2ENSITE$HOST".conf" # params for a2ensite

echo "execute root tools with pkexec to create virtualhost"
[ -d "$DIR" ] || mkdir -p "$DIR"
pkexec /bin/bash <<EOF
chgrp www-data "$DIR"
chmod u=rwX,g=rX,o= "$DIR"
mv $TMPHOST$HOST $HOSTFILE
chown root:root $HOSTFILE
chmod u=rw,g=r,o=r $HOSTFILE
a2ensite $A2ENSITE
EOF









share|improve this question









New contributor




LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$

















    5












    $begingroup$


    Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost".



    Tested on Ubuntu, but should work where dependency met.



    Not for production, for development purposes only.



    Use zenity for gui and pkexec for root permissions, so can be run without terminal, however some terminal output persist.



    /etc/hosts file looks like: (so allowing add any subdomain)



    127.0.0.1 localhost *.localhost


    Note the wildcard, script doesn't create domains.



    I'm not very experienced at bash scripting. Review and improve security, compatibility, maybe also some features with domains.



    It's also on GitHub:(Updated) https://github.com/LeonidMew/CreateVirtualHost



    #!/bin/bash

    WEBROOT="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
    APACHEHOST="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
    A2ENSITE="050-" # short prefix for virtualhost config file
    TMPHOST="/tmp/a2host-" # tmp prefix for virtualhost config while editing or rejecting

    if ((`which zenity|wc -w` == 0)) # check dependency
    then
    echo "Error: zenity not installed."
    exit
    fi

    if [ "$USER" == "root" ]
    then
    zenity --error --text="You should not run this script as root but as user going to edit web files."
    exit
    fi

    HOST=`zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)'`
    words=$( wc -w <<<"$HOST" )

    if (($words == "0" || $words > 1)) # this not check for fully qualified sub domain name. ".localhost" added
    then
    zenity --error --text="More then one word for sub domain or empty"
    exit
    fi

    HOSTFILE="$APACHEHOST$HOST"
    HOSTFILE=$HOSTFILE".conf" # apache virtualhost config file
    DIR="$WEBROOT$HOST" # folder used as document root for virtualhost

    # virtualhost template
    cat >$TMPHOST$HOST <<EOF
    <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot $DIR
    ServerName $HOST.localhost
    ServerAlias $HOST.localhost
    <Directory "$DIR">
    AllowOverride All
    Require local
    </Directory>
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    LogLevel warn
    </VirtualHost>
    # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
    EOF

    # edit virtualhost config
    TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
    words=$( wc -w <<<"$TEXT" )
    if (($words == 0))
    then
    echo "Cancel"
    rm $TMPHOST$HOST
    exit
    fi
    echo "$TEXT" > $TMPHOST$HOST

    A2ENSITE=$A2A2ENSITE$HOST".conf" # params for a2ensite

    echo "execute root tools with pkexec to create virtualhost"
    [ -d "$DIR" ] || mkdir -p "$DIR"
    pkexec /bin/bash <<EOF
    chgrp www-data "$DIR"
    chmod u=rwX,g=rX,o= "$DIR"
    mv $TMPHOST$HOST $HOSTFILE
    chown root:root $HOSTFILE
    chmod u=rw,g=r,o=r $HOSTFILE
    a2ensite $A2ENSITE
    EOF









    share|improve this question









    New contributor




    LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      5












      5








      5





      $begingroup$


      Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost".



      Tested on Ubuntu, but should work where dependency met.



      Not for production, for development purposes only.



      Use zenity for gui and pkexec for root permissions, so can be run without terminal, however some terminal output persist.



      /etc/hosts file looks like: (so allowing add any subdomain)



      127.0.0.1 localhost *.localhost


      Note the wildcard, script doesn't create domains.



      I'm not very experienced at bash scripting. Review and improve security, compatibility, maybe also some features with domains.



      It's also on GitHub:(Updated) https://github.com/LeonidMew/CreateVirtualHost



      #!/bin/bash

      WEBROOT="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
      APACHEHOST="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
      A2ENSITE="050-" # short prefix for virtualhost config file
      TMPHOST="/tmp/a2host-" # tmp prefix for virtualhost config while editing or rejecting

      if ((`which zenity|wc -w` == 0)) # check dependency
      then
      echo "Error: zenity not installed."
      exit
      fi

      if [ "$USER" == "root" ]
      then
      zenity --error --text="You should not run this script as root but as user going to edit web files."
      exit
      fi

      HOST=`zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)'`
      words=$( wc -w <<<"$HOST" )

      if (($words == "0" || $words > 1)) # this not check for fully qualified sub domain name. ".localhost" added
      then
      zenity --error --text="More then one word for sub domain or empty"
      exit
      fi

      HOSTFILE="$APACHEHOST$HOST"
      HOSTFILE=$HOSTFILE".conf" # apache virtualhost config file
      DIR="$WEBROOT$HOST" # folder used as document root for virtualhost

      # virtualhost template
      cat >$TMPHOST$HOST <<EOF
      <VirtualHost *:80>
      ServerAdmin webmaster@localhost
      DocumentRoot $DIR
      ServerName $HOST.localhost
      ServerAlias $HOST.localhost
      <Directory "$DIR">
      AllowOverride All
      Require local
      </Directory>
      # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
      # error, crit, alert, emerg.
      LogLevel warn
      </VirtualHost>
      # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
      EOF

      # edit virtualhost config
      TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
      words=$( wc -w <<<"$TEXT" )
      if (($words == 0))
      then
      echo "Cancel"
      rm $TMPHOST$HOST
      exit
      fi
      echo "$TEXT" > $TMPHOST$HOST

      A2ENSITE=$A2A2ENSITE$HOST".conf" # params for a2ensite

      echo "execute root tools with pkexec to create virtualhost"
      [ -d "$DIR" ] || mkdir -p "$DIR"
      pkexec /bin/bash <<EOF
      chgrp www-data "$DIR"
      chmod u=rwX,g=rX,o= "$DIR"
      mv $TMPHOST$HOST $HOSTFILE
      chown root:root $HOSTFILE
      chmod u=rw,g=r,o=r $HOSTFILE
      a2ensite $A2ENSITE
      EOF









      share|improve this question









      New contributor




      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost".



      Tested on Ubuntu, but should work where dependency met.



      Not for production, for development purposes only.



      Use zenity for gui and pkexec for root permissions, so can be run without terminal, however some terminal output persist.



      /etc/hosts file looks like: (so allowing add any subdomain)



      127.0.0.1 localhost *.localhost


      Note the wildcard, script doesn't create domains.



      I'm not very experienced at bash scripting. Review and improve security, compatibility, maybe also some features with domains.



      It's also on GitHub:(Updated) https://github.com/LeonidMew/CreateVirtualHost



      #!/bin/bash

      WEBROOT="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
      APACHEHOST="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
      A2ENSITE="050-" # short prefix for virtualhost config file
      TMPHOST="/tmp/a2host-" # tmp prefix for virtualhost config while editing or rejecting

      if ((`which zenity|wc -w` == 0)) # check dependency
      then
      echo "Error: zenity not installed."
      exit
      fi

      if [ "$USER" == "root" ]
      then
      zenity --error --text="You should not run this script as root but as user going to edit web files."
      exit
      fi

      HOST=`zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)'`
      words=$( wc -w <<<"$HOST" )

      if (($words == "0" || $words > 1)) # this not check for fully qualified sub domain name. ".localhost" added
      then
      zenity --error --text="More then one word for sub domain or empty"
      exit
      fi

      HOSTFILE="$APACHEHOST$HOST"
      HOSTFILE=$HOSTFILE".conf" # apache virtualhost config file
      DIR="$WEBROOT$HOST" # folder used as document root for virtualhost

      # virtualhost template
      cat >$TMPHOST$HOST <<EOF
      <VirtualHost *:80>
      ServerAdmin webmaster@localhost
      DocumentRoot $DIR
      ServerName $HOST.localhost
      ServerAlias $HOST.localhost
      <Directory "$DIR">
      AllowOverride All
      Require local
      </Directory>
      # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
      # error, crit, alert, emerg.
      LogLevel warn
      </VirtualHost>
      # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
      EOF

      # edit virtualhost config
      TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
      words=$( wc -w <<<"$TEXT" )
      if (($words == 0))
      then
      echo "Cancel"
      rm $TMPHOST$HOST
      exit
      fi
      echo "$TEXT" > $TMPHOST$HOST

      A2ENSITE=$A2A2ENSITE$HOST".conf" # params for a2ensite

      echo "execute root tools with pkexec to create virtualhost"
      [ -d "$DIR" ] || mkdir -p "$DIR"
      pkexec /bin/bash <<EOF
      chgrp www-data "$DIR"
      chmod u=rwX,g=rX,o= "$DIR"
      mv $TMPHOST$HOST $HOSTFILE
      chown root:root $HOSTFILE
      chmod u=rw,g=r,o=r $HOSTFILE
      a2ensite $A2ENSITE
      EOF






      security bash template configuration






      share|improve this question









      New contributor




      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 21 hours ago







      LeonidMew













      New contributor




      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      LeonidMewLeonidMew

      1286




      1286




      New contributor




      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      LeonidMew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          4












          $begingroup$

          Notes:




          • Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells

          • Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH.


          • A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere


            • this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard to read.



          • For Command Substitution, don't use backticks, use $( ... ). That syntax is (IMO) easier to read, and there are other advantages, such as nestability.


          • if ((`which zenity|wc -w` == 0)) -- use the bash builtin type command to see if there is a zenity command available: type -p zenity will return an unsuccessful exit status if there's no zenity in your path:



            if ! type -p zenity >/dev/null


            Although I don't really see the need for zenity. It would be super frustrating for the user who doesn't have it, being prevented from using your script. And the technical user who would be comfortable installing it is the type of user who doesn't need the bells and whistles, IMO.




          • To check if a string is empty, you don't need to call out to wc.



            Not this:



            TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
            words=$( wc -w <<<"$TEXT" )
            if (($words == 0))


            but this:



            text=$(zenity --text-info --filename="$filename" --editable)
            if [ -z "$text" ] # cancel if empty



          • use mktemp for temp files



            tmphost=$(mktemp)


            And just use "$tmphost" instead of $TMPHOST$HOST




          • you can tell bash to automatically delete the temp file when it exits:



            trap "rm $tmphost" EXIT



          • validate user input for host: a case statement might make sense here:



            host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
            case "$host" in
            "") zenity --error --text="Bad input: empty"; exit 1 ;;
            *"*"*) zenity --error --text="Bad input: wildcard"; exit 1 ;;
            *[[:space:]]*) zenity --error --text="Bad input: whitespace"; exit 1 ;;
            esac


          • I applaud your use of here-documents


          • use if [ "$(id -un)" = "root" ] instead of the USER variable.


          • mkdir -p silently does nothing if the directory already exists, so you don't need to test -d


          Perhaps you want this:



          #!/bin/bash

          webroot="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
          apachehost="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
          a2ensite="050-" # short prefix for virtualhost config file
          tmphost=$(mktemp)
          trap "rm $tmphost" EXIT

          if [ "$USER" == "root" ]
          then
          echo "You should not run this script as root but as user going to edit web files." >&2
          exit 1
          fi

          read -p"Create virtualhost (= Folder name,case sensitive)" -r host
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac

          # braces only for readability
          hostfile="${apachehost}${host}.conf" # apache virtualhost config file
          dir="${webroot}${host}" # folder used as document root for virtualhost

          # virtualhost template
          cat >"$tmphost" <<EOF
          <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          DocumentRoot $dir
          ServerName $host.localhost
          ServerAlias $host.localhost
          <Directory "$dir">
          AllowOverride All
          Require local
          </Directory>
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          LogLevel warn
          </VirtualHost>
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          EOF

          # edit virtualhost config
          editor=${VISUAL:-$EDITOR}
          if [ -z "$editor" ]
          then
          echo "edit '$tmphost' to your liking, then hit Enter"
          read -p "I'll wait ... "
          else
          "$editor" "$tmphost"
          fi
          # probably want some validating here that the user has not broken the config

          echo "execute root tools with pkexec to create virtualhost"
          mkdir -p "$dir"

          pkexec /bin/bash <<EOF
          chgrp www-data "$dir"
          chmod u=rwX,g=rX,o= "$dir"
          mv "$tmphost" "$hostfile"
          chown root:root "$hostfile"
          chmod u=rw,g=r,o=r "$hostfile"
          a2ensite "${a2ensite}${host}.conf"
          EOF




          Responding to your questions:





          1. "determine if running in a terminal?" Yes with this obscure test:



            if [ -t 0 ]; then echo "in a terminal"; fi


            That tests file descriptor 0, which is stdin. If you're launching your script as a GUI, that test should be false.



          2. editor=${VISUAL:-$EDITOR} sets the editor variable to the user's $VISUAL variable, or if that's not set, to the $EDITOR variable. Many programs use this to determine the user's preferred "terminal" editor. vim and emacs are two common values there. If neither of those are set, then the user gets to go edit that however he chooses.


          3. "is read terminal only?" Yes



          If you're going to aim for GUI and text versions, I'd use one script, but make sure all the common code is put into functions so you don't have to duplicate your code. For example:



          get_virtual_host() {
          if [ -t 0 ]; then
          read -p "Create virtualhost (= Folder name,case sensitive)" -r host
          else
          host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
          fi
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac
          echo "$host"
          }

          host=$(get_virtual_host)





          share|improve this answer











          $endgroup$













          • $begingroup$
            Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
            $endgroup$
            – LeonidMew
            yesterday










          • $begingroup$
            Merged and updated version in git. If you may look over it - I can add another question.
            $endgroup$
            – LeonidMew
            21 hours ago











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          LeonidMew is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214489%2fsimple-bash-script-creates-apache2-virtualhost-config-for-subdomain%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4












          $begingroup$

          Notes:




          • Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells

          • Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH.


          • A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere


            • this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard to read.



          • For Command Substitution, don't use backticks, use $( ... ). That syntax is (IMO) easier to read, and there are other advantages, such as nestability.


          • if ((`which zenity|wc -w` == 0)) -- use the bash builtin type command to see if there is a zenity command available: type -p zenity will return an unsuccessful exit status if there's no zenity in your path:



            if ! type -p zenity >/dev/null


            Although I don't really see the need for zenity. It would be super frustrating for the user who doesn't have it, being prevented from using your script. And the technical user who would be comfortable installing it is the type of user who doesn't need the bells and whistles, IMO.




          • To check if a string is empty, you don't need to call out to wc.



            Not this:



            TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
            words=$( wc -w <<<"$TEXT" )
            if (($words == 0))


            but this:



            text=$(zenity --text-info --filename="$filename" --editable)
            if [ -z "$text" ] # cancel if empty



          • use mktemp for temp files



            tmphost=$(mktemp)


            And just use "$tmphost" instead of $TMPHOST$HOST




          • you can tell bash to automatically delete the temp file when it exits:



            trap "rm $tmphost" EXIT



          • validate user input for host: a case statement might make sense here:



            host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
            case "$host" in
            "") zenity --error --text="Bad input: empty"; exit 1 ;;
            *"*"*) zenity --error --text="Bad input: wildcard"; exit 1 ;;
            *[[:space:]]*) zenity --error --text="Bad input: whitespace"; exit 1 ;;
            esac


          • I applaud your use of here-documents


          • use if [ "$(id -un)" = "root" ] instead of the USER variable.


          • mkdir -p silently does nothing if the directory already exists, so you don't need to test -d


          Perhaps you want this:



          #!/bin/bash

          webroot="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
          apachehost="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
          a2ensite="050-" # short prefix for virtualhost config file
          tmphost=$(mktemp)
          trap "rm $tmphost" EXIT

          if [ "$USER" == "root" ]
          then
          echo "You should not run this script as root but as user going to edit web files." >&2
          exit 1
          fi

          read -p"Create virtualhost (= Folder name,case sensitive)" -r host
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac

          # braces only for readability
          hostfile="${apachehost}${host}.conf" # apache virtualhost config file
          dir="${webroot}${host}" # folder used as document root for virtualhost

          # virtualhost template
          cat >"$tmphost" <<EOF
          <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          DocumentRoot $dir
          ServerName $host.localhost
          ServerAlias $host.localhost
          <Directory "$dir">
          AllowOverride All
          Require local
          </Directory>
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          LogLevel warn
          </VirtualHost>
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          EOF

          # edit virtualhost config
          editor=${VISUAL:-$EDITOR}
          if [ -z "$editor" ]
          then
          echo "edit '$tmphost' to your liking, then hit Enter"
          read -p "I'll wait ... "
          else
          "$editor" "$tmphost"
          fi
          # probably want some validating here that the user has not broken the config

          echo "execute root tools with pkexec to create virtualhost"
          mkdir -p "$dir"

          pkexec /bin/bash <<EOF
          chgrp www-data "$dir"
          chmod u=rwX,g=rX,o= "$dir"
          mv "$tmphost" "$hostfile"
          chown root:root "$hostfile"
          chmod u=rw,g=r,o=r "$hostfile"
          a2ensite "${a2ensite}${host}.conf"
          EOF




          Responding to your questions:





          1. "determine if running in a terminal?" Yes with this obscure test:



            if [ -t 0 ]; then echo "in a terminal"; fi


            That tests file descriptor 0, which is stdin. If you're launching your script as a GUI, that test should be false.



          2. editor=${VISUAL:-$EDITOR} sets the editor variable to the user's $VISUAL variable, or if that's not set, to the $EDITOR variable. Many programs use this to determine the user's preferred "terminal" editor. vim and emacs are two common values there. If neither of those are set, then the user gets to go edit that however he chooses.


          3. "is read terminal only?" Yes



          If you're going to aim for GUI and text versions, I'd use one script, but make sure all the common code is put into functions so you don't have to duplicate your code. For example:



          get_virtual_host() {
          if [ -t 0 ]; then
          read -p "Create virtualhost (= Folder name,case sensitive)" -r host
          else
          host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
          fi
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac
          echo "$host"
          }

          host=$(get_virtual_host)





          share|improve this answer











          $endgroup$













          • $begingroup$
            Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
            $endgroup$
            – LeonidMew
            yesterday










          • $begingroup$
            Merged and updated version in git. If you may look over it - I can add another question.
            $endgroup$
            – LeonidMew
            21 hours ago
















          4












          $begingroup$

          Notes:




          • Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells

          • Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH.


          • A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere


            • this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard to read.



          • For Command Substitution, don't use backticks, use $( ... ). That syntax is (IMO) easier to read, and there are other advantages, such as nestability.


          • if ((`which zenity|wc -w` == 0)) -- use the bash builtin type command to see if there is a zenity command available: type -p zenity will return an unsuccessful exit status if there's no zenity in your path:



            if ! type -p zenity >/dev/null


            Although I don't really see the need for zenity. It would be super frustrating for the user who doesn't have it, being prevented from using your script. And the technical user who would be comfortable installing it is the type of user who doesn't need the bells and whistles, IMO.




          • To check if a string is empty, you don't need to call out to wc.



            Not this:



            TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
            words=$( wc -w <<<"$TEXT" )
            if (($words == 0))


            but this:



            text=$(zenity --text-info --filename="$filename" --editable)
            if [ -z "$text" ] # cancel if empty



          • use mktemp for temp files



            tmphost=$(mktemp)


            And just use "$tmphost" instead of $TMPHOST$HOST




          • you can tell bash to automatically delete the temp file when it exits:



            trap "rm $tmphost" EXIT



          • validate user input for host: a case statement might make sense here:



            host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
            case "$host" in
            "") zenity --error --text="Bad input: empty"; exit 1 ;;
            *"*"*) zenity --error --text="Bad input: wildcard"; exit 1 ;;
            *[[:space:]]*) zenity --error --text="Bad input: whitespace"; exit 1 ;;
            esac


          • I applaud your use of here-documents


          • use if [ "$(id -un)" = "root" ] instead of the USER variable.


          • mkdir -p silently does nothing if the directory already exists, so you don't need to test -d


          Perhaps you want this:



          #!/bin/bash

          webroot="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
          apachehost="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
          a2ensite="050-" # short prefix for virtualhost config file
          tmphost=$(mktemp)
          trap "rm $tmphost" EXIT

          if [ "$USER" == "root" ]
          then
          echo "You should not run this script as root but as user going to edit web files." >&2
          exit 1
          fi

          read -p"Create virtualhost (= Folder name,case sensitive)" -r host
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac

          # braces only for readability
          hostfile="${apachehost}${host}.conf" # apache virtualhost config file
          dir="${webroot}${host}" # folder used as document root for virtualhost

          # virtualhost template
          cat >"$tmphost" <<EOF
          <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          DocumentRoot $dir
          ServerName $host.localhost
          ServerAlias $host.localhost
          <Directory "$dir">
          AllowOverride All
          Require local
          </Directory>
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          LogLevel warn
          </VirtualHost>
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          EOF

          # edit virtualhost config
          editor=${VISUAL:-$EDITOR}
          if [ -z "$editor" ]
          then
          echo "edit '$tmphost' to your liking, then hit Enter"
          read -p "I'll wait ... "
          else
          "$editor" "$tmphost"
          fi
          # probably want some validating here that the user has not broken the config

          echo "execute root tools with pkexec to create virtualhost"
          mkdir -p "$dir"

          pkexec /bin/bash <<EOF
          chgrp www-data "$dir"
          chmod u=rwX,g=rX,o= "$dir"
          mv "$tmphost" "$hostfile"
          chown root:root "$hostfile"
          chmod u=rw,g=r,o=r "$hostfile"
          a2ensite "${a2ensite}${host}.conf"
          EOF




          Responding to your questions:





          1. "determine if running in a terminal?" Yes with this obscure test:



            if [ -t 0 ]; then echo "in a terminal"; fi


            That tests file descriptor 0, which is stdin. If you're launching your script as a GUI, that test should be false.



          2. editor=${VISUAL:-$EDITOR} sets the editor variable to the user's $VISUAL variable, or if that's not set, to the $EDITOR variable. Many programs use this to determine the user's preferred "terminal" editor. vim and emacs are two common values there. If neither of those are set, then the user gets to go edit that however he chooses.


          3. "is read terminal only?" Yes



          If you're going to aim for GUI and text versions, I'd use one script, but make sure all the common code is put into functions so you don't have to duplicate your code. For example:



          get_virtual_host() {
          if [ -t 0 ]; then
          read -p "Create virtualhost (= Folder name,case sensitive)" -r host
          else
          host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
          fi
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac
          echo "$host"
          }

          host=$(get_virtual_host)





          share|improve this answer











          $endgroup$













          • $begingroup$
            Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
            $endgroup$
            – LeonidMew
            yesterday










          • $begingroup$
            Merged and updated version in git. If you may look over it - I can add another question.
            $endgroup$
            – LeonidMew
            21 hours ago














          4












          4








          4





          $begingroup$

          Notes:




          • Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells

          • Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH.


          • A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere


            • this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard to read.



          • For Command Substitution, don't use backticks, use $( ... ). That syntax is (IMO) easier to read, and there are other advantages, such as nestability.


          • if ((`which zenity|wc -w` == 0)) -- use the bash builtin type command to see if there is a zenity command available: type -p zenity will return an unsuccessful exit status if there's no zenity in your path:



            if ! type -p zenity >/dev/null


            Although I don't really see the need for zenity. It would be super frustrating for the user who doesn't have it, being prevented from using your script. And the technical user who would be comfortable installing it is the type of user who doesn't need the bells and whistles, IMO.




          • To check if a string is empty, you don't need to call out to wc.



            Not this:



            TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
            words=$( wc -w <<<"$TEXT" )
            if (($words == 0))


            but this:



            text=$(zenity --text-info --filename="$filename" --editable)
            if [ -z "$text" ] # cancel if empty



          • use mktemp for temp files



            tmphost=$(mktemp)


            And just use "$tmphost" instead of $TMPHOST$HOST




          • you can tell bash to automatically delete the temp file when it exits:



            trap "rm $tmphost" EXIT



          • validate user input for host: a case statement might make sense here:



            host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
            case "$host" in
            "") zenity --error --text="Bad input: empty"; exit 1 ;;
            *"*"*) zenity --error --text="Bad input: wildcard"; exit 1 ;;
            *[[:space:]]*) zenity --error --text="Bad input: whitespace"; exit 1 ;;
            esac


          • I applaud your use of here-documents


          • use if [ "$(id -un)" = "root" ] instead of the USER variable.


          • mkdir -p silently does nothing if the directory already exists, so you don't need to test -d


          Perhaps you want this:



          #!/bin/bash

          webroot="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
          apachehost="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
          a2ensite="050-" # short prefix for virtualhost config file
          tmphost=$(mktemp)
          trap "rm $tmphost" EXIT

          if [ "$USER" == "root" ]
          then
          echo "You should not run this script as root but as user going to edit web files." >&2
          exit 1
          fi

          read -p"Create virtualhost (= Folder name,case sensitive)" -r host
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac

          # braces only for readability
          hostfile="${apachehost}${host}.conf" # apache virtualhost config file
          dir="${webroot}${host}" # folder used as document root for virtualhost

          # virtualhost template
          cat >"$tmphost" <<EOF
          <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          DocumentRoot $dir
          ServerName $host.localhost
          ServerAlias $host.localhost
          <Directory "$dir">
          AllowOverride All
          Require local
          </Directory>
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          LogLevel warn
          </VirtualHost>
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          EOF

          # edit virtualhost config
          editor=${VISUAL:-$EDITOR}
          if [ -z "$editor" ]
          then
          echo "edit '$tmphost' to your liking, then hit Enter"
          read -p "I'll wait ... "
          else
          "$editor" "$tmphost"
          fi
          # probably want some validating here that the user has not broken the config

          echo "execute root tools with pkexec to create virtualhost"
          mkdir -p "$dir"

          pkexec /bin/bash <<EOF
          chgrp www-data "$dir"
          chmod u=rwX,g=rX,o= "$dir"
          mv "$tmphost" "$hostfile"
          chown root:root "$hostfile"
          chmod u=rw,g=r,o=r "$hostfile"
          a2ensite "${a2ensite}${host}.conf"
          EOF




          Responding to your questions:





          1. "determine if running in a terminal?" Yes with this obscure test:



            if [ -t 0 ]; then echo "in a terminal"; fi


            That tests file descriptor 0, which is stdin. If you're launching your script as a GUI, that test should be false.



          2. editor=${VISUAL:-$EDITOR} sets the editor variable to the user's $VISUAL variable, or if that's not set, to the $EDITOR variable. Many programs use this to determine the user's preferred "terminal" editor. vim and emacs are two common values there. If neither of those are set, then the user gets to go edit that however he chooses.


          3. "is read terminal only?" Yes



          If you're going to aim for GUI and text versions, I'd use one script, but make sure all the common code is put into functions so you don't have to duplicate your code. For example:



          get_virtual_host() {
          if [ -t 0 ]; then
          read -p "Create virtualhost (= Folder name,case sensitive)" -r host
          else
          host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
          fi
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac
          echo "$host"
          }

          host=$(get_virtual_host)





          share|improve this answer











          $endgroup$



          Notes:




          • Quote your variables. Ref Security implications of forgetting to quote a variable in bash/POSIX shells

          • Don't use ALLCAPS varnames. It's too easy to overwrite important shell variables like PATH.


          • A2ENSITE=$A2A2ENSITE$HOST".conf" -- I don't see the A2A2ENSITE variable anywhere


            • this is a perhaps a corollary of the ALLCAPS vars problem: they can be hard to read.



          • For Command Substitution, don't use backticks, use $( ... ). That syntax is (IMO) easier to read, and there are other advantages, such as nestability.


          • if ((`which zenity|wc -w` == 0)) -- use the bash builtin type command to see if there is a zenity command available: type -p zenity will return an unsuccessful exit status if there's no zenity in your path:



            if ! type -p zenity >/dev/null


            Although I don't really see the need for zenity. It would be super frustrating for the user who doesn't have it, being prevented from using your script. And the technical user who would be comfortable installing it is the type of user who doesn't need the bells and whistles, IMO.




          • To check if a string is empty, you don't need to call out to wc.



            Not this:



            TEXT=`zenity --text-info --filename=$TMPHOST$HOST --editable`
            words=$( wc -w <<<"$TEXT" )
            if (($words == 0))


            but this:



            text=$(zenity --text-info --filename="$filename" --editable)
            if [ -z "$text" ] # cancel if empty



          • use mktemp for temp files



            tmphost=$(mktemp)


            And just use "$tmphost" instead of $TMPHOST$HOST




          • you can tell bash to automatically delete the temp file when it exits:



            trap "rm $tmphost" EXIT



          • validate user input for host: a case statement might make sense here:



            host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
            case "$host" in
            "") zenity --error --text="Bad input: empty"; exit 1 ;;
            *"*"*) zenity --error --text="Bad input: wildcard"; exit 1 ;;
            *[[:space:]]*) zenity --error --text="Bad input: whitespace"; exit 1 ;;
            esac


          • I applaud your use of here-documents


          • use if [ "$(id -un)" = "root" ] instead of the USER variable.


          • mkdir -p silently does nothing if the directory already exists, so you don't need to test -d


          Perhaps you want this:



          #!/bin/bash

          webroot="/home/leonid/Web/" # root folder where subfolders for virtualhosts created
          apachehost="/etc/apache2/sites-available/050-" # prefix for virtualhost config file
          a2ensite="050-" # short prefix for virtualhost config file
          tmphost=$(mktemp)
          trap "rm $tmphost" EXIT

          if [ "$USER" == "root" ]
          then
          echo "You should not run this script as root but as user going to edit web files." >&2
          exit 1
          fi

          read -p"Create virtualhost (= Folder name,case sensitive)" -r host
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac

          # braces only for readability
          hostfile="${apachehost}${host}.conf" # apache virtualhost config file
          dir="${webroot}${host}" # folder used as document root for virtualhost

          # virtualhost template
          cat >"$tmphost" <<EOF
          <VirtualHost *:80>
          ServerAdmin webmaster@localhost
          DocumentRoot $dir
          ServerName $host.localhost
          ServerAlias $host.localhost
          <Directory "$dir">
          AllowOverride All
          Require local
          </Directory>
          # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
          # error, crit, alert, emerg.
          LogLevel warn
          </VirtualHost>
          # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
          EOF

          # edit virtualhost config
          editor=${VISUAL:-$EDITOR}
          if [ -z "$editor" ]
          then
          echo "edit '$tmphost' to your liking, then hit Enter"
          read -p "I'll wait ... "
          else
          "$editor" "$tmphost"
          fi
          # probably want some validating here that the user has not broken the config

          echo "execute root tools with pkexec to create virtualhost"
          mkdir -p "$dir"

          pkexec /bin/bash <<EOF
          chgrp www-data "$dir"
          chmod u=rwX,g=rX,o= "$dir"
          mv "$tmphost" "$hostfile"
          chown root:root "$hostfile"
          chmod u=rw,g=r,o=r "$hostfile"
          a2ensite "${a2ensite}${host}.conf"
          EOF




          Responding to your questions:





          1. "determine if running in a terminal?" Yes with this obscure test:



            if [ -t 0 ]; then echo "in a terminal"; fi


            That tests file descriptor 0, which is stdin. If you're launching your script as a GUI, that test should be false.



          2. editor=${VISUAL:-$EDITOR} sets the editor variable to the user's $VISUAL variable, or if that's not set, to the $EDITOR variable. Many programs use this to determine the user's preferred "terminal" editor. vim and emacs are two common values there. If neither of those are set, then the user gets to go edit that however he chooses.


          3. "is read terminal only?" Yes



          If you're going to aim for GUI and text versions, I'd use one script, but make sure all the common code is put into functions so you don't have to duplicate your code. For example:



          get_virtual_host() {
          if [ -t 0 ]; then
          read -p "Create virtualhost (= Folder name,case sensitive)" -r host
          else
          host=$(zenity --forms --add-entry=Name --text='Create virtualhost (= Folder name,case sensitive)')
          fi
          case "$host" in
          "") echo "Bad input: empty" >&2; exit 1 ;;
          *"*"*) echo "Bad input: wildcard" >&2; exit 1 ;;
          *[[:space:]]*) echo "Bad input: whitespace" >&2; exit 1 ;;
          esac
          echo "$host"
          }

          host=$(get_virtual_host)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered yesterday









          glenn jackmanglenn jackman

          1,799711




          1,799711












          • $begingroup$
            Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
            $endgroup$
            – LeonidMew
            yesterday










          • $begingroup$
            Merged and updated version in git. If you may look over it - I can add another question.
            $endgroup$
            – LeonidMew
            21 hours ago


















          • $begingroup$
            Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
            $endgroup$
            – LeonidMew
            yesterday










          • $begingroup$
            Merged and updated version in git. If you may look over it - I can add another question.
            $endgroup$
            – LeonidMew
            21 hours ago
















          $begingroup$
          Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
          $endgroup$
          – LeonidMew
          yesterday




          $begingroup$
          Great! Ill manage two versions - gui and your - terminal. Going to merge security and readability changes. Is it possible to determine if script is running without terminal? Whats unclear is editor=${VISUAL:-$EDITOR}` I haven't this variables set, so script is running in terminal only, without editor. Also read... is it terminal only command?
          $endgroup$
          – LeonidMew
          yesterday












          $begingroup$
          Merged and updated version in git. If you may look over it - I can add another question.
          $endgroup$
          – LeonidMew
          21 hours ago




          $begingroup$
          Merged and updated version in git. If you may look over it - I can add another question.
          $endgroup$
          – LeonidMew
          21 hours ago










          LeonidMew is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          LeonidMew is a new contributor. Be nice, and check out our Code of Conduct.













          LeonidMew is a new contributor. Be nice, and check out our Code of Conduct.












          LeonidMew is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f214489%2fsimple-bash-script-creates-apache2-virtualhost-config-for-subdomain%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Fairchild Swearingen Metro Inhaltsverzeichnis Geschichte | Innenausstattung | Nutzung | Zwischenfälle...

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...

          Marineschifffahrtleitung Inhaltsverzeichnis Geschichte | Heutige Organisation der NATO | Nationale und...