1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/jenkins_ynh.git synced 2024-09-03 19:26:18 +02:00
jenkins_ynh/scripts/install

246 lines
9.7 KiB
Text
Raw Normal View History

2014-12-09 21:00:17 +01:00
#!/bin/bash
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# GENERIC START
2017-03-19 18:28:38 +01:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2016-11-30 17:45:05 +01:00
2017-03-19 22:50:12 +01:00
source _common.sh
2021-02-25 23:05:04 +01:00
source ynh_send_readme_to_admin__2
2017-03-19 18:28:38 +01:00
source /usr/share/yunohost/helpers
#=================================================
2021-02-25 23:05:04 +01:00
# MANAGE SCRIPT FAILURE
2017-03-19 18:28:38 +01:00
#=================================================
ynh_clean_setup () {
2019-01-13 18:07:28 +01:00
# Clean installation remaining that are not handle by the remove script.
2017-12-16 23:20:29 +01:00
ynh_clean_check_starting
2019-01-13 18:07:28 +01:00
# Stop change_port()
ynh_exec_warn_less kill -s 15 $pid_change_port
2016-11-30 17:52:46 +01:00
# Clean hosts
sed -i '/#jenkins/d' /etc/hosts
2016-11-30 17:45:05 +01:00
}
2019-01-13 18:07:28 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-03-19 18:28:38 +01:00
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
2016-11-30 17:45:05 +01:00
domain=$YNH_APP_ARG_DOMAIN
2017-03-19 18:28:38 +01:00
path_url=$YNH_APP_ARG_PATH
2016-11-30 17:45:05 +01:00
is_public=$YNH_APP_ARG_IS_PUBLIC
2022-05-22 14:58:59 +02:00
jenkins_version=$(ynh_app_upstream_version)
2016-11-30 17:45:05 +01:00
app=$YNH_APP_INSTANCE_NAME
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
2017-03-19 18:28:38 +01:00
#=================================================
2019-05-28 00:28:01 +02:00
ynh_script_progression --message="Validating installation parameters..."
2016-11-30 17:45:05 +01:00
final_path=/var/lib/$app
2019-05-28 00:28:01 +02:00
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
2019-05-28 00:28:01 +02:00
ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
2014-12-09 21:00:17 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Storing installation settings..."
2016-11-30 17:45:05 +01:00
2019-05-28 00:28:01 +02:00
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=overwrite_nginx --value=1
ynh_app_setting_set --app=$app --key=admin_mail_html --value=1
2016-11-30 17:45:05 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Finding an available port..."
2017-03-19 18:28:38 +01:00
2021-02-25 23:05:04 +01:00
# Find an available port
2022-05-22 14:58:59 +02:00
port=$(ynh_find_port --port=8095)
2019-05-28 00:28:01 +02:00
ynh_app_setting_set --app=$app --key=port --value=$port
2017-03-19 18:28:38 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Installing dependencies..."
2016-11-30 17:45:05 +01:00
2021-02-25 23:05:04 +01:00
ynh_install_app_dependencies $pkg_dependencies
2022-05-24 01:06:35 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
2021-02-25 23:05:04 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="../conf"
2022-05-22 14:58:59 +02:00
ynh_setup_source --source_id="jenkins-plugin-manager" --dest_dir="$final_path"
2017-03-19 18:28:38 +01:00
2022-05-23 23:23:48 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:$app "$final_path"
2017-03-19 18:28:38 +01:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Configuring NGINX web server..."
2017-03-19 18:28:38 +01:00
2020-12-03 18:24:29 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2017-03-19 18:28:38 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# INSTALL JENKINS
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Installing Jenkins..."
2019-01-13 18:07:28 +01:00
# Download jenkins deb file and install it.
2019-01-21 13:08:17 +01:00
dpkg --install --force-confnew ../conf/jenkins.deb
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# SETUP APPLICATION
2017-03-19 18:28:38 +01:00
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Setuping application..."
2021-02-25 23:05:04 +01:00
2022-05-22 14:58:59 +02:00
cat >> "$final_path/jenkins.install.InstallUtil.lastExecVersion" <<EOF
$jenkins_version
EOF
chown $app:$app "$final_path/jenkins.install.InstallUtil.lastExecVersion"
2014-12-16 08:14:48 +01:00
2022-05-22 14:58:59 +02:00
cat >> "$final_path/jenkins.install.UpgradeWizard.state" <<EOF
$jenkins_version
EOF
chown $app:$app "$final_path/jenkins.install.UpgradeWizard.state"
2022-05-22 14:58:59 +02:00
ynh_replace_string --match_string="Environment=\"JENKINS_PORT=8080\"" --replace_string="Environment=\"JENKINS_PORT=$port\"\nEnvironment=\"JENKINS_PREFIX=$path_url\"" --target_file="/lib/systemd/system/jenkins.service"
2019-01-21 19:29:42 +01:00
2022-05-22 14:58:59 +02:00
systemctl daemon-reload --quiet
2022-05-22 14:58:59 +02:00
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started Jenkins Continuous Integration Server" --log_path="systemd"
2018-07-13 17:33:05 +02:00
2022-05-22 14:58:59 +02:00
#=================================================
# INSTALL PLUGINS
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Installing plugins..."
2019-01-30 15:56:18 +01:00
2022-05-22 14:58:59 +02:00
jenkins_plugin_manager="ynh_exec_warn_less java -jar $final_path/jenkins-plugin-manager.jar --war /usr/share/java/jenkins.war --plugin-download-directory=$final_path/plugins"
2019-01-21 19:29:42 +01:00
2019-01-13 18:07:28 +01:00
# Install plugins for http authentication and ldap.
2022-05-22 14:58:59 +02:00
$jenkins_plugin_manager --plugins reverse-proxy-auth-plugin
2017-12-16 23:20:29 +01:00
2019-01-13 18:07:28 +01:00
# Install recommended plugins (those from Setup Wizard)
2022-05-22 14:58:59 +02:00
$jenkins_plugin_manager --plugins cloudbees-folder # Folders Plugin
$jenkins_plugin_manager --plugins antisamy-markup-formatter # OWASP Markup Formatter Plugin
$jenkins_plugin_manager --plugins pam-auth # PAM Authentication plugin
$jenkins_plugin_manager --plugins mailer # Mailer Plugin
$jenkins_plugin_manager --plugins ldap # LDAP Plugin
$jenkins_plugin_manager --plugins matrix-auth # Matrix Authorization Strategy Plugin
$jenkins_plugin_manager --plugins build-timeout # Build timeout plugin
$jenkins_plugin_manager --plugins credentials-binding # Credentials Binding Plugin
$jenkins_plugin_manager --plugins timestamper # Timestamper
$jenkins_plugin_manager --plugins ws-cleanup # Workspace Cleanup Plugin
$jenkins_plugin_manager --plugins ant # Ant Plugin
$jenkins_plugin_manager --plugins gradle # Gradle Plugin
$jenkins_plugin_manager --plugins workflow-aggregator # Pipeline
$jenkins_plugin_manager --plugins pipeline-stage-view # Pipeline: Stage View Plugin
$jenkins_plugin_manager --plugins git # Git plugin
$jenkins_plugin_manager --plugins github-organization-folder # GitHub Organization Folder Plugin
$jenkins_plugin_manager --plugins subversion # Subversion Plug-in
$jenkins_plugin_manager --plugins email-ext # Email Extension Plugin
$jenkins_plugin_manager --plugins ssh-slaves # SSH Slaves plugin
2017-12-16 23:20:29 +01:00
2019-01-13 18:07:28 +01:00
# Install extra comfort plugins
# Handle terminal colours. Enhance the readability of the terminal.
2022-05-22 14:58:59 +02:00
$jenkins_plugin_manager --plugins ansicolor
2021-02-25 23:05:04 +01:00
# Monitoring of the local file system. Allow to monitor a directory and trig a job if a file has been modified.
2022-05-22 14:58:59 +02:00
$jenkins_plugin_manager --plugins fstrigger
2019-01-30 15:56:18 +01:00
2021-02-25 23:05:04 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
# ADD A CONFIGURATION
2021-02-25 23:05:04 +01:00
#=================================================
2022-05-22 14:58:59 +02:00
ynh_script_progression --message="Adding a configuration file..."
ynh_add_config --template="../conf/config.xml" --destination="$final_path/config.xml"
2021-02-25 23:05:04 +01:00
2022-05-22 14:58:59 +02:00
chown $app:$app "$final_path/config.xml"
2021-02-25 23:05:04 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2022-05-22 14:58:59 +02:00
yunohost service add $app --description="Jenkins Continuous Integration Server"
2021-02-25 23:05:04 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Starting a systemd service..."
2021-02-25 23:05:04 +01:00
# Start a systemd service
2022-05-22 14:58:59 +02:00
ynh_systemd_action --service_name=$app --action="restart" --line_match="Started Jenkins Continuous Integration Server" --log_path="systemd"
2016-11-30 17:45:05 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
# SETUP SSOWAT
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Configuring permissions..."
2017-03-19 18:28:38 +01:00
2021-02-25 23:05:04 +01:00
# Make app public if necessary
if [ $is_public -eq 1 ]
2019-01-13 18:07:28 +01:00
then
2021-02-25 23:05:04 +01:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
ynh_permission_update --permission="main" --add="visitors"
2016-11-30 17:45:05 +01:00
fi
2016-11-30 17:52:46 +01:00
2021-02-25 23:05:04 +01:00
# /path/github-webhook has to be accessible for github's webhooks
2021-04-10 20:50:48 +02:00
ynh_permission_create --permission="github-webhook" --url="/github-webhook" --allowed="visitors" --show_tile="false" --protected="true"
2021-02-25 23:05:04 +01:00
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
# RELOAD NGINX
2017-03-19 18:28:38 +01:00
#=================================================
2021-02-25 23:05:04 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-03-19 18:28:38 +01:00
2021-02-25 23:05:04 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2017-12-16 23:20:29 +01:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2019-01-21 13:08:17 +01:00
# Get main domain and buid the url of the admin panel of the app.
admin_panel="https://$(grep portal_domain /etc/ssowat/conf.json | cut -d'"' -f4)/yunohost/admin/#/apps/$app"
2017-12-16 23:20:29 +01:00
2019-01-30 19:23:57 +01:00
echo "You can configure this app easily by using the experimental __URL_TAG1__config-panel feature__URL_TAG2__$admin_panel/config-panel__URL_TAG3__.
You can also find some specific actions for this app by using the experimental __URL_TAG1__action feature__URL_TAG2__$admin_panel/actions__URL_TAG3__.
If you're facing an issue or want to improve this app, please open a new issue in this __URL_TAG1__project__URL_TAG2__https://github.com/YunoHost-Apps/jenkins_ynh__URL_TAG3__." > mail_to_send
2019-01-21 13:08:17 +01:00
2019-05-28 00:28:01 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --recipients="root" --type=install
2019-01-21 13:08:17 +01:00
2019-01-30 15:56:18 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2021-04-10 20:50:48 +02:00
ynh_script_progression --message="Installation of $app completed"