Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions projects/sftpgo.com/com.sftpgo.plist.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.sftpgo.com</string>
<key>UserName</key>
<string>_sftpgo</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/pkgx</string>
<string>+{{ getenv "package_project" "SETUP_ERROR" }}^{{ getenv "package_version" "SETUP_ERROR" }}</string>
<string>sftpgo</string>
<string>serve</string>
<string>--config-dir</string>
<string>{{ getenv "app_conf_path" "SETUP_ERROR" }}</string>
</array>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>10</integer>
</dict>
</plist>
18 changes: 10 additions & 8 deletions projects/sftpgo.com/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ build:
SFTPGO_SETUP_SCRIPT: setup.bash
SFTPGO_README_FILE: README.md
SFTPGO_CONFIG_FILE: sftpgo.json
SFTPGO_SERVICE_ENVIRONMENT_FILE: sftpgo.env
SFTPGO_SERVICE_FILE: sftpgo.service
# SFTPGO_SERVICE_ENVIRONMENT_FILE: sftpgo.env.gtpl
SFTPGO_SYSTEMD_SERVICE_FILE: sftpgo.service.gtpl
SFTPGO_LAUNCHD_SERVICE_FILE: com.sftpgo.plist.gtpl
script:
# fails to find sqlite3.Error
- run: TAGS="-tags nosqlite"
if: 2.6.0
- go build -v $TAGS -trimpath -ldflags="${GO_LDFLAGS}" -o {{prefix}}/bin/sftpgo
- install -v -D props/${SFTPGO_SETUP_SCRIPT} {{prefix}}/bin/sftpgo-setup
- install -v -D props/${SFTPGO_README_FILE} {{prefix}}/doc/${SFTPGO_README_FILE}
- install -v -D ${SFTPGO_CONFIG_FILE} {{prefix}}/etc/sftpgo/${SFTPGO_CONFIG_FILE}
- install -v -D props/${SFTPGO_SERVICE_ENVIRONMENT_FILE} {{prefix}}/etc/sftpgo/${SFTPGO_SERVICE_ENVIRONMENT_FILE}
- install -v -D props/${SFTPGO_SERVICE_FILE} {{prefix}}/etc/systemd/system/${SFTPGO_SERVICE_FILE}
- find templates -type f -exec install -v -D "{}" "{{prefix}}/{}" \;
- find static -type f -exec install -v -D "{}" "{{prefix}}/{}" \;
- find openapi -type f -exec install -v -D "{}" "{{prefix}}/{}" \;
- install -v -D ${SFTPGO_CONFIG_FILE} {{prefix}}/conf/${SFTPGO_CONFIG_FILE}
# - install -v -D props/${SFTPGO_SERVICE_ENVIRONMENT_FILE} {{prefix}}/conf/${SFTPGO_SERVICE_ENVIRONMENT_FILE}
- install -v -D props/${SFTPGO_SYSTEMD_SERVICE_FILE} {{prefix}}/conf/${SFTPGO_SYSTEMD_SERVICE_FILE}
- install -v -D props/${SFTPGO_LAUNCHD_SERVICE_FILE} {{prefix}}/conf/${SFTPGO_LAUNCHD_SERVICE_FILE}
- find templates -type f -exec install -v -D "{}" "{{prefix}}/conf/{}" \;
- find static -type f -exec install -v -D "{}" "{{prefix}}/conf/{}" \;
- find openapi -type f -exec install -v -D "{}" "{{prefix}}/conf/{}" \;

provides:
- bin/sftpgo
Expand Down
105 changes: 71 additions & 34 deletions projects/sftpgo.com/setup.bash
Original file line number Diff line number Diff line change
@@ -1,46 +1,83 @@
#!/usr/bin/env -S pkgx +gnu.org/coreutils +bash^5 bash
#!/usr/bin/env -S pkgx +gnu.org/coreutils +gomplate.ca +bash^5 bash

function install_files {
command install -v -D -b \
"${package_conf_path}/${app_conf_file}" \
"${app_conf_path}/${app_conf_file}"
# command gomplate --verbose \
# --file "${package_conf_path}/${app_environment_file}.gtpl" \
# --out "${app_conf_path}/${app_environment_file}"
command gomplate --verbose \
--file "${package_conf_path}/${service_file}.gtpl" \
--out "${services_path}/${service_file}"

for subdir in templates openapi static; do
ln -v -s "${package_conf_path}/${subdir}" \
"${app_conf_path}"
done
chown -R "${app_username}:${app_username}" \
"${app_homedir}"
}

function setup_on_linux {
declare -rx app_homedir="/home/${app_username}"
declare -rx app_conf_path="${app_homedir}/app/sftpgo/conf"
declare -r service_file='sftpgo.service'
declare -r services_path='/etc/systemd/system'

if [[ -d /run/systemd/system ]]; then
useradd -m \
-d "${app_homedir}" \
"${app_username}"

install_files
else
echo 'Only systemd supported yet on Linux'
fi
}

function setup_on_darwin {
declare -rx app_homedir="/Users/${app_username}"
declare -rx app_conf_path="${app_homedir}/app/sftpgo/conf"
declare -r service_file='com.sftpgo.plist'
declare -r services_path='/Library/LaunchDaemons'

sysadminctl -addUser \
-home "${app_homedir}" \
"${app_username}"

install_files
}

function main {
declare -r script_file_path="$( realpath "${BASH_SOURCE[0]}" )"
declare -r package_bin_path="$( dirname "${script_file_path}" )"
declare -r package_path="$( dirname "${package_bin_path}" )"
declare -r package_version="${package_path#*/v}"
declare -r package_etc_path="${package_path}/etc"
declare -r system_etc_path='/etc'

declare -r username="_sftpgo"
declare -r homedir="/home/${username}"
declare -r environment_file='sftpgo/sftpgo.env'
declare -r config_file='sftpgo/sftpgo.json'
declare -r systemd_service_file='systemd/system/sftpgo.service'
declare -r setup_script_file_path="$( realpath "${BASH_SOURCE[0]}" )"
declare -r setup_script_dir_path="$( dirname "${setup_script_file_path}" )"
declare -r setup_script_pkgx_path="$( dirname "${setup_script_dir_path}" )"
declare -rx package_version="${setup_script_pkgx_path#*/v}"
declare -r package_project_path="$( dirname "${setup_script_pkgx_path}" )"
declare -rx package_project="$( basename "${package_project_path}" )"

declare -r package_bin_path="$(
sudo -u _sftpgo pkgx +${package_project}^${package_version} \
| cut -d= -f2 \
| cut -d$ -f1 \
| tr -d \"
)"
declare -r package_path="$( dirname "${package_bin_path}" )"
declare -r package_conf_path="${package_path}/conf"
declare -r app_username="_sftpgo"
# declare -r app_environment_file='sftpgo.env'
declare -r app_conf_file='sftpgo.json'

printf 'Package directory %s\n' ${package_path}

case "$(uname)" in
Linux)
if [[ -d /run/systemd/system ]]; then
useradd -m -d "${homedir}" "${username}"
install -v -D -b \
"${package_etc_path}/${environment_file}" \
"${system_etc_path}/${environment_file}"
sed -i "s/^PKGX_SFTPGO_VERSION=.*$/PKGX_SFTPGO_VERSION=${package_version}/" \
"${system_etc_path}/${environment_file}"
install -v -D -b \
"${package_etc_path}/${config_file}" \
"${system_etc_path}/${config_file}"
install -v -D \
"${package_etc_path}/${systemd_service_file}" \
"${system_etc_path}/${systemd_service_file}"
for subdir in templates openapi static; do
ln -v -s "${package_path}/${subdir}" "${homedir}/${subdir}"
done
else
echo 'Only systemd supported yet'
fi
setup_on_linux
;;
Darwin)
echo 'Not managed yet on darwin'
;;
setup_on_darwin
;;
*)
echo 'OS not supported'
;;
Expand Down
4 changes: 0 additions & 4 deletions projects/sftpgo.com/sftpgo.env

This file was deleted.

4 changes: 4 additions & 0 deletions projects/sftpgo.com/sftpgo.env.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PKGX_SFTPGO_PROJECT='{{ getenv "package_project" "SETUP_ERROR" }}'
PKGX_SFTPGO_VERSION='{{ getenv "package_version" "SETUP_ERROR" }}'

SFTPGO_CONFIG_DIR='{{ getenv "app_conf_path" "SETUP_ERROR" }}'
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ After=network.target
Type=simple
User=_sftpgo
Group=_sftpgo
EnvironmentFile=/etc/sftpgo/sftpgo.env
ExecStart=/bin/bash -c "/usr/local/bin/pkgx +${PKGX_SFTPGO_PROJECT}^${PKGX_SFTPGO_VERSION} sftpgo serve --config-file ${SFTPGO_CONFIG_FILE} --config-dir=${HOME}"
ExecStart=/usr/local/bin/pkgx +{{
getenv "package_project" "SETUP_ERROR"
}}^{{
getenv "package_version" "SETUP_ERROR"
}} sftpgo serve --config-dir {{
getenv "app_conf_path" "SETUP_ERROR"
}}
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=8192
KillMode=mixed
Expand Down