1. This forum is in read-only mode.

Simple Batch tutorial - 1 post

Discussion in 'Computers & Modding' started by yoshi2889, Feb 15, 2010.

  1. yoshi2889

    yoshi2889 Well-Known Member

    Hey all!

    I am doing much with Batch lately, don't know why, but I like it.
    I made a simple tutorial for you all.
    This one is with pics :)

    Lets start...

    1. Basics

    1.1 - Creating a Batch file (.bat)
    Simply, open up Notepad.
    Click File, click Save, type ''tutorial.bat'' (or another name, if you wish, as long as it has the extention .bat).

    1.2 - Starting a Batch file
    Start a Batch file with the code:
    Code:
    @echo off
    This will prevent that any of the Batch codes will be displayed when running.

    1.3 - Displaying text
    The Batch file will display text with the following code:
    Code:
    echo (yourtexthere)
    This will display ''(yourtexthere)'' on the screen (without the '').
    Be sure it is after the @echo off.

    1.4 - Asking for button press
    If you want the user to press a button to continue, this is the ideal code!
    Code:
    PAUSE
    This will cause:
    [​IMG]
    (Press any key to continue)

    1.5 - Run an external program
    If you want the Batch file run an external program, you need to know the full filename (name + extention).
    Example (Batch going to run Notepad):
    Code:
    @echo off
    start notepad.exe
    If you want the Batch file to run an .txt file (or any other extention), you need to know the filename too.
    Code:
    @echo off
    start your_txt_filename_here.txt
    1.6 - Writing to an .ini or .txt file
    If you need the Batch file to write into another file, use this code:
    Code:
    @echo off
    echo The_Text_You_Want_To_Write >> The_Filename_Of_The_File.txt/.ini
    The >> tells the Batch file that the text must be writed to a file.

    **Will be updated, I'm still learning...**
     
  2. Loonylion

    Loonylion Administrator Staff Member

    THIS is a real batch

    Code:
    #!/bin/sh
    
    yum -y install mysql-server cyrus-sasl-sql cyrus-sasl-devel pcre-devel mysql-devel google-perftools google-perftools-devel libxml2-devel libc-client libc-client-devel db4-devel
    
    yum -y update autoconf automake make
    
    cd /tmp
    wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-shared-community-5.1.41-0.rhel5.x86_64.rpm/from/http://opensource.become.com/mysql/
    
    rpm -Uvh MySQL-shared-community-5.1.41-0.rhel5.x86_64.rpm
    
    export LE_VER=1.4.13
    
    wget -m -nd http://www.monkey.org/~provos/libevent-$LE_VER-stable.tar.gz
    
    tar -zxf "libevent-$LE_VER-stable.tar.gz"
    cd "libevent-$LE_VER-stable"
    ./configure
    make
    make install
    cd ../
    
    export PHP_VER=5.3.1
    
    cd /tmp
    
    wget -m -nd "http://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~$PHP_VER.tar.gz"
    tar -zxf "php-fpm-0.6~$PHP_VER.tar.gz"
    php-fpm-0.6-$PHP_VER/generate-fpm-patch
    
    wget -m -nd http://us2.php.net/distributions/php-$PHP_VER.tar.gz
    tar zxf "php-$PHP_VER.tar.gz"
    cd "php-$PHP_VER"
    
    # Patch and build.
    patch -p1 < ../fpm.patch
    ./buildconf --force
    mkdir fpm-build 
    cd fpm-build
    ../configure --enable-mysqlnd-threading --disable-pdo --without-pear --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-zlib --with-fpm --with-imap --enable-mbstring
    make
    make install
    
    cd /tmp
    export NGINX_VER=0.8.31;
    wget -m -nd http://nginx.org/download/nginx-$NGINX_VER.tar.gz
    tar -zxf "nginx-$NGINX_VER.tar.gz"
    cd nginx-$NGINX_VER
    
    ./configure --with-rtsig_module --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --without-http_ssi_module  --without-http_autoindex_module --without-http_limit_req_module --without-http_empty_gif_module --with-google_perftools_module --with-pcre
    make
    make install
    
    cp -f /tmp/mailinstall/nginx.txt /usr/local/nginx/conf/nginx.conf
    echo "fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;" >> /usr/local/nginx/conf/fastcgi_params
    
    echo pwcheck_method: auxprop >> /usr/lib64/sasl2/postfix.conf
    echo auxprop_plugin: sql >> /usr/lib64/sasl2/postfix.conf
    echo mech_list: CRAM-MD5 DIGEST-MD5 PLAIN LOGIN >> /usr/lib64/sasl2/postfix.conf
    echo sql_engine: mysql >> /usr/lib64/sasl2/postfix.conf
    echo sql_hostnames: localhost >> /usr/lib64/sasl2/postfix.conf
    echo sql_user: mailtest >> /usr/lib64/sasl2/postfix.conf
    echo sql_passwd: mailtest >> /usr/lib64/sasl2/postfix.conf
    echo sql_database: mailtest >> /usr/lib64/sasl2/postfix.conf
    echo sql_verbose: yes >> /usr/lib64/sasl2/postfix.conf
    echo sql_select: SELECT clear_password FROM mailbox WHERE email='%u@%r' AND disablesmtpauth=0 >> /usr/lib64/sasl2/postfix.conf
    
    echo default-character-set = utf8 >> /etc/my.cnf
    echo default-collation = utf8_general_ci >> /etc/my.cnf
    
    service mysqld start
    
    echo "run the following commands:"
    echo "source /tmp/mailinstall/sql.sql;"
    echo "exit;"
    
    mysql -u root -p 
    
    groupadd -r postfix
    useradd -r -g postfix -s /bin/false postfix
    
    groupadd -r postdrop
    
    chown root.postfix /usr/lib64/sasl2/postfix.conf
    chmod 640 /usr/lib64/sasl2/postfix.conf 
    
    groupadd -g 1001 mail
    useradd -u 1001 -s /bin/false -g mail vmail
    
    rm -f /usr/lib/sendmail
    
    
    cd /tmp
    
    wget http://www.tigertech.net/mirrors/postfix-release/experimental/postfix-2.7-20091209.tar.gz
    tar -zxf postfix-2.7-20091209.tar.gz
    cd postfix-2.7-20091209
    
    mkdir /etc/postfix
    
    cp -f /tmp/mailinstall/postfix-main.txt /etc/postfix/main.cf
    
    make -f Makefile.init makefiles   'CCARGS=-DHAS_MYSQL -I/usr/include/mysql -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -I/usr/include/openssl'   'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm -lsasl2 -lssl -lcrypto'
    make
    
    make upgrade
    
    ln -s /usr/sbin/sendmail /usr/lib/sendmail
    
    mkdir -p /var/vmail
    chmod 770 /var/vmail
    chown vmail.mail /var/vmail
    
    cd /tmp
    echo download dovecot >> /tmp/mailinstall/log.txt
    
    wget http://www.dovecot.org/releases/1.2/dovecot-1.2.9.tar.gz
    tar -zxf dovecot-1.2.9.tar.gz
    cd dovecot-1.2.9
    ./configure --with-mysql --with-sql
    make
    make install
    
    cp -f /tmp/mailinstall/dovecot-main.txt /usr/local/etc/dovecot.conf
    mkdir /usr/local/etc/dovecot
    cp -f /tmp/mailinstall/dovecot-sql.txt /usr/local/etc/dovecot/sql.conf
    echo 1 Spam >> /usr/local/etc/dovecot/trash.conf
    echo 2 Trash >> /usr/local/etc/dovecot/trash.conf
    useradd dovecot -s /bin/false
    
    
    cd /tmp
    
    wget http://sourceforge.net/projects/postfixadmin/files/postfixadmin/postfixadmin_2.3.tar.gz/download
    mkdir -p /home/mailadmin/public_html
    tar -xzf postfixadmin_2.3.tar.gz -C /home/mailadmin/public_html/
    cp -f /tmp/mailinstall/postfixadmin.txt /home/mailadmin/public_html/postfixadmin-2.3/config.inc.php
    
    cd /etc/postfix
    
    echo # Dovecot LDA >> master.cf
    echo dovecot   unix  -       n       n       -       -       pipe >> master.cf
    echo  flags=DRhu user=vmail:mail argv=/usr/libexec/dovecot/deliver -d ${recipient} >> master.cf
    
    echo user            = mailtest  >> mysql_virtual_alias_maps.cf
    echo password        = mailtest  >> mysql_virtual_alias_maps.cf
    echo hosts           = 127.0.0.1  >> mysql_virtual_alias_maps.cf
    echo dbname          = mailtest  >> mysql_virtual_alias_maps.cf
    echo query           = SELECT goto FROM alias WHERE address='%s' AND active = '1' >> mysql_virtual_alias_maps.cf
    
    echo user            = mailtest >> mysql_virtual_domains_maps.cf
    echo password        = mailtest >> mysql_virtual_domains_maps.cf
    echo hosts           = 127.0.0.1 >> mysql_virtual_domains_maps.cf
    echo dbname          = mailtest >> mysql_virtual_domains_maps.cf
    echo #query          = SELECT domain FROM domain WHERE domain='%s'  >> mysql_virtual_domains_maps.cf
    echo #optional query to use when relaying for backup MX  >> mysql_virtual_domains_maps.cf
    echo query           = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1' >> mysql_virtual_domains_maps.cf
    
    echo user            = mailtest >> mysql_relay_domains_maps.cf
    echo password        = mailtest  >> mysql_relay_domains_maps.cf
    echo hosts           = 127.0.0.1 >> mysql_relay_domains_maps.cf
    echo dbname          = mailtest >> mysql_relay_domains_maps.cf
    echo query           = SELECT domain FROM domain WHERE domain='%s' and backupmx = '1' >> mysql_relay_domains_maps.cf
    
    echo user            = mailtest >> mysql_virtual_mailbox_limit_maps.cf
    echo password        = mailtest >> mysql_virtual_mailbox_limit_maps.cf
    echo hosts           = 127.0.0.1 >> mysql_virtual_mailbox_limit_maps.cf
    echo dbname          = mailtest >> mysql_virtual_mailbox_limit_maps.cf
    echo query           = SELECT quota FROM mailbox WHERE username='%s' AND active = '1' >> mysql_virtual_mailbox_limit_maps.cf
    
    echo user            = mailtest >> mysql_virtual_mailbox_maps.cf
    echo password        = mailtest >> mysql_virtual_mailbox_maps.cf
    echo hosts           = 127.0.0.1 >> mysql_virtual_mailbox_maps.cf
    echo dbname          = mailtest >> mysql_virtual_mailbox_maps.cf
    echo query           = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1' >> mysql_virtual_mailbox_maps.cf 
    
    postfix start
    dovecot
    /usr/local/nginx/sbin/nginx
    Forget printing to the screen and opening notepad, this compiles, installs and configures a complete mailserver and all supporting software from NOTHING.
     
  3. timmy1991

    timmy1991 Well-Known Member

    That's kinda cool... what would happen if I copied this into my PC?
     
  4. Loonylion

    Loonylion Administrator Staff Member

    it wouldn't work, its for fedora linux.
     
  5. Suiseiseki

    Suiseiseki Well-Known Member

    Yeah, yeah, bash scripting. Sup list of URLs and rudimentary knowledge of how to use the terminal. Considering it's for Fedora (which I'm pretty sure only like 20 people here use) it's sort of irrelevant.
     
  6. yoshi2889

    yoshi2889 Well-Known Member

    Are you pissed? :eek:
     
  7. matty999555

    matty999555 Well-Known Member

    You like doing tutorials don't you.
     
  8. yoshi2889

    yoshi2889 Well-Known Member

    Yes...
     
  9. Seph

    Seph Administrator Staff Member

    It wasn't exactly made for other people, it was made for RomUlation to configure and install servers quickly.
     
  10. Suiseiseki

    Suiseiseki Well-Known Member

    I gathered this.
     
  11. yoshi2889

    yoshi2889 Well-Known Member

    But nobody likes them T.T