#!/usr/bin/env escript % coding: utf-8 % Copyright 2008 Grégory Burri % % This file is part of Euphorik. % % Euphorik is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % Euphorik is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with Euphorik. If not, see . % This file replace the old one 'tools.rb' written in a crapy language ;) % TODO : % - création de unit tests (voir eunit) et validation avant la mise en prod main(Args) -> file:set_cwd(".."), case Args of ["prod"] -> in_prod("gburri@euphorik.ch:/var/www/euphorik"); ["pre"] -> in_preprod("gburri@euphorik.ch:/var/www/euphorik_preprod", "var/www/euphorik"); ["js"] -> verif_js(); ["version"] -> update_version(); _ -> io:format( "Usage : ~s (prod | pre | js | version)~n" " prod : in production~n" " pre : in preproduction, data are copied from production~n" " js : check the JavaScript files~n" " version : update the version into somes files from the VERSION file", [escript:script_name()] ) end. % A simple fonction to log message. log(Str) -> io:format("===== ~s =====~n", [Str]). % Execute an OS commande and print the result to stdout. cmd(Commande_str) -> cmd(Commande_str, []). cmd(Commande_str, Params) -> io:format("~s~n", [os:cmd(lists:flatten(io_lib:format(Commande_str, Params)))]). -record(uri, { host, path % in absolute }). % Create an uri record from an uri string. create_uri(Uri_str) -> [Host, Path] = string:tokens(Uri_str, ":"), #uri{host = Host, path = Path}. % Update the version into somes files from the VERSION file. update_version() -> log("Update the version tag"), todo. % Check the JavaScript files. verif_js() -> todo. % Start the production processus. in_prod(Uri) -> compile_server_part(Uri), make_var_directory(Uri), copy_files(Uri), define_files_rights(Uri), update_server(). % Start the pre-production processus. in_preprod(Uri, data_path) -> compile_server_part(Uri), make_var_directory(Uri), copy_files(Uri), define_files_rights(Uri), start_server(), update_server(). % Compile the Erlang modules. compile_server_part(Uri) -> todo. % Create the 'var' folder if it doesn't exist. make_var_directory(Uri) -> todo. % Copy files from developpement env to production server. copy_files(Uri) -> copy_static_part(Uri), copy_packed_js(Uri). % Copy all static files like modules, styles, pages, etc. copy_static_part(Uri) -> %~ creer_rep('modules') %~ system("rsync -r --exclude 'euphorik_test.beam' modules/ebin #{@uri}:#{@rep}/modules") %~ system("rsync -r modules/include #{@uri}:#{@rep}/modules") todo. % Minify and pack JavaScript in one file then copy it to ther server. copy_packed_js(Uri) -> todo. % Define the rights for the copied folder et files. define_files_rights(Uri) -> todo. % Start the server if it not already started (in preproduction case only). start_server() -> todo. % Run a erlang script to update_server() -> todo.