1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ghost_ynh.git synced 2024-09-03 19:16:02 +02:00

Merge branch 'registeradmin'

This commit is contained in:
Julien Malik 2014-03-24 22:23:43 +01:00
commit 4e872c43df
5 changed files with 52 additions and 2 deletions

4
conf/user_getmail.py Normal file
View file

@ -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"]

4
conf/user_getname.py Normal file
View file

@ -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"]

3
conf/user_list.py Normal file
View file

@ -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))

View file

@ -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"
}
}
]
}

View file

@ -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"