module ActiveScripts module Packages class Redis < ActiveScripts::Packages::Base # INFO: ActiveScripts::Packages::Redis contains code that # execute the Redis package. private def install if package_installed?(includes: "redis") || package_installed?(command: "which redis", includes: "redis") notify_package_exists! else case $operating_system when :macosx execute_command!("brew install redis") say_ok(" Installation complete!") when :linux if agree(" [?] Redis-CLI only? ", true) execute_command!("git clone http://github.com/antirez/redis.git") execute_command!("cd redis && git checkout 3.0.2") execute_command!("cd redis && make redis-cli") execute_command!("cd redis && sudo cp src/redis-cli /usr/local/bin") execute_command!("sudo touch /var/lib/redis/6379/dump.rdb") else execute_command!("sudo apt-get -y install tcl8.5") execute_command!("wget http://download.redis.io/releases/redis-3.0.2.tar.gz") execute_command!("tar xzf redis-3.0.2.tar.gz") execute_command!("cd redis-3.0.2 && make") execute_command!("cd redis-3.0.2 && make test") execute_command!("cd redis-3.0.2 && sudo make install") execute_command!("cd redis-3.0.2/utils && sudo ./install_server.sh") execute_command!("cd redis-3.0.2/utils && sudo update-rc.d redis_6379 defaults") execute_command!("echo 1 > /proc/sys/vm/overcommit_memory") if agree(" [?] Dedicated Redis server? ", true) end say_ok(" Installation complete!") else notify_package_unavailable! end end end def upgrade if package_installed?(includes: "redis") || package_installed?(command: "which redis", includes: "redis") case $operating_system when :macosx output = execute_command!("brew upgrade redis") say_warning(" [!] #{output.squish}") unless option_dry_run? || package_output?(output, includes: "Error:") say_ok(" Upgrade complete!") else notify_package_unavailable! end else notify_package_missing! end end def uninstall if package_installed?(includes: "redis") || package_installed?(command: "which redis", includes: "redis") case $operating_system when :macosx execute_command!("brew remove redis") say_ok(" Uninstallation complete!") when :linux execute_command!("sudo rm -rf redis-3.0.2") execute_command!("sudo rm -rf redis") say_ok(" Uninstallation complete!") else notify_package_unavailable! end else notify_package_missing! end end end end end