diff --git a/scripts/upgrade b/scripts/upgrade index c429a3b..b464c60 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,4 +1,116 @@ #!/bin/bash -echo "TODO" -exit 1 \ No newline at end of file +# Retrieve arguments +domain=$(sudo yunohost app setting ghostblog domain) +path=$(sudo yunohost app setting ghostblog path) +path=${path%/} +admin=$(sudo yunohost app setting ghostblog admin) +password=$(sudo yunohost app setting ghostblog password) + +sudo service ynh-ghostblog stop + +final_path=/var/www/ghostblog + +version=0.5.0 +echo "Downloading Ghost $version..." +mkdir ../tmp +sudo wget -O ../tmp/ghost-$version.zip "https://en.ghost.org/zip/ghost-$version.zip" +unzip ../tmp/ghost-$version.zip -d ../tmp/ghost + +echo "Saving content folder..." +sudo cp -ar $final_path/ghost/content ../tmp + +echo "Deploying source files..." +sudo rm -rf $final_path/ghost +sudo cp -r ../tmp/ghost $final_path +sudo cp -ar ../tmp/content $final_path/ghost +#sudo cp ../conf/npm-shrinkwrap.json $final_path/ghost +sudo chown -R ghostblog: $final_path + +echo "Installing Ghost with NPM..." +#sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.eu" ghostblog +sudo su --shell /bin/bash --command "cd $final_path/ghost && npm install --production --registry http://registry.npmjs.org" ghostblog + +echo "Cleaning up install tree..." +sudo rm -rf $final_path/.npm +find $final_path -type d | grep "test$" | xargs sudo rm -rf +find $final_path -type d | grep "tests$" | xargs sudo rm -rf +sudo rm -rf $final_path/ghost/node_modules/sqlite3/build +sudo rm -rf $final_path/tmp + +echo "Patching sources to remove calls to googleapis..." +# patches to core +sudo cp $final_path/ghost/core/server/views/user-error.hbs $final_path/ghost/core/server/views/user-error.hbs.orig +sudo cp $final_path/ghost/core/server/views/default.hbs $final_path/ghost/core/server/views/default.hbs.orig +sudo cp $final_path/ghost/core/client/assets/css/fonts.css $final_path/ghost/core/client/assets/css/fonts.css.orig +sudo sed -i '/googleapis/c\ ' $final_path/ghost/core/server/views/user-error.hbs +sudo sed -i '/googleapis/c\ ' $final_path/ghost/core/server/views/default.hbs +sudo cp ../patches/core/fonts.css $final_path/ghost/core/client/assets/css +sudo cp ../patches/core/*.woff $final_path/ghost/core/client/assets/fonts +# patches to casper theme +#sudo cp $final_path/ghost/content/themes/casper/default.hbs $final_path/ghost/content/themes/casper/default.hbs.orig +#sudo cp $final_path/ghost/content/themes/casper/assets/css/fonts.css $final_path/ghost/content/themes/casper/assets/css/fonts.css.orig +#sudo sed -i '/googleapis/c\ ' $final_path/ghost/content/themes/casper/default.hbs +#sudo cp ../patches/theme/fonts.css $final_path/ghost/content/themes/casper/assets/css +#sudo cp ../patches/theme/*.woff $final_path/ghost/content/themes/casper/assets/fonts + +echo "Setting up permissions" +sudo chown -R ghostblog: $final_path/ghost + +echo "Setting up database..." +db_name=ghostblog +db_user=ghostblog +db_pwd=$(sudo yunohost app setting ghostblog mysqlpwd) +# db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d '[A-Za-z0-9]' | sed -n 's/\(.\{24\}\).*/\1/p') +# sudo yunohost app initdb $db_user -d $db_name -p $db_pwd +# sudo yunohost app setting ghostblog mysqlpwd -v $db_pwd + +echo "Deploying configuration..." +sed -i "s@YNH_DOMAIN@$domain@g" ../conf/config.js +sed -i "s@YNH_LOCATION@${path%/}@g" ../conf/config.js +sed -i "s@YNH_DBNAME@$db_name@g" ../conf/config.js +sed -i "s@YNH_DBUSER@$db_user@g" ../conf/config.js +sed -i "s@YNH_DBPWD@$db_pwd@g" ../conf/config.js +sudo cp ../conf/config.js $final_path/ghost +sudo chown ghostblog: $final_path/ghost/config.js +sudo chmod 644 $final_path/ghost/config.js + +echo "Setting up init script..." +logfile=/var/log/ynh-ghostblog.log +sudo touch $logfile +sudo chown ghostblog: $logfile + +sed -i "s@YNH_FINALPATH@$final_path@g" ../conf/init-script +sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/init-script +sudo cp ../conf/init-script /etc/init.d/ynh-ghostblog +sudo chmod +x /etc/init.d/ynh-ghostblog +sudo update-rc.d ynh-ghostblog defaults +sudo service ynh-ghostblog start +sudo yunohost service add ynh-ghostblog -l $logfile + +echo "Setting up logrotate configuration..." +sed -i "s@YNH_LOGFILE@$logfile@g" ../conf/logrotate +sudo cp ../conf/logrotate /etc/logrotate.d/ynh-ghostblog + +echo "Nginx configuration (sso disabled)..." +sed -i "s@YNH_LOCATION@$path@g" ../conf/nginx.conf +sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/ghostblog.conf +sudo yunohost app setting ghostblog skipped_uris -v "/" + +echo "Reloading Nginx (sso disabled)..." +sudo service nginx reload +sudo yunohost app ssowatconf + +# echo "Registering admin..." +# admin_name=$(sudo yunohost user list --json | python ../conf/user_getname.py $admin) +# admin_mail=$(sudo yunohost user list --json | python ../conf/user_getmail.py $admin) +# curl -kL -X POST http://localhost:2368${path%/}/ghost/api/v0.1/authentication/setup/ \ +# --data-urlencode "setup[0][name]=$admin_name" \ +# --data-urlencode "setup[0][email]=$admin_mail" \ +# --data-urlencode "setup[0][password]=$password" \ +# --data-urlencode "setup[0][blogTitle]=My Yunohost blog" +# +# sudo yunohost app setting ghostblog admin -v $admin +# sudo yunohost app setting ghostblog password -v $password + +echo "Success ! You can go to https://$domain$path/ghost to write your posts"