diff --git a/conf/config.php b/conf/config.php index d888873..d59c7c7 100644 --- a/conf/config.php +++ b/conf/config.php @@ -1,16 +1,4 @@ \ No newline at end of file diff --git a/conf/init_config.php b/conf/init_config.php new file mode 100644 index 0000000..ce0b784 --- /dev/null +++ b/conf/init_config.php @@ -0,0 +1,17 @@ + diff --git a/conf/init_config_user.php b/conf/init_config_user.php new file mode 100644 index 0000000..f0fc7ac --- /dev/null +++ b/conf/init_config_user.php @@ -0,0 +1,52 @@ +#!/usr/bin/php + $userlogin) +{ + $userlevel = '2'; + if ($userlogin == $GLOBALS['ynh_admin']) + { + $userlevel = '4'; + } + + $currentLogin = array($userlogin); + $currentPassword = array($userlogin => ''); + $currentLevel = array($userlogin => $userlevel); + $currentEmail = array($userlogin => ''); + + if (array_key_exists('login', $GLOBALS)) + { + $GLOBALS['login'] = array_merge($GLOBALS['login'], $currentLogin); + $GLOBALS['password'] = array_merge($GLOBALS['password'], $currentPassword); + $GLOBALS['level'] = array_merge($GLOBALS['level'], $currentLevel); + $GLOBALS['email'] = array_merge($GLOBALS['email'], $currentEmail); + } + else + { + $GLOBALS['login'] = $currentLogin; + $GLOBALS['password'] = $currentPassword; + $GLOBALS['level'] = $currentLevel; + $GLOBALS['email'] = $currentEmail; + } +} + +$userconf = ''; + +$userconf_file = '/home/yunohost.app/shaarli/data/config_user.php'; +if (!file_put_contents($userconf_file, $userconf) || strcmp(file_get_contents($userconf_file),$userconf)!=0) +{ + fwrite(STDERR, "Error while writing " . $userconf_file); + exit(1); +} + +?> 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 1effb3a..c73944c 100644 --- a/manifest.json +++ b/manifest.json @@ -51,6 +51,14 @@ }, "choices": ["Yes", "No"], "default": "Yes" + }, + { + "name": "admin", + "ask": { + "en": "Admin user" + }, + "example": "test", + "default": "test" } ] } diff --git a/scripts/install b/scripts/install index 23b8d60..a9c1de5 100644 --- a/scripts/install +++ b/scripts/install @@ -6,6 +6,7 @@ path=$2 is_public=$3 title=$4 privatelinkbydefault=$5 +admin=$6 # Check domain/path availability @@ -27,58 +28,28 @@ do done salt=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p') +if [ $privatelinkbydefault = "No" ]; then + privatelinkbydefault_php=false +else + privatelinkbydefault_php=true +fi -user_count=0 -for user in $(sudo yunohost user list | python user_list.py) -do - if [[ ! $user == yunohost.* ]]; - then - - YNH_LOGINS=$(cat << EOF -$YNH_LOGINS\\ -$user_count => $user, -EOF -) +sudo sed -i "s@YNH_SALT@$salt@g" ../conf/init_config.php +sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/init_config.php +sudo sed -i "s@YNH_TITLE@$title@g" ../conf/init_config.php +sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault_php@g" ../conf/init_config.php +sudo sed -i "s@YNH_ADMIN@$admin@g" ../conf/init_config.php - YNH_PASSWORDS=$(cat << EOF -$YNH_PASSWORDS\\ -$user => '', -EOF -) - - YNH_LEVELS=$(cat << EOF -$YNH_LEVELS\\ -$user => 2, -EOF -) - - YNH_EMAILS=$(cat << EOF -$YNH_EMAILS\\ -$user => '' -EOF -) - - let user_count++ - fi -done - -sudo sed -i "s@YNH_LOGINS@$YNH_LOGINS@g" ../conf/config.php -sudo sed -i "s@YNH_PASSWORDS@$YNH_PASSWORDS@g" ../conf/config.php -sudo sed -i "s@YNH_LEVELS@$YNH_LEVELS@g" ../conf/config.php -sudo sed -i "s@YNH_EMAILS@$YNH_EMAILS@g" ../conf/config.php -sudo sed -i "s@YNH_SALT@$salt@g" ../conf/config.php -sudo sed -i "s@YNH_TIMEZONE@$(cat /etc/timezone)@g" ../conf/config.php -sudo sed -i "s@YNH_TITLE@$title@g" ../conf/config.php -sudo sed -i "s@YNH_PRIVATE_LINK_BY_DEFAULT@$privatelinkbydefault@g" ../conf/config.php - -sudo cp ../conf/config.php $app_home_path/data +sudo cp ../conf/options.php $app_home_path/data/options.php +sudo cp ../conf/init_config.php $app_home_path/data/config.php +sudo php ../conf/init_config_user.php $(sudo yunohost user list | python ../conf/user_list.py) sudo find $final_path -type f | xargs sudo chmod 644 sudo find $final_path -type d | xargs sudo chmod 755 sudo chown -R root: $final_path -sudo find $app_home_path -type f | xargs sudo chmod 640 -sudo find $app_home_path -type d | xargs sudo chmod 750 +sudo find $app_home_path -type f | xargs sudo chmod 600 +sudo find $app_home_path -type d | xargs sudo chmod 700 sudo chown -R www-data: $app_home_path # Modify Nginx configuration file and copy it to Nginx conf directory diff --git a/scripts/user_list.py b/scripts/user_list.py deleted file mode 100644 index 8887a02..0000000 --- a/scripts/user_list.py +++ /dev/null @@ -1,3 +0,0 @@ -import sys, json -for user in json.loads(sys.stdin.readlines()[0])["Users"]: - print user["Username"] \ No newline at end of file