Created
February 21, 2017 11:40
-
-
Save zorbash/eaffc7e24f86eac476506e62be8797dd to your computer and use it in GitHub Desktop.
Kitto Updater Script (for version >= 0.5.1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
set -e | |
github_base_url=https://raw.githubusercontent.com/kittoframework/kitto/master | |
print_banner | |
ask_continue | |
update_configs | |
update_widgets | |
echo "Updating: application.js" | |
local url="$github_base_url/installer/templates/new/assets/javascripts/application.js" | |
curl -# $url > "assets/javascripts/application.js" | |
remove_obsolete_files | |
print_outro | |
} | |
print_banner() { | |
cat <<EOF | |
╔═══════════════╗ | |
║ Kitto Updater ║ | |
╚═══════════════╝ | |
╔═════════════════════════════════════════════════════════════════════════════════════╗ | |
║ ║ | |
║ Your assets and configs will be updated to use Kitto version >= v0.5.1 ║ | |
║ ║ | |
║ Please backup your sources or use version control, since files will be overwritten ║ | |
║ or removed. ║ | |
║ ║ | |
╚═════════════════════════════════════════════════════════════════════════════════════╝ | |
EOF | |
} | |
ask_continue() { | |
cat <<EOF | |
╔══════════════════════════════════════════╗ | |
║ Are you sure you wish to continue? (y/n) ║ | |
╚══════════════════════════════════════════╝ | |
EOF | |
read answer | |
if echo "$answer" | grep -iq "^y" ;then | |
echo Yes | |
else | |
echo No | |
exit 1 | |
fi | |
} | |
print_outro() { | |
echo "Update has been completed." \ | |
"Make sure to run \`npm install\` to fetch the packaged Kitto JavaScript library." | |
} | |
update_configs() { | |
echo "Updating: package.json" | |
mix run --no-start --eval ' | |
old_config = File.read!("package.json") |> Poison.decode! | |
new_config = put_in(old_config["dependencies"]["kitto"], "file:deps/kitto") | |
case File.write("package.json", new_config |> Poison.encode!(pretty: true)) do | |
:ok -> :nop | |
{:error, reason} -> | |
IO.puts(:stderr, "[#{reason}] Could not write file: package.json") | |
end | |
' | |
} | |
update_widgets() { | |
local widgets=" | |
clock | |
graph | |
image | |
list | |
meter | |
number | |
text | |
" | |
for widget in $widgets | |
do | |
echo "Updating: $widget" | |
install -d widgets/$widget | |
local url="$github_base_url/installer/templates/new/widgets/$widget/$widget.js" | |
curl -# $url > "widgets/$widget/$widget.js" | |
done | |
} | |
remove_obsolete_files() { | |
local obsolete_files="widget.js helpers.js" | |
for file in $obsolete_files | |
do | |
echo "Removing Obsolete: assets/javascripts/$file" | |
rm -f "assets/javascripts/$file" | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment