diff --git a/conf/user_getmail.py b/conf/user_getmail.py new file mode 100644 index 0000000..1930a7f --- /dev/null +++ b/conf/user_getmail.py @@ -0,0 +1,4 @@ +import sys, json +for i in json.loads(sys.stdin.readlines()[0])["Users"]: + if i["Username"] == sys.argv[1]: + print i["Mail"] \ No newline at end of file diff --git a/conf/user_getname.py b/conf/user_getname.py new file mode 100644 index 0000000..852371b --- /dev/null +++ b/conf/user_getname.py @@ -0,0 +1,4 @@ +import sys, json +for i in json.loads(sys.stdin.readlines()[0])["Users"]: + if i["Username"] == sys.argv[1]: + print i["Fullname"] \ No newline at end of file diff --git a/conf/user_list.py b/conf/user_list.py new file mode 100644 index 0000000..52994aa --- /dev/null +++ b/conf/user_list.py @@ -0,0 +1,3 @@ +import sys, json +userlist=json.loads(sys.stdin.readlines()[0])["Users"] +print "{0}".format("\n".join(i["Username"] for i in userlist)) diff --git a/manifest.json b/manifest.json index 6a211b4..4e8cc00 100644 --- a/manifest.json +++ b/manifest.json @@ -34,6 +34,19 @@ }, "choices": ["Yes", "No"], "default": "Yes" + }, + { + "name": "admin", + "ask": { + "en": "Admin user (must be an existing Yunohost user login)" + }, + "default": "homer" + }, + { + "name": "password", + "ask": { + "en": "Admin user password" + } } ] } diff --git a/scripts/install b/scripts/install index b6e9c83..7f99233 100644 --- a/scripts/install +++ b/scripts/install @@ -4,11 +4,20 @@ domain=$1 path=$2 is_public=$3 +admin=$4 +password=$5 # Check domain/path availability sudo yunohost app checkurl $domain$path -a ghostblog if [[ ! $? -eq 0 ]]; then - exit 1 + exit 1 +fi + +# Check that admin user is an existing account +sudo yunohost user list | python ../conf/user_list.py | grep "^$admin$" >/dev/null +if [[ ! $? -eq 0 ]]; then + echo "Error : the chosen admin user does not exist" + exit 1 fi echo "Install dependencies..." @@ -74,10 +83,27 @@ sudo update-rc.d ynh-ghostblog defaults sudo service ynh-ghostblog start sudo yunohost app service 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 "Reloading Nginx..." - sudo service nginx reload sudo yunohost app ssowatconf + +echo "Registering admin..." +admin_name=$(sudo yunohost user list | python ../conf/user_getname.py $admin) +admin_mail=$(sudo yunohost user list | python ../conf/user_getmail.py $admin) +curl -kL -X GET https://$domain$path/ghost/signup --cookie-jar cookie.txt > signup_get +csrf_token=$(cat signup_get | egrep csrf-param | egrep "content=\".+\"" -o | egrep "\".+\"" -o | cut -d '"' -f 2) +curl -kL -X POST https://$domain$path/ghost/signup/ \ + --cookie cookie.txt --header "X-CSRF-Token: $csrf_token" \ + --data-urlencode "name=$admin_name" \ + --data-urlencode "email=$admin_mail" \ + --data-urlencode "password=$password" \ + > /dev/null 2>&1 +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"