From 601a88e78a4e5cd2ae534f61c46ae07a641d4848 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rault Date: Fri, 9 Jun 2017 15:06:05 +0200 Subject: [PATCH 1/3] manifest and scripts overhaul --- manifest.json | 27 +++++++++++++++++------ scripts/install | 58 ++++++++++++++++++++++++++++++------------------- scripts/remove | 10 ++++++--- 3 files changed, 63 insertions(+), 32 deletions(-) diff --git a/manifest.json b/manifest.json index e3dbdca..3f53471 100644 --- a/manifest.json +++ b/manifest.json @@ -1,19 +1,30 @@ { "name": "Gitweb", "id": "gitweb", + "packaging_format": 1, + "url": "https://github.com/rigelk/gitweb_ynh", "description": { "en": "Web interface to see gitolite repositories", "fr": "Une interface web pour consulter les dépôts gitolite" }, - "developer": { - "name": "Matlink", - "email": "matlink@matlink.fr" + "maintainer": { + "name": "rigelk", + "email": "par@rigelk.eu", + "url": "https://rigelk.eu" }, - "multi_instance": "false", + "requirements": { + "yunohost": ">> 2.5.4" + }, + "license": "free", + "services": [ + "nginx" + ], + "multi_instance": false, "arguments": { "install" : [ { "name": "domain", + "type": "domain", "ask": { "en": "Choose a domain for Gitweb", "fr": "Choisissez un domaine pour Gitweb" @@ -22,6 +33,7 @@ }, { "name": "path", + "type": "path", "ask": { "en": "Choose a path for Gitweb", "fr": "Choisissez un chemin pour Gitweb" @@ -31,6 +43,7 @@ }, { "name": "admin", + "type": "user", "ask": { "en": "Choose an admin user for Gitweb", "fr": "Choisissez un administrateur pour Gitweb" @@ -38,13 +51,13 @@ "example": "homer" }, { - "name": "public_site", + "name": "is_public", + "type": "boolean", "ask": { "en": "Should this application be public ?", "fr": "Est-ce que cette application doit être visible publiquement ?" }, - "choices": ["Yes", "No"], - "default": "No" + "default": true } diff --git a/scripts/install b/scripts/install index 93b82aa..53a04f0 100644 --- a/scripts/install +++ b/scripts/install @@ -1,43 +1,57 @@ #! /bin/bash +set -eu +# Source app helpers +. /usr/share/yunohost/helpers + +# This is a single instance app app=gitweb -domain=$1 -path=$2 -admin=$3 -is_public=$4 -final_path=/var/www$path +# Retrieve arguments +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +admin=$YNH_APP_ARG_ADMIN +is_public=$YNH_APP_ARG_IS_PUBLIC +final_path=/var/www/$path # Check domain/path availability -sudo yunohost app checkurl $domain$path -a $app -if [[ ! $? -eq 0 ]]; then - echo "Path of the domain is not available" - exit 1 -fi +sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ +|| ynh_die "Path not available: ${domain}${path_url}" # Check user sudo yunohost user list --json | grep -q "\"username\": \"$admin\"" if [[ ! $? -eq 0 ]]; then echo "Error : the chosen admin user does not exist" - exit 1 + ynh_die 1 fi # Check /var/www/$app path is available if [ -f $final_path ]; then echo "This path already contains a folder" - exit 1 + ynh_die 1 fi +# Check destination directory +[[ -d $final_path ]] && ynh_die \ +"The destination directory '$final_path' already exists.\ + You should safely delete it before installing this app." + +# Check user parameter +ynh_user_exists "$admin" \ + || ynh_die "The chosen admin user does not exist." + # Save app settings -sudo yunohost app setting $app admin -v "$admin" -sudo yunohost app setting $app is_public -v "$is_public" -sudo yunohost app setting $app final_path -v "$final_path" +ynh_app_setting_set $app admin $admin +ynh_app_setting_set $app is_public "$is_public" +ynh_app_setting_set $app final_path "$final_path" -echo "Updating apt ..." +# Installing packages +echo "Updating apt package db..." sudo apt-get -qq update echo "Installing dependancies ..." sudo apt-get install -qqy fcgiwrap gitweb >/dev/null 2>&1 +# Adding user www-data to group git sudo adduser www-data git sudo cp ../conf/gitweb.conf /etc/gitweb.conf @@ -46,7 +60,7 @@ sudo chmod 644 /etc/gitweb.conf sudo ln -s /usr/share/gitweb $final_path sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf -sudo sed -i "s,YNH_NGINX_PATH,$path,g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_WWW_PATH@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf sudo chown root: /etc/nginx/conf.d/$domain.d/$app.conf sudo chmod 600 /etc/nginx/conf.d/$domain.d/$app.conf @@ -54,10 +68,10 @@ sudo chmod 600 /etc/nginx/conf.d/$domain.d/$app.conf sudo yunohost app addaccess $app -u $admin # If app is public, add url to SSOWat conf as skipped_uris -if [ "$is_public" = "Yes" ]; -then - sudo yunohost app setting $app skipped_uris -v "/" +if [[ $is_public -eq 1 ]]; then + # unprotected_uris allows SSO credentials to be passed anyway. + ynh_app_setting_set "$app" unprotected_uris "/" fi -sudo service nginx restart -sudo yunohost app ssowatconf \ No newline at end of file +sudo service nginx reload +sudo yunohost app ssowatconf diff --git a/scripts/remove b/scripts/remove index 7253ae9..15cf0ef 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,9 +1,13 @@ #! /bin/bash +set -u + +# Source app helpers +. /usr/share/yunohost/helpers app=gitweb -domain=$(sudo yunohost app setting $app domain) -final_path=$(sudo yunohost app setting $app final_path) +domain=$(ynh_app_setting_set$app domain) +final_path=$(ynh_app_setting_set $app final_path) sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo rm -rf $final_path -sudo deluser www-data git \ No newline at end of file +sudo deluser www-data git From 202727cc763ad632e4a3265dcdc32e55f439d1f4 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rault Date: Fri, 9 Jun 2017 15:32:07 +0200 Subject: [PATCH 2/3] fixed variable mismatch in install script and typo in remove script + added git project root selection + added cloneable urls --- conf/nginx.conf | 24 +++++++++++++++++++++--- manifest.json | 12 +++++++++++- scripts/install | 10 ++++++++-- scripts/remove | 2 +- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 4944fbb..f36c471 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,4 +1,4 @@ -location YNH_NGINX_PATH/index.cgi { +location YNH_WWW_PATH/index.cgi { root /var/www/; include fastcgi_params; gzip off; @@ -6,7 +6,25 @@ location YNH_NGINX_PATH/index.cgi { fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; fastcgi_pass unix:/var/run/fcgiwrap.socket; } -location YNH_NGINX_PATH { +location YNH_WWW_PATH { root /var/www/; index index.cgi; -} \ No newline at end of file +} + +# static repo files for cloning over https +location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { + root YNH_GIT_PROJECT_ROOT; +} + +# requests that need to go to git-http-backend +location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { + root /home/git/repositories; + + fastcgi_pass unix:/var/run/fcgiwrap.socket; + fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; + fastcgi_param PATH_INFO $uri; + fastcgi_param GIT_PROJECT_ROOT YNH_GIT_PROJECT_ROOT; + fastcgi_param GIT_HTTP_EXPORT_ALL ""; + fastcgi_param REMOTE_USER $remote_user; + include fastcgi_params; +} diff --git a/manifest.json b/manifest.json index 3f53471..cfd9c81 100644 --- a/manifest.json +++ b/manifest.json @@ -41,11 +41,21 @@ "example": "/gitweb", "default": "/gitweb" }, + { + "name": "git_project_root", + "type": "path", + "ask": { + "en": "Choose an existing git project root for Gitweb", + "fr": "Choisissez un chemin existant où chercher vos projects git pour Gitweb" + }, + "example": "/home/git/repositories", + "default": "/home/git/repositories" + }, { "name": "admin", "type": "user", "ask": { - "en": "Choose an admin user for Gitweb", + "en": "Choose an admin for Gitweb", "fr": "Choisissez un administrateur pour Gitweb" }, "example": "homer" diff --git a/scripts/install b/scripts/install index 53a04f0..4969695 100644 --- a/scripts/install +++ b/scripts/install @@ -12,7 +12,9 @@ domain=$YNH_APP_ARG_DOMAIN path_url=$YNH_APP_ARG_PATH admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC -final_path=/var/www/$path +git_project_root=$YNH_APP_ARG_GIT_PROJECT_ROOT + +final_path=/var/www/$path_url # Check domain/path availability sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ @@ -31,10 +33,13 @@ if [ -f $final_path ]; then ynh_die 1 fi -# Check destination directory +# Check directories [[ -d $final_path ]] && ynh_die \ "The destination directory '$final_path' already exists.\ You should safely delete it before installing this app." +[[ ! -d $git_project_root ]] && ynh_die \ +"The git project root directory '$git_project_root' doesn't exist.\ + You should safely create it/choose another before installing this app." # Check user parameter ynh_user_exists "$admin" \ @@ -61,6 +66,7 @@ sudo chmod 644 /etc/gitweb.conf sudo ln -s /usr/share/gitweb $final_path sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf sudo sed -i "s@YNH_WWW_PATH@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_GIT_PROJECT_ROOT@$git_project_root@g" /etc/nginx/conf.d/$domain.d/$app.conf sudo chown root: /etc/nginx/conf.d/$domain.d/$app.conf sudo chmod 600 /etc/nginx/conf.d/$domain.d/$app.conf diff --git a/scripts/remove b/scripts/remove index 15cf0ef..22356a3 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,7 +6,7 @@ set -u app=gitweb -domain=$(ynh_app_setting_set$app domain) +domain=$(ynh_app_setting_set $app domain) final_path=$(ynh_app_setting_set $app final_path) sudo rm -f /etc/nginx/conf.d/$domain.d/$app.conf sudo rm -rf $final_path From df6e591c507fc05eeeafa27e94aaf1fe5c7e4f53 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rault Date: Fri, 9 Jun 2017 17:32:39 +0200 Subject: [PATCH 3/3] fixed nginx path generation and added verbose configuration defaults --- conf/gitweb.conf | 60 ++++++++++++++++++++++++++++++++++++++++++++++-- conf/nginx.conf | 6 ++--- scripts/install | 10 ++++---- scripts/remove | 2 +- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/conf/gitweb.conf b/conf/gitweb.conf index 1ba84cd..19806fe 100644 --- a/conf/gitweb.conf +++ b/conf/gitweb.conf @@ -1,9 +1,15 @@ # path to git projects (.git) $projectroot = "/home/git/repositories/"; +# default order is "project" - I prefer sorting by age, altough it's more CPU intensive +$default_projects_order = "age"; + # directory to use for temp files $git_temp = "/tmp"; +# site name shown at the page title +#$site_name = "Git trees"; + # target of the home link on top of all pages #$home_link = $my_uri || "/"; @@ -11,7 +17,7 @@ $git_temp = "/tmp"; #$home_text = "indextext.html"; # file with project list; by default, simply scan the projectroot dir. -$projects_list = "/home/git/projects.list"; +#$projects_list = "/home/git/projects.list"; # stylesheet to use #@stylesheets = ("static/gitweb.css"); @@ -25,6 +31,56 @@ $projects_list = "/home/git/projects.list"; # the 'favicon' #$favicon = "static/git-favicon.png"; +# this prevents gitweb to show hidden repositories +#$export_ok = "git-daemon-export-ok"; +#$strict_export = 1; +# and this prevents gitweb to show any repository that doesn't have a file named 'gitweb-export-ok' +#$export_ok = "gitweb-export-ok"; + +# This lets it make the URLs you see in the header +#@git_base_url_list = ( 'git://' ); # git-diff-tree(1) options to use for generated patches #@diff_opts = ("-M"); -@diff_opts = (); \ No newline at end of file +@diff_opts = (); + +# Enable PATH_INFO so the server can produce URLs of the +# form: http://example.org/domain/project.git/xxx/xxx +# This allows for pretty URLs *within* the Git repository, +# also needs the Apache rewrite rules for full effect. +#$feature{'pathinfo'}{'default'} = [1]; + +# Neat way of prefixing the top URL listing +#our @extra_breadcrumbs = ( +# [ 'Site title or whatever' => 'http://example.org/' ], +# ); + +# List avatars next to committers +#$feature{'avatar'}{'default'} = ['gravatar']; + +# The category name is read from .git/category, in the same manner as .git/description. +#$projects_list_group_categories = 1; +#$project_list_default_category = "misc"; + +$projects_list_description_width = 80; + +# Enable blame, pickaxe search, snapshop, search, and grep +# support, but still allow individual projects to turn them off. +# These are features that users can use to interact with your Git trees. They +# consume some CPU whenever a user uses them, so you can turn them off if you +# need to. Note that the 'override' option means that you can override the +# setting on a per-repository basis. +$feature{'blame'}{'default'} = [1]; +$feature{'blame'}{'override'} = [1]; + +$feature{'pickaxe'}{'default'} = [1]; +$feature{'pickaxe'}{'override'} = [1]; + +$feature{'snapshot'}{'default'} = [1]; +$feature{'snapshot'}{'override'} = [1]; + +$feature{'search'}{'default'} = [1]; + +$feature{'grep'}{'default'} = [1]; +$feature{'grep'}{'override'} = [1]; + +$feature{'highlight'}{'default'} = [1]; diff --git a/conf/nginx.conf b/conf/nginx.conf index f36c471..42eb956 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,5 +1,5 @@ -location YNH_WWW_PATH/index.cgi { - root /var/www/; +location YNH_WWW_PATHindex.cgi { + root YNH_APP_PATH; include fastcgi_params; gzip off; fastcgi_param SCRIPT_NAME $uri; @@ -7,7 +7,7 @@ location YNH_WWW_PATH/index.cgi { fastcgi_pass unix:/var/run/fcgiwrap.socket; } location YNH_WWW_PATH { - root /var/www/; + root YNH_APP_PATH; index index.cgi; } diff --git a/scripts/install b/scripts/install index 4969695..e819d0c 100644 --- a/scripts/install +++ b/scripts/install @@ -5,7 +5,7 @@ set -eu . /usr/share/yunohost/helpers # This is a single instance app -app=gitweb +app=$YNH_APP_INSTANCE_NAME # Retrieve arguments domain=$YNH_APP_ARG_DOMAIN @@ -14,7 +14,7 @@ admin=$YNH_APP_ARG_ADMIN is_public=$YNH_APP_ARG_IS_PUBLIC git_project_root=$YNH_APP_ARG_GIT_PROJECT_ROOT -final_path=/var/www/$path_url +final_path=/var/www/$app # Check domain/path availability sudo yunohost app checkurl "${domain}${path_url}" -a "$app" \ @@ -46,7 +46,7 @@ ynh_user_exists "$admin" \ || ynh_die "The chosen admin user does not exist." # Save app settings -ynh_app_setting_set $app admin $admin +ynh_app_setting_set $app admin "$admin" ynh_app_setting_set $app is_public "$is_public" ynh_app_setting_set $app final_path "$final_path" @@ -66,12 +66,12 @@ sudo chmod 644 /etc/gitweb.conf sudo ln -s /usr/share/gitweb $final_path sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf sudo sed -i "s@YNH_WWW_PATH@$path_url@g" /etc/nginx/conf.d/$domain.d/$app.conf +sudo sed -i "s@YNH_APP_PATH@$final_path@g" /etc/nginx/conf.d/$domain.d/$app.conf sudo sed -i "s@YNH_GIT_PROJECT_ROOT@$git_project_root@g" /etc/nginx/conf.d/$domain.d/$app.conf sudo chown root: /etc/nginx/conf.d/$domain.d/$app.conf sudo chmod 600 /etc/nginx/conf.d/$domain.d/$app.conf - -sudo yunohost app addaccess $app -u $admin +sudo yunohost app addaccess --users="$admin" $app # If app is public, add url to SSOWat conf as skipped_uris if [[ $is_public -eq 1 ]]; then diff --git a/scripts/remove b/scripts/remove index 22356a3..75496f2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -4,7 +4,7 @@ set -u # Source app helpers . /usr/share/yunohost/helpers -app=gitweb +app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_set $app domain) final_path=$(ynh_app_setting_set $app final_path)