Skip to content

Commit

Permalink
Unmunged variable names, more consistent and easier to read.
Browse files Browse the repository at this point in the history
  • Loading branch information
zk committed May 1, 2010
1 parent e2e7343 commit 0726b68
Showing 1 changed file with 38 additions and 44 deletions.
82 changes: 38 additions & 44 deletions src/leiningen/init_script.clj
Expand Up @@ -4,76 +4,70 @@
[clojure.contrib.duck-streams]
))

(def init-script-template)
(def install-script-template)
(def clean-script-template)
(def gen-init-script)
(def gen-install-script)
(def gen-clean-script)

(defn create-output-dir [path]
(.mkdirs (java.io.File. path)))

(defn opts-to-map
([args]
(opts-to-map args {}))
([args defaults]
(let [res (reduce #(assoc %1 (first %2) (second %2)) {} (partition 2 args))]
(conj defaults res))))

(defn defaults [project]
(let [name (:name project)
root (:root project)]
{:name name
:pid-dir "/var/run"
:install-dir (str "/usr/local/" name)
:init-script-dir "/etc/init.d"}))
:jar-install-dir (str "/usr/local/" name)
:init-script-install-dir "/etc/init.d"
:artifact-dir (str root "/init-script")}))

(defn init-script [projects & args]
(let [root (:root projects)
name (:name projects)
output-dir-path (str root "/init-script/")
uberjar-file (java.io.File. (str root "/" (:name projects) "-standalone.jar"))
uberjar-lsg-file (java.io.File. (str output-dir-path (:name projects) "-standalone.jar"))
init-script-path (str output-dir-path (:name projects) "d")
install-script-path (str output-dir-path "install-" (:name projects))
clean-script-path (str output-dir-path "clean-" (:name projects))
opts (merge (defaults projects) (:lis-opts projects))]
(create-output-dir output-dir-path)
(let [opts (merge (defaults projects) (:lis-opts projects))
root (:root projects)
name (:name opts)
artifact-dir (:artifact-dir opts)
source-uberjar-path (str root "/" name "-standalone.jar")
artifact-uberjar-path (str artifact-dir "/" name "-standalone.jar")
artifact-init-script-path (str artifact-dir "/" name "d")
install-script-path (str artifact-dir "/" "install-" name)
clean-script-path (str artifact-dir "/" "clean-" name)]
(create-output-dir artifact-dir)
(uberjar projects)
(copy uberjar-file uberjar-lsg-file)
(spit init-script-path (init-script-template projects opts))
(copy (java.io.File. source-uberjar-path) (java.io.File. artifact-uberjar-path))
(spit artifact-init-script-path (gen-init-script projects opts))
(spit
install-script-path
(install-script-template (.getAbsolutePath uberjar-file) init-script-path opts))
(spit clean-script-path (clean-script-template projects opts))
(println (str "*** Done generating init scripts, see the " output-dir-path " directory"))))
(gen-install-script artifact-uberjar-path artifact-init-script-path opts))
(spit clean-script-path (gen-clean-script projects opts))
(println (str "*** Done generating init scripts, see the " artifact-dir " directory"))))

(defn install-script-template [uberjar-path init-script-path opts]
(let [install-dir (:install-dir opts)
init-script-dir (:init-script-dir opts)
(defn gen-install-script [uberjar-path init-script-path opts]
(let [jar-install-dir (:jar-install-dir opts)
init-script-install-dir (:init-script-install-dir opts)
name (:name opts)
installed-init-script-path (str init-script-dir "/" name "d")]
installed-init-script-path (str init-script-install-dir "/" name "d")]
(str "#!/bin/bash
mkdir -p " install-dir "
cp " uberjar-path " " install-dir "/" name "-standalone.jar
mkdir -p " init-script-dir "
cp " init-script-path " " init-script-dir "
mkdir -p " jar-install-dir "
cp " uberjar-path " " jar-install-dir "/" name "-standalone.jar
mkdir -p " init-script-install-dir "
cp " init-script-path " " init-script-install-dir "
chmod u+x " installed-init-script-path "
")))

(defn clean-script-template [project opts]
(let [install-dir (:install-dir opts)
init-script-dir (:init-script-dir opts)
(defn gen-clean-script [project opts]
(let [jar-install-dir (:jar-install-dir opts)
init-script-install-dir (:init-script-install-dir opts)
name (:name project)]
(str "#!/bin/bash
rm -f " install-dir "/" name "-standalone.jar
rm -f " init-script-dir "/" name "d
rm -f " jar-install-dir "/" name "-standalone.jar
rm -f " init-script-install-dir "/" name "d
")))


(defn init-script-template [project opts]
(defn gen-init-script [project opts]
(let [name (:name project)
description (:description project)
pid-dir (:pid-dir opts)
install-dir (:install-dir opts)]
jar-install-dir (:jar-install-dir opts)]
(str "#!/bin/bash
#
# /etc/rc.d/init.d/" name "d
Expand All @@ -85,7 +79,7 @@ rm -f " init-script-dir "/" name "d
NAME=" name "
PID_DIR=" pid-dir "
PID_FILE=$PID_DIR/$NAME.pid
INSTALL_DIR=" install-dir "
INSTALL_DIR=" jar-install-dir "
INSTALL_JAR=$INSTALL_DIR/$NAME-standalone.jar
mkdir -p $PID_DIR
Expand Down Expand Up @@ -138,7 +132,7 @@ case \"$1\" in
start
;;
*)
echo 'Usage $NAMEd {start|stop|status|restart}'
echo \"Usage: $NAME\"\"d {start|stop|status|restart}\"
exit 1
;;
esac
Expand Down

0 comments on commit 0726b68

Please sign in to comment.