diff --git a/Dockerfile b/Dockerfile index b6fc5b0..b438d11 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM debian:bookworm-slim +FROM debian:forky-slim + +# Suppress "unable to initialize frontend: Dialog" errors +ENV DEBIAN_FRONTEND=noninteractive # Create the directory in which the scripts will be stored RUN mkdir -p /opt/Nextcloud/log @@ -8,6 +11,10 @@ RUN apt update \ && apt -y upgrade \ && apt install -yq --no-install-recommends \ moreutils \ + mc \ + nano \ + locales \ + locales-all \ && apt clean \ && apt -y autoremove \ && rm -rf \ @@ -25,6 +32,7 @@ RUN apt update \ && apt install -yq --no-install-recommends \ openssl \ ca-certificates \ + procps \ nextcloud-desktop-cmd \ && apt upgrade -y \ && apt-get clean \ @@ -39,12 +47,24 @@ RUN apt update \ /usr/share/info \ /usr/share/lintian -COPY *.sh /opt/Nextcloud/ +RUN locale-gen C.UTF-8 + +RUN echo 'alias ll="ls -l"\ alias ll="ls -l --color"\' >> ~/.bashrc + +COPY docker-entrypoint.sh /opt/Nextcloud/ +COPY run.sh /opt/Nextcloud/ +COPY ini /root/.config/mc/ + WORKDIR /nextclouddata ENTRYPOINT ["/bin/bash","/opt/Nextcloud/docker-entrypoint.sh"] CMD ["/bin/bash", "/opt/Nextcloud/run.sh"] +ENV LANG C.UTF-8 +ENV LC_ALL C.UTF-8 +ENV LC_TIME=C.UTF-8 +ENV LANGUAGE=C.UTF-8 + ENV NEXTCLOUD_USER=NEXTCLOUD_username \ NEXTCLOUD_PASS=NEXTCLOUD_passwordORtoken \ NEXTCLOUD_SERVER=yourserver.com \ @@ -55,6 +75,7 @@ ENV NEXTCLOUD_USER=NEXTCLOUD_username \ TRUST_SELFSIGN=0 \ SYNC_HIDDEN=0 \ SILENCE_OUTPUT=1 \ - RUN_INTERVAL=30 \ - RUN_UID=99 \ - RUN_GID=100 + RUN_INTERVAL=120 \ + DEBUG=0 \ + RUN_UID=9001 \ + RUN_GID=9001 diff --git a/docker-compose.yml b/docker-compose.yml index 633b9c5..f7f9122 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,19 +1,33 @@ -occlient: - image: dyonr/nextcloudcmd-client - volumes: - - ${PWD}/mydata:/nextclouddata - environment: - - NEXTCLOUD_USER=myuser - - NEXTCLOUD_PASS=mypass - - NEXTCLOUD_PROTO=https - - NEXTCLOUD_SERVER=myocserver.com - - NEXTCLOUD_URLPATH=/ - - NEXTCLOUD_WEBDAV=remote.php/webdav - - NEXTCLOUD_FILEPATH=/ - - TRUST_SELFSIGN=0 - - SYNC_HIDDEN=0 - - SILENCE_OUTPUT=1 - - RUN_INTERVAL=30 - - RUN_UID=99 - - RUN_GID=100 +services: + occlient: + container_name: occlient + image: nextcloudcmd-client + env_file: ".env" + logging: + driver: journald + options: + max-size: "50mb" + volumes: + - ${VOLUME_MAPPING:-/home:/home} + - /opt/Nextcloud/log:/opt/Nextcloud/log + - /etc/localtime:/etc/localtime:ro + environment: + - NEXTCLOUD_USER=${NEXTCLOUD_USER:-admin} + - NEXTCLOUD_PASS=${NEXTCLOUD_PASS:-none} + - NEXTCLOUD_PROTO=${NEXTCLOUD_PROTO:-https} + - NEXTCLOUD_SERVER=${NEXTCLOUD_SERVER:-www.nextcloud.com} + - NEXTCLOUD_URLPATH=${NEXTCLOUD_URLPATH:-/} + - NEXTCLOUD_WEBDAV=${NEXTCLOUD_WEBDAV:-""} + - NEXTCLOUD_FILEPATH=${NEXTCLOUD_FILEPATH:-/} + - TRUST_SELFSIGN=${TRUST_SELFSIGN:-0} + - SYNC_HIDDEN=${SYNC_HIDDEN:-0} + - SILENCE_OUTPUT=${SILENCE_OUTPUT:-0} + - RUN_INTERVAL=${RUN_INTERVAL:-120} + - DEBUG=${DEBUG:-0} + - RUN_UID=${RUN_UID:-9001} + - RUN_GID=${RUN_GID:-9001} + + restart: always + + network_mode: "host" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 9bbdb12..2973f15 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,35 +1,48 @@ #!/bin/bash # Check if the PGID exists, if not create the group with the name 'nextcloudclient' -getent group "$RUN_GID" > /dev/null 2>&1 +/usr/bin/getent group "$RUN_GID" > /dev/null 2>&1 if [ $? -eq 0 ]; then - echo "[INFO] A group with PGID $RUN_GID already exists in /etc/group, nothing to do." | ts '%Y-%m-%d %H:%M:%.S' + echo "[INFO] A group with PGID $RUN_GID already exists in /etc/group, nothing to do." | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' else - echo "[INFO] A group with PGID $RUN_GID does not exist, adding a group called 'nextcloudclient' with PGID $RUN_GID" | ts '%Y-%m-%d %H:%M:%.S' - groupadd -g $RUN_GID nextcloudclient + echo "[INFO] A group with PGID $RUN_GID does not exist, adding a group called 'nextcloudclient' with PGID $RUN_GID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + /usr/sbin/groupadd -g $RUN_GID nextcloudclient fi # Check if the PUID exists, if not create the user with the name 'nextcloudclient', with the correct group -getent passwd "$RUN_UID" > /dev/null 2>&1 +/usr/bin/getent passwd "$RUN_UID" > /dev/null 2>&1 if [ $? -eq 0 ]; then - echo "[INFO] An user with PUID $RUN_UID already exists in /etc/passwd, nothing to do." | ts '%Y-%m-%d %H:%M:%.S' + echo "[INFO] An user with PUID $RUN_UID already exists in /etc/passwd, nothing to do." | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' else - echo "[INFO] An user with PUID $RUN_UID does not exist, adding an user called 'nextcloudclient user' with PUID $RUN_UID" | ts '%Y-%m-%d %H:%M:%.S' - useradd --comment "nextcloudclient user" --gid $RUN_GID --uid $RUN_UID --create-home --shell /bin/bash nextcloudclient + echo "[INFO] An user with PUID $RUN_UID does not exist, adding an user called 'nextcloudclient user' with PUID $RUN_UID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + /usr/sbin/useradd --comment "nextcloudclient user" --gid $RUN_GID --uid $RUN_UID --create-home --shell /bin/bash nextcloudclient fi - +# If we end up with a \n in the file it will complain +netrc_tmp="/home/nextcloudclient/.netrctmp" netrc_file="/home/nextcloudclient/.netrc" -nextcloud_server_without_port=$(echo $NEXTCLOUD_SERVER | sed 's/\(.*\):.*/\1/') -cat < $netrc_file -machine $nextcloud_server_without_port - login $NEXTCLOUD_USER - password $NEXTCLOUD_PASS +nextcloud_server_without_port=$(echo $NEXTCLOUD_SERVER | /usr/bin/sed 's/\(.*\):.*/\1/') +/usr/bin/cat < $netrc_tmp +machine $nextcloud_server_without_port login $NEXTCLOUD_USER password $NEXTCLOUD_PASS EOF -chown $RUN_UID:$RUN_GID $netrc_file -chmod 600 $netrc_file +/usr/bin/tr -d "\n" < $netrc_tmp > $netrc_file +/usr/bin/rm $netrc_tmp + +/usr/bin/sed -i '1s/^/LANG="C.UTF-8"\nexport "LANG"\n/' /home/nextcloudclient/.bashrc + +/usr/bin/chown $RUN_UID:$RUN_GID $netrc_file +/usr/bin/chmod 600 $netrc_file + +echo "[INFO] Changing ownership of all files and directories in /nextclouddata and /opt/Nextcloud/log to $RUN_UID:$RUN_GID" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + +#SETUP PATHS +NC_PATH=(${NEXTCLOUD_FILEPATH}) +for ((i = 0; i <= COUNT; i++)); do + FILEPATH=${NC_PATH[${i}]} + /usr/bin/chgrp -R $RUN_GID /nextclouddata/$FILEPATH/ +done + -echo "[INFO] Changing ownership of all files and directories in /nextclouddata and /opt/Nextcloud/log to $RUN_UID:$RUN_GID" | ts '%Y-%m-%d %H:%M:%.S' -chown -R $RUN_UID:$RUN_GID /nextclouddata /opt/Nextcloud/log +/usr/bin/chown -R $RUN_UID:$RUN_GID /opt/Nextcloud/log exec $@ diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..d4e7e1a --- /dev/null +++ b/env.sample @@ -0,0 +1,19 @@ +NEXTCLOUD_USER= +NEXTCLOUD_PASS= +NEXTCLOUD_PROTO=https +NEXTCLOUD_SERVER= +NEXTCLOUD_URLPATH=/ +NEXTCLOUD_WEBDAV="" +NEXTCLOUD_FILEPATH="dir1 dir2" +UPLIMIT=1024 +DOWNLIMIT=1024 +TRANSFERLIMIT=0 +VOLUME_MAPPING=/host/dir:/nextclouddata +TRUST_SELFSIGN=0 +SYNC_HIDDEN=0 +SILENCE_OUTPUT=0 +RUN_INTERVAL=20 +JOB_INTERVAL=20 +DEBUG=0 +RUN_UID=9001 +RUN_GID=9001 diff --git a/ini b/ini new file mode 100644 index 0000000..21e440c --- /dev/null +++ b/ini @@ -0,0 +1,158 @@ +[Midnight-Commander] +verbose=true +shell_patterns=true +auto_save_setup=true +preallocate_space=false +auto_menu=false +use_internal_view=true +use_internal_edit=true +clear_before_exec=true +confirm_delete=true +confirm_overwrite=true +confirm_execute=false +confirm_history_cleanup=true +confirm_exit=false +confirm_directory_hotlist_delete=false +confirm_view_dir=false +safe_delete=false +use_8th_bit_as_meta=false +mouse_move_pages_viewer=true +mouse_close_dialog=false +fast_refresh=false +drop_menus=false +wrap_mode=true +old_esc_mode=true +cd_symlinks=true +show_all_if_ambiguous=false +use_file_to_guess_type=true +alternate_plus_minus=false +only_leading_plus_minus=true +show_output_starts_shell=false +xtree_mode=false +file_op_compute_totals=true +classic_progressbar=true +use_netrc=true +ftpfs_always_use_proxy=false +ftpfs_use_passive_connections=true +ftpfs_use_passive_connections_over_proxy=false +ftpfs_use_unix_list_options=true +ftpfs_first_cd_then_ls=true +ignore_ftp_chattr_errors=true +editor_fill_tabs_with_spaces=false +editor_return_does_auto_indent=true +editor_backspace_through_tabs=false +editor_fake_half_tabs=true +editor_option_save_position=true +editor_option_auto_para_formatting=false +editor_option_typewriter_wrap=false +editor_edit_confirm_save=true +editor_syntax_highlighting=false +editor_persistent_selections=true +editor_drop_selection_on_copy=true +editor_cursor_beyond_eol=false +editor_cursor_after_inserted_block=false +editor_visible_tabs=true +editor_visible_spaces=true +editor_line_state=false +editor_simple_statusbar=false +editor_check_new_line=false +editor_show_right_margin=false +editor_group_undo=false +editor_state_full_filename=false +editor_ask_filename_before_edit=false +nice_rotating_dash=true +mcview_remember_file_position=false +auto_fill_mkdir_name=true +copymove_persistent_attr=true +pause_after_run=1 +mouse_repeat_rate=100 +double_click_speed=250 +old_esc_mode_timeout=1000000 +max_dirt_limit=10 +num_history_items_recorded=60 +vfs_timeout=60 +ftpfs_directory_timeout=900 +ftpfs_retry_seconds=30 +fish_directory_timeout=900 +editor_tab_spacing=8 +editor_word_wrap_line_length=72 +editor_option_save_mode=0 +editor_backup_extension=~ +editor_filesize_threshold=64M +editor_stop_format_chars=-+*\\,.;:&> +mcview_eof= +skin=default + +filepos_max_saved_entries=1024 + +[Layout] +message_visible=1 +keybar_visible=1 +xterm_title=1 +output_lines=0 +command_prompt=1 +menubar_visible=1 +free_space=1 +horizontal_split=0 +vertical_equal=1 +left_panel_size=181 +horizontal_equal=1 +top_panel_size=1 + +[Misc] +timeformat_recent=%b %e %H:%M +timeformat_old=%b %e %Y +ftp_proxy_host=gate +ftpfs_password=anonymous@ +display_codepage=UTF-8 +source_codepage=Other_8_bit +autodetect_codeset= +spell_language=en +clipboard_store= +clipboard_paste= + +[Colors] +base_color= +xterm-256color= +color_terminals= + +linux= + +[Panels] +show_mini_info=true +kilobyte_si=false +mix_all_files=false +show_backups=true +show_dot_files=true +fast_reload=false +fast_reload_msg_shown=false +mark_moves_down=true +reverse_files_only=true +auto_save_setup_panels=false +navigate_with_arrows=false +panel_scroll_pages=true +panel_scroll_center=false +mouse_move_pages=true +filetype_mode=true +permission_mode=false +torben_fj_mode=false +quick_search_mode=2 +select_flags=6 + +[DiffView] +show_symbols=false +show_numbers=false +tab_size=8 +diff_quality=0 +diff_ignore_tws=false +diff_ignore_all_space=false +diff_ignore_space_change=false +diff_tab_expansion=false +diff_ignore_case=false + +[Panelize] +Find *.orig after patching=find . -name \\*.orig -print +Find SUID and SGID programs=find . \\( \\( -perm -04000 -a -perm /011 \\) -o \\( -perm -02000 -a -perm /01 \\) \\) -print +Find rejects after patching=find . -name \\*.rej + + diff --git a/run.sh b/run.sh index 6ecf57d..8b47080 100644 --- a/run.sh +++ b/run.sh @@ -2,27 +2,81 @@ set -e # check if we should trust selfsigned certificates -if [ "$TRUST_SELFSIGN" -eq 1 ]; then - echo "[INFO] TRUST_SELFSIGN is set to $TRUST_SELFSIGN, setting run parameter '--trust'" | ts '%Y-%m-%d %H:%M:%.S' - SELFSIGN="--trust" +if [[ "$TRUST_SELFSIGN" -eq 1 ]]; then + echo "[INFO] TRUST_SELFSIGN is set to $TRUST_SELFSIGN, setting run parameter '--trust'" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + SELFSIGN="--trust" fi # check if we should sync hidden files -if [ "$SYNC_HIDDEN" -eq 1 ]; then - echo "[INFO] SYNC_HIDDEN is set to $SYNC_HIDDEN, setting run parameter '-h'" | ts '%Y-%m-%d %H:%M:%.S' - SYNCHIDDEN='-h' +if [[ "$SYNC_HIDDEN" -eq 1 ]]; then + echo "[INFO] SYNC_HIDDEN is set to $SYNC_HIDDEN, setting run parameter '-h'" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + SYNCHIDDEN='-h' fi # check if we should silence output -if [ "$SILENCE_OUTPUT" -eq 1 ]; then - echo "[INFO] SILENCE_OUTPUT is set to $SILENCE_OUTPUT, setting run parameter '--silent'" | ts '%Y-%m-%d %H:%M:%.S' - SILENCEOUTPUT='--silent' +if [[ "$SILENCE_OUTPUT" -eq 1 ]]; then + echo "[INFO] SILENCE_OUTPUT is set to $SILENCE_OUTPUT, setting run parameter '--silent'" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + SILENCEOUTPUT='--silent' fi -echo "[INFO] Running nextcloudcmd as following:" | ts '%Y-%m-%d %H:%M:%.S' -echo "[INFO] nextcloudcmd $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -n --non-interactive /nextclouddata $NEXTCLOUD_PROTO://$NEXTCLOUD_SERVER$NEXTCLOUD_URLPATH$NEXTCLOUD_WEBDAV$NEXTCLOUD_FILEPATH" | ts '%Y-%m-%d %H:%M:%.S' -while true -do - su - nextcloudclient -c "nextcloudcmd $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -n --non-interactive /nextclouddata $NEXTCLOUD_PROTO://$NEXTCLOUD_SERVER$NEXTCLOUD_URLPATH$NEXTCLOUD_WEBDAV$NEXTCLOUD_FILEPATH &> /opt/Nextcloud/log/latest.log" - sleep $RUN_INTERVAL +if [[ "$DEBUG" -eq 1 ]]; then + echo "[INFO] DEBUG = $DEBUG, setting --logdebug" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + DEBUG='--logdebug' + SILENCEOUTPUT='' +else + DEBUG='' +fi + +if [[ "$TRANSFERLIMIT" -eq 1 ]]; then + echo "[INFO] TRANSFERLIMIT enabled --uplimit $UPLIMIT --downlimit $DOWNLIMIT" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + UP="--uplimit $UPLIMIT" + DOWN="--downlimit $DOWNLIMIT" +else + UP="--uplimit 0" + DOWN="--downlimit 0" +fi + +#SETUP PATHS +PATH=(${NEXTCLOUD_FILEPATH}) + +echo "[INFO] Starting nextcloudclient " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + +while true; do + if [[ "$DEBUG" -eq 1 ]]; then + echo "[INFO] running script " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + fi + + # Is client running? Make sure we aren't doubling up. + if [[ ! -z "$(/usr/bin/ps -C nextcloudcmd --no-headers -o "pid,ppid,sid,comm" | /usr/bin/grep -v "$$ " | /usr/bin/grep -v "")" ]]; then + echo "[INFO] client is already running " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + else + echo "[INFO] client isn't running - starting" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + + # We have two formats for copying + + # This is for standard password https://user:pass@ncServer + #echo "[INFO] executing nextcloudcmd $DEBUG $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -n --non-interactive --path $FILEPATH /nextclouddata $NEXTCLOUD_PROTO://$NEXTCLOUD_USER:PassWord@$NEXTCLOUD_SERVER " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + #su - nextcloudclient -c "nextcloudcmd $DEBUG $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -n --non-interactive --path $FILEPATH /nextclouddata $NEXTCLOUD_PROTO://$NEXTCLOUD_USER:$NEXTCLOUD_PASS@$NEXTCLOUD_SERVER &> /opt/Nextcloud/log/latest.log" + + # Number of dir in array + COUNT=${#PATH[@]} + # Decrement by one as the array starts at 0 + COUNT=$((COUNT - 1)) + + for ((i = 0; i <= COUNT; i++)); do + FILEPATH=${PATH[${i}]} + #echo "This many $COUNT" + echo "[INFO]Executing path $FILEPATH" + # This is -u user -p password https://ncServer + echo "[INFO] executing nextcloudcmd $DEBUG $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -u $NEXTCLOUD_USER -p PassKey $UP $DOWN -n --non-interactive --path /$FILEPATH /nextclouddata/$FILEPATH $NEXTCLOUD_PROTO://$NEXTCLOUD_SERVER " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + /usr/bin/su - nextcloudclient -c "nextcloudcmd $DEBUG $SELFSIGN $SYNCHIDDEN $SILENCEOUTPUT -u $NEXTCLOUD_USER -p $NEXTCLOUD_PASS $UP $DOWN -n --non-interactive --path /$FILEPATH /nextclouddata/$FILEPATH $NEXTCLOUD_PROTO://$NEXTCLOUD_SERVER &>> /opt/Nextcloud/log/latest.log" + echo "[INFO] $FILEPATH client completed" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + /usr/bin/sleep $JOB_INTERVAL + done + fi + + echo "[INFO] complete waiting for $RUN_INTERVAL secs " | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + /usr/bin/sleep $RUN_INTERVAL + echo "[INFO] Wait over!" | /usr/bin/ts '%Y-%m-%d %H:%M:%.S' + echo "" done