diff --git a/src/freedombone-utils-dns b/src/freedombone-utils-dns index 7dc3bb39..cd726d04 100755 --- a/src/freedombone-utils-dns +++ b/src/freedombone-utils-dns @@ -131,7 +131,7 @@ function create_freedns_updater { } function add_ddns_domain { - if [ ! $1 ]; then + if [ ! "$1" ]; then echo $'ddns domain not specified' exit 5638 fi @@ -147,10 +147,10 @@ function add_ddns_domain { exit 5745 fi if ! grep -q "$DDNS_PROVIDER" /etc/inadyn.conf; then - echo '' >> /etc/inadyn.conf - echo "system $DDNS_PROVIDER" >> /etc/inadyn.conf - echo ' ssl' >> /etc/inadyn.conf - echo " checkip-url $GET_IP_ADDRESS_URL /" >> /etc/inadyn.conf + { echo ''; + echo "system $DDNS_PROVIDER"; + echo ' ssl'; + echo " checkip-url $GET_IP_ADDRESS_URL /"; } >> /etc/inadyn.conf if [ $DDNS_USERNAME ]; then echo " username $DDNS_USERNAME" >> /etc/inadyn.conf fi @@ -168,7 +168,7 @@ function add_ddns_domain { } function remove_ddns_domain { - if [ ! $1 ]; then + if [ ! "$1" ]; then echo $'ddns domain not specified' exit 5638 fi @@ -203,14 +203,14 @@ function configure_dns { # allow changes to resolv.conf chattr -i $resolvconf - echo 'domain localdomain' > $resolvconf - echo 'search localdomain' >> $resolvconf - echo "nameserver $NAMESERVER1" >> $resolvconf - echo "nameserver $NAMESERVER2" >> $resolvconf - echo "nameserver $NAMESERVER3" >> $resolvconf - echo "nameserver $NAMESERVER4" >> $resolvconf - echo "nameserver $NAMESERVER5" >> $resolvconf - echo "nameserver $NAMESERVER6" >> $resolvconf + { echo 'domain localdomain'; + echo 'search localdomain'; + echo "nameserver $NAMESERVER1"; + echo "nameserver $NAMESERVER2"; + echo "nameserver $NAMESERVER3"; + echo "nameserver $NAMESERVER4"; + echo "nameserver $NAMESERVER5"; + echo "nameserver $NAMESERVER6"; } > $resolvconf # prevent resolv.conf from changing resolvconf -u @@ -222,7 +222,7 @@ function set_hostname { DEFAULT_DOMAIN_NAME="$1" echo "$DEFAULT_DOMAIN_NAME" > /etc/hostname - hostname $DEFAULT_DOMAIN_NAME + hostname "$DEFAULT_DOMAIN_NAME" echo "$DEFAULT_DOMAIN_NAME" > /etc/mailname if grep -q "127.0.1.1" /etc/hosts; then @@ -238,7 +238,7 @@ function set_your_domain_name { fi function_check set_hostname - set_hostname $DEFAULT_DOMAIN_NAME + set_hostname "$DEFAULT_DOMAIN_NAME" mark_completed "${FUNCNAME[0]}" } diff --git a/src/freedombone-utils-filesystem b/src/freedombone-utils-filesystem index 8712abd9..3a708882 100755 --- a/src/freedombone-utils-filesystem +++ b/src/freedombone-utils-filesystem @@ -32,44 +32,45 @@ TOMB_REPO="https://github.com/dyne/Tomb" TOMB_COMMIT='c80ebd6d6ed77980eb5b559757e03ea13a29bdd1' function mesh_install_tomb { - chroot ${rootdir} apt-get -yq install cryptsetup zsh pinentry-curses + # shellcheck disable=SC2154 + chroot "${rootdir}" apt-get -yq install cryptsetup zsh pinentry-curses - if [ ! -d ${rootdir}/$INSTALL_DIR ]; then - mkdir -p ${rootdir}/$INSTALL_DIR + if [ ! -d "${rootdir}/$INSTALL_DIR" ]; then + mkdir -p "${rootdir}/$INSTALL_DIR" fi if [ -d /repos/tomb ]; then - mkdir ${rootdir}/$INSTALL_DIR/tomb - cp -r -p /repos/tomb/. ${rootdir}/$INSTALL_DIR/tomb - cd ${rootdir}/$INSTALL_DIR/tomb + mkdir "${rootdir}/$INSTALL_DIR/tomb" + cp -r -p /repos/tomb/. "${rootdir}/$INSTALL_DIR/tomb" + cd "${rootdir}/$INSTALL_DIR/tomb" || exit 3648368 git pull else - git_clone $TOMB_REPO ${rootdir}/$INSTALL_DIR/tomb + git_clone "$TOMB_REPO" "${rootdir}/$INSTALL_DIR/tomb" fi - cd ${rootdir}/$INSTALL_DIR/tomb + cd "${rootdir}/$INSTALL_DIR/tomb" || exit 7346384 git checkout $TOMB_COMMIT -b $TOMB_COMMIT - chroot ${rootdir} /bin/bash -x <> /home/$MY_USERNAME/.bashrc + if ! grep -q 'controluser' "/home/$MY_USERNAME/.bashrc"; then + echo 'controluser' >> "/home/$MY_USERNAME/.bashrc" fi - if [ ! -f $IMAGE_PASSWORD_FILE ]; then - if [ -f /root/${PROJECT_NAME}-wifi.cfg ]; then + if [ ! -f "$IMAGE_PASSWORD_FILE" ]; then + if [ -f "/root/${PROJECT_NAME}-wifi.cfg" ]; then create_wifi_startup_script echo '' echo $'Shutting down the system. Detatch the ethernet cable, attach wifi dongle, then power on again.' echo '' - ${PROJECT_NAME}-logging off --restart + "${PROJECT_NAME}-logging" off --restart systemctl poweroff return fi echo $'Turning off logging' - ${PROJECT_NAME}-logging off --restart + "${PROJECT_NAME}-logging" off --restart echo $'Rebooting the system' systemctl reboot -i fi echo $'Turning off logging' - ${PROJECT_NAME}-logging off --restart + "${PROJECT_NAME}-logging" off --restart } function update_installed_apps_list { # Why does this secondary file exist, apart from COMPLETION_FILE ? # It's so that it is visible to unprivileged users from the user control panel - cat $COMPLETION_FILE | grep "install_" > /usr/share/${PROJECT_NAME}/installed.txt + grep "install_" "$COMPLETION_FILE" > "/usr/share/${PROJECT_NAME}/installed.txt" } function create_default_user_removal_daemon { @@ -96,31 +96,31 @@ function create_default_user_removal_daemon { first_start_daemon_filename=/etc/systemd/system/firststart.service first_start_script=/usr/local/bin/firststart - echo '#!/bin/bash' > $first_start_script - echo 'if [ -d /home/fbone]; then' >> $first_start_script - echo ' userdel -r fbone' >> $first_start_script - echo ' if [ -d /home/fbone]; then' >> $first_start_script - echo ' rm -rf /home/fbone' >> $first_start_script - echo ' fi' >> $first_start_script - echo 'fi' >> $first_start_script - echo 'systemctl disable firststart' >> $first_start_script - echo "rm $first_start_daemon_filename" >> $first_start_script + { echo '#!/bin/bash'; + echo 'if [ -d /home/fbone]; then'; + echo ' userdel -r fbone'; + echo ' if [ -d /home/fbone]; then'; + echo ' rm -rf /home/fbone'; + echo ' fi'; + echo 'fi'; + echo 'systemctl disable firststart'; + echo "rm $first_start_daemon_filename"; } > $first_start_script chmod +x $first_start_script - echo '[Unit]' > $first_start_daemon_filename - echo 'Description=Daemon run on first boot' >> $first_start_daemon_filename - echo 'After=syslog.target' >> $first_start_daemon_filename - echo 'After=network.target' >> $first_start_daemon_filename - echo '' >> $first_start_daemon_filename - echo '[Service]' >> $first_start_daemon_filename - echo 'User=root' >> $first_start_daemon_filename - echo 'Group=root' >> $first_start_daemon_filename - echo "ExecStart=$first_start_script" >> $first_start_daemon_filename - echo 'StandardOutput=syslog' >> $first_start_daemon_filename - echo 'StandardError=syslog' >> $first_start_daemon_filename - echo '' >> $first_start_daemon_filename - echo '[Install]' >> $first_start_daemon_filename - echo 'WantedBy=multi-user.target' >> $first_start_daemon_filename + { echo '[Unit]'; + echo 'Description=Daemon run on first boot'; + echo 'After=syslog.target'; + echo 'After=network.target'; + echo ''; + echo '[Service]'; + echo 'User=root'; + echo 'Group=root'; + echo "ExecStart=$first_start_script"; + echo 'StandardOutput=syslog'; + echo 'StandardError=syslog'; + echo ''; + echo '[Install]'; + echo 'WantedBy=multi-user.target'; } > $first_start_daemon_filename systemctl enable firststart } diff --git a/src/freedombone-utils-firewall b/src/freedombone-utils-firewall index 2b70d31a..fc95b87f 100755 --- a/src/freedombone-utils-firewall +++ b/src/freedombone-utils-firewall @@ -47,7 +47,7 @@ function save_firewall_settings { } function firewall_block_bad_ip_ranges { - if [ $INSTALLING_MESH ]; then + if [ "$INSTALLING_MESH" ]; then return fi if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then @@ -135,13 +135,13 @@ function firewall_enable_vpn { } function configure_firewall { - if [ $INSTALLING_MESH ]; then + if [ "$INSTALLING_MESH" ]; then mesh_firewall return fi if grep -q "RELATED" /etc/firewall.conf; then # recreate the firewall to remove RELATED - sed -i "/firewall/d" $COMPLETION_FILE + sed -i "/firewall/d" "$COMPLETION_FILE" fi if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then return @@ -276,10 +276,10 @@ function configure_internet_protocol { echo 'net.ipv4.tcp_syn_retries = 1' >> /etc/sysctl.conf fi if ! grep -q "keepalive" /etc/sysctl.conf; then - echo '# keepalive' >> /etc/sysctl.conf - echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf - echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf - echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf + { echo '# keepalive'; + echo 'net.ipv4.tcp_keepalive_probes = 9'; + echo 'net.ipv4.tcp_keepalive_intvl = 75'; + echo 'net.ipv4.tcp_keepalive_time = 7200'; } >> /etc/sysctl.conf fi if ! grep -q "net.ipv4.conf.default.send_redirects" /etc/sysctl.conf; then echo "net.ipv4.conf.default.send_redirects = 0" >> /etc/sysctl.conf @@ -335,103 +335,100 @@ function configure_internet_protocol { } function mesh_firewall { - FIREWALL_FILENAME=${rootdir}/etc/systemd/system/meshfirewall.service + # shellcheck disable=SC2154 + FIREWALL_FILENAME="${rootdir}/etc/systemd/system/meshfirewall.service" MESH_FIREWALL_SCRIPT=${rootdir}/usr/bin/mesh-firewall - echo '#!/bin/bash' > $MESH_FIREWALL_SCRIPT - echo 'iptables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -P INPUT ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -F' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -F' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -t nat -F' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -t nat -F' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -X' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -X' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -P INPUT DROP' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -i lo -j ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT' >> $MESH_FIREWALL_SCRIPT - echo '' >> $MESH_FIREWALL_SCRIPT - echo '# Make sure incoming tcp connections are SYN packets' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP' >> $MESH_FIREWALL_SCRIPT - echo '' >> $MESH_FIREWALL_SCRIPT - echo '# Drop packets with incoming fragments' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -f -j DROP' >> $MESH_FIREWALL_SCRIPT - echo '' >> $MESH_FIREWALL_SCRIPT - echo '# Drop bogons' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP' >> $MESH_FIREWALL_SCRIPT - echo '' >> $MESH_FIREWALL_SCRIPT - echo '# Incoming malformed NULL packets:' >> $MESH_FIREWALL_SCRIPT - echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT - echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP' >> $MESH_FIREWALL_SCRIPT - echo '' >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "iptables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - echo "ip6tables -A INPUT -p udp --dport 1900 -j ACCEPT" >> $MESH_FIREWALL_SCRIPT - chmod +x $MESH_FIREWALL_SCRIPT + { echo '#!/bin/bash'; + echo 'iptables -P INPUT ACCEPT'; + echo 'ip6tables -P INPUT ACCEPT'; + echo 'iptables -F'; + echo 'ip6tables -F'; + echo 'iptables -t nat -F'; + echo 'ip6tables -t nat -F'; + echo 'iptables -X'; + echo 'ip6tables -X'; + echo 'iptables -P INPUT DROP'; + echo 'ip6tables -P INPUT DROP'; + echo 'iptables -A INPUT -i lo -j ACCEPT'; + echo 'ip6tables -A INPUT -i lo -j ACCEPT'; + echo 'iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT'; + echo 'ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT'; + echo ''; + echo '# Make sure incoming tcp connections are SYN packets'; + echo 'iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP'; + echo 'ip6tables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP'; + echo ''; + echo '# Drop packets with incoming fragments'; + echo 'iptables -A INPUT -f -j DROP'; + echo 'ip6tables -A INPUT -f -j DROP'; + echo ''; + echo '# Drop bogons'; + echo 'iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP'; + echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP'; + echo 'iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP'; + echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP'; + echo 'iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP'; + echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP'; + echo ''; + echo '# Incoming malformed NULL packets:'; + echo 'iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP'; + echo 'ip6tables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP'; + echo ''; + echo "iptables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT"; + echo "ip6tables -A INPUT -p tcp --dport $TOX_PORT -j ACCEPT"; + echo "iptables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT"; + echo "ip6tables -A INPUT -p udp --dport $ZERONET_PORT -j ACCEPT"; + echo "iptables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT"; + echo "ip6tables -A INPUT -p tcp --dport $ZERONET_PORT -j ACCEPT"; + echo "iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT"; + echo "ip6tables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT"; + echo "iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT"; + echo "ip6tables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT"; + echo "iptables -A INPUT -p udp --dport 1900 -j ACCEPT"; + echo "ip6tables -A INPUT -p udp --dport 1900 -j ACCEPT"; } > "$MESH_FIREWALL_SCRIPT" + chmod +x "$MESH_FIREWALL_SCRIPT" - echo '[Unit]' > $FIREWALL_FILENAME - echo 'Description=Mesh Firewall' >> $FIREWALL_FILENAME - echo '' >> $FIREWALL_FILENAME - echo '[Service]' >> $FIREWALL_FILENAME - echo 'Type=oneshot' >> $FIREWALL_FILENAME - echo 'ExecStart=/usr/bin/mesh-firewall' >> $FIREWALL_FILENAME - echo 'RemainAfterExit=no' >> $FIREWALL_FILENAME - echo '' >> $FIREWALL_FILENAME - echo 'TimeoutSec=30' >> $FIREWALL_FILENAME - echo '' >> $FIREWALL_FILENAME - echo '[Install]' >> $FIREWALL_FILENAME - echo 'WantedBy=multi-user.target' >> $FIREWALL_FILENAME - chmod +x $FIREWALL_FILENAME + { echo '[Unit]'; + echo 'Description=Mesh Firewall'; + echo ''; + echo '[Service]'; + echo 'Type=oneshot'; + echo 'ExecStart=/usr/bin/mesh-firewall'; + echo 'RemainAfterExit=no'; + echo ''; + echo 'TimeoutSec=30'; + echo ''; + echo '[Install]'; + echo 'WantedBy=multi-user.target'; } > "$FIREWALL_FILENAME" + chmod +x "$FIREWALL_FILENAME" chroot "$rootdir" systemctl enable meshfirewall } function firewall_add { - firewall_name=$(echo "$1" | sed "s| |-|g") + firewall_name=$(string="$1" ; echo "${string// /-}") firewall_port=$2 firewall_protocol="$3" - if ! grep -q "${firewall_name}=${firewall_port}" $FIREWALL_CONFIG; then - echo "${firewall_name}=${firewall_port}" >> $FIREWALL_CONFIG - if [ ! ${firewall_protocol} ]; then - iptables -C INPUT -p udp --dport ${firewall_port} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p udp --dport ${firewall_port} -j ACCEPT + if ! grep -q "${firewall_name}=${firewall_port}" "$FIREWALL_CONFIG"; then + echo "${firewall_name}=${firewall_port}" >> "$FIREWALL_CONFIG" + if [ ! "${firewall_protocol}" ]; then + if ! iptables -C INPUT -p udp --dport "${firewall_port}" -j ACCEPT; then + iptables -A INPUT -p udp --dport "${firewall_port}" -j ACCEPT fi - iptables -C INPUT -p tcp --dport ${firewall_port} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p tcp --dport ${firewall_port} -j ACCEPT + if ! iptables -C INPUT -p tcp --dport "${firewall_port}" -j ACCEPT; then + iptables -A INPUT -p tcp --dport "${firewall_port}" -j ACCEPT fi else if [[ "${firewall_protocol}" == *"udp"* ]]; then - iptables -C INPUT -p udp --dport ${firewall_port} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p udp --dport ${firewall_port} -j ACCEPT + if ! iptables -C INPUT -p udp --dport "${firewall_port}" -j ACCEPT; then + iptables -A INPUT -p udp --dport "${firewall_port}" -j ACCEPT fi fi if [[ "${firewall_protocol}" == *"tcp"* ]]; then - iptables -C INPUT -p tcp --dport ${firewall_port} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p tcp --dport ${firewall_port} -j ACCEPT + if ! iptables -C INPUT -p tcp --dport "${firewall_port}" -j ACCEPT; then + iptables -A INPUT -p tcp --dport "${firewall_port}" -j ACCEPT fi fi fi @@ -440,33 +437,29 @@ function firewall_add { } function firewall_add_range { - firewall_name=$(echo "$1" | sed "s| |-|g") + firewall_name=$(string="$1" ; echo "${string// /-}") firewall_port_start=$2 firewall_port_end=$3 firewall_protocol="$4" - if ! grep -q "${firewall_name}=${firewall_port_start}:${firewall_port_end}" $FIREWALL_CONFIG; then - echo "${firewall_name}=${firewall_port_start}:${firewall_port_end}" >> $FIREWALL_CONFIG - if [ ! ${firewall_protocol} ]; then - iptables -C INPUT -p udp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p udp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT + if ! grep -q "${firewall_name}=${firewall_port_start}:${firewall_port_end}" "$FIREWALL_CONFIG"; then + echo "${firewall_name}=${firewall_port_start}:${firewall_port_end}" >> "$FIREWALL_CONFIG" + if [ ! "${firewall_protocol}" ]; then + if ! iptables -C INPUT -p udp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT; then + iptables -A INPUT -p udp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT fi - iptables -C INPUT -p tcp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p tcp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT + if ! iptables -C INPUT -p tcp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT; then + iptables -A INPUT -p tcp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT fi else if [[ "${firewall_protocol}" == *"udp"* ]]; then - iptables -C INPUT -p udp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p udp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT + if ! iptables -C INPUT -p udp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT; then + iptables -A INPUT -p udp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT fi fi if [[ "${firewall_protocol}" == *"tcp"* ]]; then - iptables -C INPUT -p tcp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT - if [ ! "$?" = "0" ]; then - iptables -A INPUT -p tcp --dport ${firewall_port_start}:${firewall_port_end} -j ACCEPT + if ! iptables -C INPUT -p tcp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT; then + iptables -A INPUT -p tcp --dport "${firewall_port_start}":"${firewall_port_end}" -j ACCEPT fi fi fi @@ -479,23 +472,23 @@ function firewall_remove { firewall_port=$1 firewall_protocol="$2" - if [ ! -f $FIREWALL_CONFIG ]; then + if [ ! -f "$FIREWALL_CONFIG" ]; then return fi - if grep -q "=${firewall_port}" $FIREWALL_CONFIG; then - if [ ! ${firewall_protocol} ]; then - iptables -D INPUT -p udp --dport ${firewall_port} -j ACCEPT - iptables -D INPUT -p tcp --dport ${firewall_port} -j ACCEPT + if grep -q "=${firewall_port}" "$FIREWALL_CONFIG"; then + if [ ! "${firewall_protocol}" ]; then + iptables -D INPUT -p udp --dport "${firewall_port}" -j ACCEPT + iptables -D INPUT -p tcp --dport "${firewall_port}" -j ACCEPT else if [[ "${firewall_protocol}" == *"udp"* ]]; then - iptables -D INPUT -p udp --dport ${firewall_port} -j ACCEPT + iptables -D INPUT -p udp --dport "${firewall_port}" -j ACCEPT fi if [[ "${firewall_protocol}" == *"tcp"* ]]; then - iptables -D INPUT -p tcp --dport ${firewall_port} -j ACCEPT + iptables -D INPUT -p tcp --dport "${firewall_port}" -j ACCEPT fi fi - sed -i "/=${firewall_port}/d" $FIREWALL_CONFIG + sed -i "/=${firewall_port}/d" "$FIREWALL_CONFIG" save_firewall_settings fi } @@ -509,7 +502,7 @@ function domain_to_hex_string { characters=$(echo -n "$segment" | wc -c) hexnum=$(echo "obase=16; $characters" | bc) echo -n "|" - if [ $(echo -n "$hexnum" | wc -c) -lt 2 ]; then + if [ "$(echo -n "$hexnum" | wc -c)" -lt 2 ]; then echo -n "0" fi echo -n "$hexnum|$segment" @@ -523,20 +516,19 @@ function firewall_block_domain { blocked_domain="$1" if [[ "$blocked_domain" == *'@'* ]]; then # Don't try to block email/microblog addresses - echo "${blocked_domain}" >> $FIREWALL_DOMAINS + echo "${blocked_domain}" >> "$FIREWALL_DOMAINS" return fi - if ! grep -q "$blocked_domain" $FIREWALL_DOMAINS; then - hexstr=$(domain_to_hex_string $blocked_domain) - iptables -C INPUT -p udp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP - if [ ! "$?" = "0" ]; then + if ! grep -q "$blocked_domain" "$FIREWALL_DOMAINS"; then + hexstr=$(domain_to_hex_string "$blocked_domain") + if ! iptables -C INPUT -p udp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP; then iptables -A INPUT -p udp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP iptables -A INPUT -p tcp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP iptables -A OUTPUT -p udp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP iptables -A OUTPUT -p tcp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP iptables -I FORWARD -p udp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP iptables -I FORWARD -p tcp --dport 53 -m string --hex-string "$hexstr" --algo bm -j DROP - echo "${blocked_domain}" >> $FIREWALL_DOMAINS + echo "${blocked_domain}" >> "$FIREWALL_DOMAINS" save_firewall_settings fi @@ -559,13 +551,12 @@ function firewall_block_ip { # Don't try to block email/microblog addresses return fi - if ! grep -q "$blocked_ip" $FIREWALL_DOMAINS; then - iptables -C INPUT -s $blocked_ip -j DROP - if [ ! "$?" = "0" ]; then - iptables -A INPUT -s $blocked_ip -j DROP - iptables -A OUTPUT -s $blocked_ip -j DROP + if ! grep -q "$blocked_ip" "$FIREWALL_DOMAINS"; then + if ! iptables -C INPUT -s "$blocked_ip" -j DROP; then + iptables -A INPUT -s "$blocked_ip" -j DROP + iptables -A OUTPUT -s "$blocked_ip" -j DROP - echo "${blocked_ip}" >> $FIREWALL_DOMAINS + echo "${blocked_ip}" >> "$FIREWALL_DOMAINS" save_firewall_settings fi fi @@ -577,31 +568,31 @@ function firewall_unblock_ip { # Don't try to block email/microblog addresses return fi - if grep -q "$blocked_ip" $FIREWALL_DOMAINS; then - iptables -D INPUT -s $blocked_ip -j DROP - iptables -D OUTPUT -s $blocked_ip -j DROP + if grep -q "$blocked_ip" "$FIREWALL_DOMAINS"; then + iptables -D INPUT -s "$blocked_ip" -j DROP + iptables -D OUTPUT -s "$blocked_ip" -j DROP - sed -i '/$blocked_ip/d' $FIREWALL_DOMAINS - echo "${blocked_ip}" >> $FIREWALL_DOMAINS + sed -i "/$blocked_ip/d" "$FIREWALL_DOMAINS" + echo "${blocked_ip}" >> "$FIREWALL_DOMAINS" save_firewall_settings fi } function firewall_refresh_blocklist { - if [ ! -f /root/${PROJECT_NAME}-firewall-domains.cfg ]; then + if [ ! -f "/root/${PROJECT_NAME}-firewall-domains.cfg" ]; then return fi - while read blocked_domain; do - firewall_block_domain $blocked_domain - done > /var/www/${domain_name}/htdocs/config.php + echo "\$config['site']['qvitter']['sitebackground'] = 'img/bg_custom.${ext}';" >> "/var/www/${domain_name}/htdocs/config.php" fi fi fi @@ -112,86 +112,86 @@ function pleroma_set_background_image_from_url { fi if [ ${#ext} -gt 0 ]; then - cd $basedir + cd "$basedir" || exit 638436783 # remove any existing image - if [ -f bg_custom.${ext} ]; then - rm bg_custom.${ext} + if [ -f "bg_custom.${ext}" ]; then + rm "bg_custom.${ext}" fi # get the new image - wget "$url" -O bg_custom.${ext} - if [ ! -f bg_custom.${ext} ]; then + wget "$url" -O "bg_custom.${ext}" + if [ ! -f "bg_custom.${ext}" ]; then echo "$url" echo $'Custom background image for pleroma could not be downloaded' echo "1" return fi - if [ -d $basedir/static ]; then - cp bg_custom.${ext} static/bg_custom.${ext} - chown www-data:www-data static/bg_custom.${ext} + if [ -d "$basedir/static" ]; then + cp "bg_custom.${ext}" "static/bg_custom.${ext}" + chown www-data:www-data "static/bg_custom.${ext}" sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" static/config.json fi if [ -d priv/static/static ]; then - cp bg_custom.${ext} priv/static/static/bg_custom.${ext} - chown www-data:www-data priv/static/static/bg_custom.${ext} + cp "bg_custom.${ext}" "priv/static/static/bg_custom.${ext}" + chown www-data:www-data "priv/static/static/bg_custom.${ext}" sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" priv/static/static/config.json fi - if [[ "$basedir" != $PLEROMA_DIR ]]; then - qvitter_update_background ${domain_name} ${ext} + if [[ "$basedir" != "$PLEROMA_DIR" ]]; then + qvitter_update_background "${domain_name}" "${ext}" fi - rm bg_custom.${ext} + rm "bg_custom.${ext}" else echo "2" return fi # customise the logo - if [ -f $basedir/static/logo.png ]; then - if [ -f ~/freedombone/img/logo_fbone3.png ]; then - cp ~/freedombone/img/logo_fbone3.png $basedir/static/logo.png - if [ -d $basedir/priv/static/static ]; then - cp ~/freedombone/img/logo_fbone3.png $basedir/priv/static/static/logo.png + if [ -f "$basedir/static/logo.png" ]; then + if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png" + if [ -d "$basedir/priv/static/static" ]; then + cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png" fi else - if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then - cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/static/logo.png - if [ -d $basedir/priv/static/static ]; then - cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/priv/static/static/logo.png + if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo.png" + if [ -d "$basedir/priv/static/static" ]; then + cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/priv/static/static/logo.png" fi fi fi fi # customise the title - if [ -f $basedir/static/config.json ]; then - sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/static/config.json + if [ -f "$basedir/static/config.json" ]; then + sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json" fi - if [ -f $basedir/priv/static/static/config.json ]; then - sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/priv/static/static/config.json + if [ -f "$basedir/priv/static/static/config.json" ]; then + sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/priv/static/static/config.json" fi echo "0" } function install_qvitter { - domain_name=$1 - app_name=$2 + domain_name="$1" + app_name="$2" # update to the next commit function_check set_repo_commit - set_repo_commit /var/www/${domain_name}/htdocs/local/plugins/Qvitter "${app_name} theme commit" "$QVITTER_THEME_COMMIT" $QVITTER_THEME_REPO + set_repo_commit "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" "${app_name} theme commit" "$QVITTER_THEME_COMMIT" "$QVITTER_THEME_REPO" # customise with project logo - if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then - if [ -f ~/freedombone/img/logo_fbone3.png ]; then - cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png + if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then + if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" else - if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then - cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png + if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" fi fi fi @@ -202,101 +202,101 @@ function install_qvitter { apt-get -yq install wget - if [ ! -d /var/www/${domain_name}/htdocs/local/plugins ]; then - mkdir -p /var/www/${domain_name}/htdocs/local/plugins + if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins" ]; then + mkdir -p "/var/www/${domain_name}/htdocs/local/plugins" fi - cd /var/www/${domain_name}/htdocs/local/plugins + cd "/var/www/${domain_name}/htdocs/local/plugins" || exit 64284632 if [ -d /repos/qvitter ]; then mkdir Qvitter cp -r -p /repos/qvitter/. Qvitter - cd Qvitter + cd Qvitter || exit 2648246 git pull else function_check git_clone - git_clone $QVITTER_THEME_REPO Qvitter + git_clone "$QVITTER_THEME_REPO" Qvitter fi - if [ ! -d /var/www/${domain_name}/htdocs/local/plugins/Qvitter ]; then + if [ ! -d "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" ]; then echo $'Qvitter repo was not installed' exit 835638 fi - cd /var/www/${domain_name}/htdocs/local/plugins/Qvitter - git checkout $QVITTER_THEME_COMMIT -b $QVITTER_THEME_COMMIT + cd "/var/www/${domain_name}/htdocs/local/plugins/Qvitter" || exit 7824245 + git checkout "$QVITTER_THEME_COMMIT" -b "$QVITTER_THEME_COMMIT" - config_file=/var/www/${domain_name}/htdocs/config.php - if ! grep -q "addPlugin('Qvitter')" $config_file; then - echo "" >> $config_file - echo "// Qvitter settings" >> $config_file - echo "addPlugin('Qvitter');" >> $config_file - echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $config_file - echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $config_file - echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $config_file - echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $config_file + config_file="/var/www/${domain_name}/htdocs/config.php" + if ! grep -q "addPlugin('Qvitter')" "$config_file"; then + { echo ""; + echo "// Qvitter settings"; + echo "addPlugin('Qvitter');"; + echo "\$config['site']['qvitter']['enabledbydefault'] = true;"; + echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';"; + echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';"; + echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs"; } >> "$config_file" if [[ $ONION_ONLY == 'no' ]]; then - echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $config_file - echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $config_file + echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> "$config_file" + echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> "$config_file" fi - echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $config_file - echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $config_file - echo "\$config['site']['qvitter']['enablewelcometext'] = false;" >> $config_file - echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $config_file + { echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';"; + echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';"; + echo "\$config['site']['qvitter']['enablewelcometext'] = false;"; + echo "\$config['site']['qvitter']['blocked_ips'] = array();"; } >> "$config_file" fi # customise with project logo - if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then - if [ -f ~/freedombone/img/${app_name}_sprite.png ]; then - cp ~/freedombone/img/${app_name}_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png + if [ -f "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" ]; then + if [ -f "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" ]; then + cp "$HOME/${PROJECT_NAME}/img/${app_name}_sprite.png" "/var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png" fi fi - chown -R www-data:www-data /var/www/${domain_name}/htdocs + chown -R www-data:www-data "/var/www/${domain_name}/htdocs" - cd /var/www/${domain_name}/htdocs + cd "/var/www/${domain_name}/htdocs" || exit 37483673 php scripts/upgrade.php php scripts/checkschema.php - chown -R www-data:www-data /var/www/${domain_name}/htdocs + chown -R www-data:www-data "/var/www/${domain_name}/htdocs" set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT" - install_completed ${app_name}_theme + install_completed "${app_name}_theme" } function install_gnusocial_default_background { - gnusocial_type=$1 - domain_name=$2 + gnusocial_type="$1" + domain_name="$2" - basedir=/var/www/${domain_name}/htdocs + basedir="/var/www/${domain_name}/htdocs" if [[ "$gnusocial_type" == 'pleroma' ]]; then - basedir=$PLEROMA_DIR/priv/static + basedir="$PLEROMA_DIR/priv/static" fi # customise the logo - if [ -f $basedir/static/logo.png ]; then - if [ -f ~/freedombone/img/logo_fbone3.png ]; then - cp ~/freedombone/img/logo_fbone3.png $basedir/static/logo_custom.png - sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" $basedir/static/config.json + if [ -f "$basedir/static/logo.png" ]; then + if [ -f "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "$HOME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png" + sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json" else - if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then - cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/static/logo_custom.png - sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" $basedir/static/config.json + if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" ]; then + cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/logo_fbone3.png" "$basedir/static/logo_custom.png" + sed -i "s|\"logo\":.*|\"logo\": \"/static/logo_custom.png\",|g" "$basedir/static/config.json" fi fi fi - if [ ! -f $basedir/static/bg.jpg ]; then + if [ ! -f "$basedir/static/bg.jpg" ]; then return fi - if [ -f ~/freedombone/img/backgrounds/${gnusocial_type}.jpg ]; then - cp ~/freedombone/img/backgrounds/${gnusocial_type}.jpg $basedir/static/bg_custom.jpg - sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" $basedir/static/config.json + if [ -f "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then + cp "$HOME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg" + sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json" else - if [ -f /home/$MY_USERNAME/freedombone/img/backgrounds/${gnusocial_type}.jpg ]; then - cp /home/$MY_USERNAME/freedombone/img/backgrounds/${gnusocial_type}.jpg $basedir/static/bg_custom.jpg - sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" $basedir/static/config.json + if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" ]; then + cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/backgrounds/${gnusocial_type}.jpg" "$basedir/static/bg_custom.jpg" + sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.jpg\",|g" "$basedir/static/config.json" fi fi } @@ -308,30 +308,30 @@ function install_pleroma_front_end { background_url="$3" title="$4" - if [ ! -d $INSTALL_DIR/pleroma ]; then + if [ ! -d "$INSTALL_DIR/pleroma" ]; then if [ -d /repos/pleroma-fe ]; then - mkdir -p $INSTALL_DIR/pleroma - cp -r -p /repos/pleroma-fe/. $INSTALL_DIR/pleroma - cd $INSTALL_DIR/pleroma + mkdir -p "$INSTALL_DIR/pleroma" + cp -r -p /repos/pleroma-fe/. "$INSTALL_DIR/pleroma" + cd "$INSTALL_DIR/pleroma" || exit 23468324 git pull else function_check git_clone - git_clone $PLEROMA_FRONTEND_REPO $INSTALL_DIR/pleroma + git_clone "$PLEROMA_FRONTEND_REPO" "$INSTALL_DIR/pleroma" fi - if [ ! -d $INSTALL_DIR/pleroma ]; then + if [ ! -d "$INSTALL_DIR/pleroma" ]; then echo $'Unable to clone pleroma repo' exit 682252 fi fi - cd $INSTALL_DIR/pleroma - git checkout $PLEROMA_FRONTEND_COMMIT -b $PLEROMA_FRONTEND_COMMIT + cd "$INSTALL_DIR/pleroma" || exit 2562844 + git checkout "$PLEROMA_FRONTEND_COMMIT" -b "$PLEROMA_FRONTEND_COMMIT" set_completion_param "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" - if [ -d $INSTALL_DIR/pleroma/node_modules ]; then - rm -rf $INSTALL_DIR/pleroma/node_modules + if [ -d "$INSTALL_DIR/pleroma/node_modules" ]; then + rm -rf "$INSTALL_DIR/pleroma/node_modules" fi npm install -g yarn @@ -341,35 +341,35 @@ function install_pleroma_front_end { npm install -g node-sass@4.5.2 npm install -g whatwg-fetch@2.0.3 yarn - if [ -f $INSTALL_DIR/pleroma/dist/index.html ]; then - rm -rf $INSTALL_DIR/pleroma/dist/* + if [ -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then + rm -rf "$INSTALL_DIR/pleroma/dist/*" fi npm run build - if [ ! -d $INSTALL_DIR/pleroma/dist ]; then + if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then echo 'Unable to build pleroma' exit 7629352 fi - if [ ! -f $INSTALL_DIR/pleroma/dist/index.html ]; then + if [ ! -f "$INSTALL_DIR/pleroma/dist/index.html" ]; then echo $'Unable to build pleroma index.html' exit 5282682 fi if [[ "$app_name" != 'pleroma' ]]; then - cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${pleroma_domain}/htdocs/ - pleroma_set_background_image_from_url /var/www/${pleroma_domain}/htdocs "$pleroma_domain" "$background_url" "$title" + cp -r "$INSTALL_DIR/pleroma/dist/*" "/var/www/${pleroma_domain}/htdocs/" + pleroma_set_background_image_from_url "/var/www/${pleroma_domain}/htdocs" "$pleroma_domain" "$background_url" "$title" else - cp -r $INSTALL_DIR/pleroma/dist/* $PLEROMA_DIR/priv/static - pleroma_set_background_image_from_url $PLEROMA_DIR/priv/static "$pleroma_domain" "$background_url" "$title" + cp -r "$INSTALL_DIR/pleroma/dist/*" "$PLEROMA_DIR/priv/static" + pleroma_set_background_image_from_url "$PLEROMA_DIR/priv/static" "$pleroma_domain" "$background_url" "$title" fi - nginx_site=/etc/nginx/sites-available/${pleroma_domain} - sed -i 's|index index.php;|index index.html;|g' $nginx_site + nginx_site="/etc/nginx/sites-available/${pleroma_domain}" + sed -i 's|index index.php;|index index.html;|g' "$nginx_site" - if [ -f /var/www/${pleroma_domain}/htdocs/index.php ]; then - mv /var/www/${pleroma_domain}/htdocs/index.php /var/www/${pleroma_domain}/htdocs/index_qvitter.php + if [ -f "/var/www/${pleroma_domain}/htdocs/index.php" ]; then + mv "/var/www/${pleroma_domain}/htdocs/index.php" "/var/www/${pleroma_domain}/htdocs/index_qvitter.php" fi - sed -i 's|index.php|index_qvitter.php|g' $nginx_site + sed -i 's|index.php|index_qvitter.php|g' "$nginx_site" # remove any cached yarn files if [ -d /root/.cache/yarn ]; then @@ -377,9 +377,9 @@ function install_pleroma_front_end { fi if [[ "$app_name" != 'pleroma' ]]; then - chown -R www-data:www-data /var/www/${pleroma_domain}/htdocs + chown -R www-data:www-data "/var/www/${pleroma_domain}/htdocs" else - chown -R pleroma:pleroma $PLEROMA_DIR + chown -R pleroma:pleroma "$PLEROMA_DIR" fi } @@ -389,269 +389,267 @@ function upgrade_pleroma_frontend { background_url="$3" title="$4" - if [ -d $INSTALL_DIR/pleroma ]; then - set_repo_commit $INSTALL_DIR/pleroma "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" $PLEROMA_FRONTEND_REPO - cd $INSTALL_DIR/pleroma + if [ -d "$INSTALL_DIR/pleroma" ]; then + set_repo_commit "$INSTALL_DIR/pleroma" "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" "$PLEROMA_FRONTEND_REPO" + cd "$INSTALL_DIR/pleroma" || exit 3468356385 yarn npm run build - if [ ! -d $INSTALL_DIR/pleroma/dist ]; then + if [ ! -d "$INSTALL_DIR/pleroma/dist" ]; then echo 'Unable to build pleroma' exit 268362 fi - basedir=/var/www/${domain_name}/htdocs + basedir="/var/www/${domain_name}/htdocs" if [[ "$app_name" == 'pleroma' ]]; then - basedir=$PLEROMA_DIR/priv/static + basedir="$PLEROMA_DIR/priv/static" fi - if [ -f $basedir/static/logo.png ]; then - cp $basedir/static/logo.png $basedir/static/logo.png.old + if [ -f "$basedir/static/logo.png" ]; then + cp "$basedir/static/logo.png" "$basedir/static/logo.png.old" fi - if [ -f $basedir/static/bg.jpg ]; then - cp $basedir/static/bg.jpg $basedir/static/bg.jpg.old + if [ -f "$basedir/static/bg.jpg" ]; then + cp "$basedir/static/bg.jpg" "$basedir/static/bg.jpg.old" fi - if [ -f $basedir/static/config.json ]; then - cp $basedir/static/config.json $basedir/static/config.json.old + if [ -f "$basedir/static/config.json" ]; then + cp "$basedir/static/config.json" "$basedir/static/config.json.old" fi - cp -r $INSTALL_DIR/pleroma/dist/* $basedir/ - if [ -f $basedir/static/config.json.old ]; then - mv $basedir/static/config.json.old $basedir/static/config.json + cp -r "$INSTALL_DIR/pleroma/dist/*" "$basedir/" + if [ -f "$basedir/static/config.json.old" ]; then + mv "$basedir/static/config.json.old" "$basedir/static/config.json" fi - sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/static/config.json - if [ -f $basedir/static/logo.png.old ]; then - cp $basedir/static/logo.png.old $basedir/static/logo.png + sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" "$basedir/static/config.json" + if [ -f "$basedir/static/logo.png.old" ]; then + cp "$basedir/static/logo.png.old" "$basedir/static/logo.png" fi - if [ -f $basedir/static/bg.jpg.old ]; then - cp $basedir/static/bg.jpg.old $basedir/static/bg.jpg + if [ -f "$basedir/static/bg.jpg.old" ]; then + cp "$basedir/static/bg.jpg.old" "$basedir/static/bg.jpg" fi - if [ -f $basedir/index.php ]; then - mv $basedir/index.php $basedir/index_qvitter.php + if [ -f "$basedir/index.php" ]; then + mv "$basedir/index.php" "$basedir/index_qvitter.php" fi - chown -R www-data:www-data $basedir + chown -R www-data:www-data "$basedir" else install_pleroma_front_end "${app_name}" "${domain_name}" "${background_url}" "${title}" fi } function gnusocial_hourly_script { - gnusocial_type=$1 - domain_name=$2 + gnusocial_type="$1" + domain_name="$2" # check that the daemon is running - echo '#!/bin/bash' > /etc/cron.hourly/${gnusocial_type}-daemons - echo -n 'daemon_lines=$(ps aux | grep "' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo -n "${domain_name}" >> /etc/cron.hourly/${gnusocial_type}-daemons - echo '/htdocs/scripts/queuedaemon.php" | grep "/var/www")' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo "cd /var/www/${domain_name}/htdocs" >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'if [[ $daemon_lines != *"/var/www/"* ]]; then' >> /etc/cron.hourly/${gnusocial_type}-daemons + { echo '#!/bin/bash'; + echo -n "daemon_lines=\$(ps aux | grep \""; + echo -n "${domain_name}"; + echo '/htdocs/scripts/queuedaemon.php" | grep "/var/www")'; + echo "cd /var/www/${domain_name}/htdocs"; + echo "if [[ \$daemon_lines != *\"/var/www/\"* ]]; then"; + echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')"; + echo " MY_EMAIL_ADDRESS=\$ADMIN_USER@$HOSTNAME"; + echo -n " echo \"Restarting ${gnusocial_type} daemons\" | mail -s \"${gnusocial_type} "; + echo "daemons not found\" \$MY_EMAIL_ADDRESS"; + echo ' su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data'; + echo 'fi'; + echo 'php scripts/delete_orphan_files.php > /dev/null'; + echo 'php scripts/clean_thumbnails.php -y > /dev/null'; + echo 'php scripts/clean_file_table.php -y > /dev/null'; + echo 'php scripts/upgrade.php > /dev/null'; } > "/etc/cron.hourly/${gnusocial_type}-daemons" - echo " ADMIN_USER=\$(cat $COMPLETION_FILE | grep 'Admin user' | awk -F ':' '{print \$2}')" >> /etc/cron.hourly/${gnusocial_type}-daemons - echo ' MY_EMAIL_ADDRESS=$ADMIN_USER@$HOSTNAME' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo -n " echo \"Restarting ${gnusocial_type} daemons\" | mail -s \"${gnusocial_type} " >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'daemons not found" $MY_EMAIL_ADDRESS' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo ' su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'fi' >> /etc/cron.hourly/${gnusocial_type}-daemons - - echo 'php scripts/delete_orphan_files.php > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'php scripts/clean_thumbnails.php -y > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'php scripts/clean_file_table.php -y > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons - echo 'php scripts/upgrade.php > /dev/null' >> /etc/cron.hourly/${gnusocial_type}-daemons - - chmod +x /etc/cron.hourly/${gnusocial_type}-daemons + chmod +x "/etc/cron.hourly/${gnusocial_type}-daemons" } function gnusocial_block_user_script { - echo '#!/bin/bash' > /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'database_name=$1' >> /usr/bin/gnusocial-delete-user - echo 'remove_user=$2' >> /usr/bin/gnusocial-delete-user - echo 'domain_name=$3' >> /usr/bin/gnusocial-delete-user - echo 'MARIADB_PASSWORD=$(freedombone-pass -u root -a mariadb)' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'if [ ${#remove_user} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-user - echo ' echo $"No user was specified"' >> /usr/bin/gnusocial-delete-user - echo ' exit 1' >> /usr/bin/gnusocial-delete-user - echo 'fi' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'if [[ "$remove_user" != *"."* || "$remove_user" != *"@"* ]]; then' >> /usr/bin/gnusocial-delete-user - echo ' echo $"This doesnt look like a user"' >> /usr/bin/gnusocial-delete-user - echo ' exit 2' >> /usr/bin/gnusocial-delete-user - echo 'fi' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'if [ ${#database_name} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-user - echo ' echo $"No database was specified"' >> /usr/bin/gnusocial-delete-user - echo ' exit 3' >> /usr/bin/gnusocial-delete-user - echo 'fi' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo "nickname=\$(echo \"\$remove_user\" | awk -F '@' '{print \$1}')" >> /usr/bin/gnusocial-delete-user - echo "remove_domain=\$(echo \"\$remove_user\" | awk -F '@' '{print \$2}')" >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo "database_query=\"delete from notice where content REGEXP '\@\${remove_user}';\"" >> /usr/bin/gnusocial-delete-user - echo 'mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'database_query="select profile.id from profile where nickname = '"'"'${nickname}'"'"' and profileurl like '"'"'%${remove_domain}%'"'"';"' >> /usr/bin/gnusocial-delete-user - echo 'declare -a ids=$(mysql -u root --password="$MARIADB_PASSWORD" << EOF' >> /usr/bin/gnusocial-delete-user - echo 'use $database_name;' >> /usr/bin/gnusocial-delete-user - echo '$database_query' >> /usr/bin/gnusocial-delete-user - echo 'EOF' >> /usr/bin/gnusocial-delete-user - echo ')' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo 'ctr=0' >> /usr/bin/gnusocial-delete-user - echo 'for id in $ids' >> /usr/bin/gnusocial-delete-user - echo 'do' >> /usr/bin/gnusocial-delete-user - echo ' if [ $ctr -gt 0 ]; then' >> /usr/bin/gnusocial-delete-user - echo ' #echo "Removing user ID $id on $remove_domain"' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' database_query="delete from reply where profile_id=${id};"' >> /usr/bin/gnusocial-delete-user - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' database_query="delete from reply where replied_id=${id};"' >> /usr/bin/gnusocial-delete-user - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' if [ $domain_name ]; then' >> /usr/bin/gnusocial-delete-user - echo ' database_query="select rendered from notice where profile_id=${id} and rendered like '"'"'%/file/%'"'"';"' >> /usr/bin/gnusocial-delete-user - echo ' declare -a stored_files=$(mysql -u root --password="$MARIADB_PASSWORD" << EOF' >> /usr/bin/gnusocial-delete-user - echo 'use $database_name;' >> /usr/bin/gnusocial-delete-user - echo '$database_query' >> /usr/bin/gnusocial-delete-user - echo 'EOF' >> /usr/bin/gnusocial-delete-user - echo ')' >> /usr/bin/gnusocial-delete-user - echo -n " files_to_delete=\$(echo \"\$stored_files\" | " >> /usr/bin/gnusocial-delete-user - echo 'sed -n '"'"'s/.*href="\([^"]*\).*/\1/p'"'"' | awk -F '"'"'file/'"'"' '"'"'{print $2}'"'"')' >> /usr/bin/gnusocial-delete-user - echo ' filectr=0' >> /usr/bin/gnusocial-delete-user - echo ' for f in $files_to_delete' >> /usr/bin/gnusocial-delete-user - echo ' do' >> /usr/bin/gnusocial-delete-user - echo ' if [ $filectr -gt 0 ]; then' >> /usr/bin/gnusocial-delete-user - echo ' if $(ls /var/www/${domain_name}/htdocs/file/*${f}* 1> /dev/null 2>&1); then' >> /usr/bin/gnusocial-delete-user - echo ' rm /var/www/${domain_name}/htdocs/file/*${f}*' >> /usr/bin/gnusocial-delete-user - echo ' fi' >> /usr/bin/gnusocial-delete-user - echo ' fi' >> /usr/bin/gnusocial-delete-user - echo ' filectr=$((filectr + 1))' >> /usr/bin/gnusocial-delete-user - echo ' done' >> /usr/bin/gnusocial-delete-user - echo ' fi' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' database_query="delete from notice where profile_id=${id};"' >> /usr/bin/gnusocial-delete-user - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' database_query="delete from profile where id=${id};"' >> /usr/bin/gnusocial-delete-user - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo '' >> /usr/bin/gnusocial-delete-user - echo ' database_query="delete from qvitternotification where to_profile_id=${id} or from_profile_id=${id};"' >> /usr/bin/gnusocial-delete-user - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-user - echo ' fi' >> /usr/bin/gnusocial-delete-user - echo ' ctr=$((ctr + 1))' >> /usr/bin/gnusocial-delete-user - echo 'done' >> /usr/bin/gnusocial-delete-user + { echo '#!/bin/bash'; + echo ''; + echo "database_name=\$1"; + echo "remove_user=\$2"; + echo "domain_name=\$3"; + echo "MARIADB_PASSWORD=\$(freedombone-pass -u root -a mariadb)"; + echo ''; + echo "if [ \${#remove_user} -lt 2 ]; then"; + echo ' echo $"No user was specified"'; + echo ' exit 1'; + echo 'fi'; + echo ''; + echo "if [[ \"\$remove_user\" != *\".\"* || \"\$remove_user\" != *\"@\"* ]]; then"; + echo ' echo $"This doesnt look like a user"'; + echo ' exit 2'; + echo 'fi'; + echo ''; + echo "if [ \${#database_name} -lt 2 ]; then"; + echo ' echo $"No database was specified"'; + echo ' exit 3'; + echo 'fi'; + echo ''; + echo "nickname=\$(echo \"\$remove_user\" | awk -F '@' '{print \$1}')"; + echo "remove_domain=\$(echo \"\$remove_user\" | awk -F '@' '{print \$2}')"; + echo ''; + echo "database_query=\"delete from notice where content REGEXP '\\@\${remove_user}';\""; + echo "mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo "database_query=\"select profile.id from profile where nickname = '\${nickname}' and profileurl like '%\${remove_domain}%';\""; + echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF"; + echo "use \$database_name;"; + echo "\$database_query"; + echo 'EOF'; + echo ')'; + echo ''; + echo 'ctr=0'; + echo "for id in \$ids"; + echo 'do'; + echo " if [ \$ctr -gt 0 ]; then"; + echo " #echo \"Removing user ID \$id on \$remove_domain\""; + echo ''; + echo " database_query=\"delete from reply where profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " database_query=\"delete from reply where replied_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " if [ \$domain_name ]; then"; + echo " database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\""; + echo " declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF"; + echo "use \$database_name;"; + echo "\$database_query"; + echo 'EOF'; + echo ')'; + echo -n " files_to_delete=\$(echo \"\$stored_files\" | "; + echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')"; + echo ' filectr=0'; + echo " for f in \$files_to_delete"; + echo ' do'; + echo " if [ \$filectr -gt 0 ]; then"; + echo " if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then"; + echo " rm /var/www/\${domain_name}/htdocs/file/*\${f}*"; + echo ' fi'; + echo ' fi'; + echo " filectr=\$((filectr + 1))"; + echo ' done'; + echo ' fi'; + echo ''; + echo " database_query=\"delete from notice where profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " database_query=\"delete from profile where id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ' fi'; + echo " ctr=\$((ctr + 1))"; + echo 'done'; } > /usr/bin/gnusocial-delete-user chmod +x /usr/bin/gnusocial-delete-user } function gnusocial_block_domain_script { - database_name=$1 - gnusoc_domain=$2 + database_name="$1" + gnusoc_domain="$2" - echo '#!/bin/bash' > /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo 'database_name=$1' >> /usr/bin/gnusocial-delete-domain - echo 'remove_domain=$2' >> /usr/bin/gnusocial-delete-domain - echo 'domain_name=$3' >> /usr/bin/gnusocial-delete-domain - echo "MARIADB_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)" >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo 'if [ ${#remove_domain} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-domain - echo ' echo $"No domain was specified"' >> /usr/bin/gnusocial-delete-domain - echo ' exit 1' >> /usr/bin/gnusocial-delete-domain - echo 'fi' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo 'if [[ "$remove_domain" != *"."* ]]; then' >> /usr/bin/gnusocial-delete-domain - echo ' echo $"This doesnt look like a domain"' >> /usr/bin/gnusocial-delete-domain - echo ' exit 2' >> /usr/bin/gnusocial-delete-domain - echo 'fi' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo 'if [ ${#database_name} -lt 2 ]; then' >> /usr/bin/gnusocial-delete-domain - echo ' echo $"No database was specified"' >> /usr/bin/gnusocial-delete-domain - echo ' exit 3' >> /usr/bin/gnusocial-delete-domain - echo 'fi' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo "database_query=\"select profile.id from profile where profileurl like '%\${remove_domain}%';\"" >> /usr/bin/gnusocial-delete-domain - echo 'declare -a ids=$(mysql -u root --password="$MARIADB_PASSWORD" << EOF' >> /usr/bin/gnusocial-delete-domain - echo 'use $database_name;' >> /usr/bin/gnusocial-delete-domain - echo '$database_query' >> /usr/bin/gnusocial-delete-domain - echo 'EOF' >> /usr/bin/gnusocial-delete-domain - echo ')' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo 'ctr=0' >> /usr/bin/gnusocial-delete-domain - echo 'for id in $ids' >> /usr/bin/gnusocial-delete-domain - echo 'do' >> /usr/bin/gnusocial-delete-domain - echo ' if [ $ctr -gt 0 ]; then' >> /usr/bin/gnusocial-delete-domain - echo ' #echo "Removing user ID $id on $remove_domain"' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo " database_query=\"delete from conversation where uri like '%\${remove_domain}%';\"" >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="delete from reply where profile_id=${id};"' >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="delete from reply where replied_id=${id};"' >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' if [ $domain_name ]; then' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="select rendered from notice where profile_id=${id} and rendered like '"'"'%/file/%'"'"';"' >> /usr/bin/gnusocial-delete-domain - echo ' declare -a stored_files=$(mysql -u root --password="$MARIADB_PASSWORD" << EOF' >> /usr/bin/gnusocial-delete-domain - echo 'use $database_name;' >> /usr/bin/gnusocial-delete-domain - echo '$database_query' >> /usr/bin/gnusocial-delete-domain - echo 'EOF' >> /usr/bin/gnusocial-delete-domain - echo ')' >> /usr/bin/gnusocial-delete-domain - echo -n " files_to_delete=\$(echo \"\$stored_files\" | " >> /usr/bin/gnusocial-delete-domain - echo 'sed -n '"'"'s/.*href="\([^"]*\).*/\1/p'"'"' | awk -F '"'"'file/'"'"' '"'"'{print $2}'"'"')' >> /usr/bin/gnusocial-delete-domain - echo ' filectr=0' >> /usr/bin/gnusocial-delete-domain - echo ' for f in $files_to_delete' >> /usr/bin/gnusocial-delete-domain - echo ' do' >> /usr/bin/gnusocial-delete-domain - echo ' if [ $filectr -gt 0 ]; then' >> /usr/bin/gnusocial-delete-domain - echo ' if $(ls /var/www/${domain_name}/htdocs/file/*${f}* 1> /dev/null 2>&1); then' >> /usr/bin/gnusocial-delete-domain - echo ' rm /var/www/${domain_name}/htdocs/file/*${f}*' >> /usr/bin/gnusocial-delete-domain - echo ' fi' >> /usr/bin/gnusocial-delete-domain - echo ' fi' >> /usr/bin/gnusocial-delete-domain - echo ' filectr=$((filectr + 1))' >> /usr/bin/gnusocial-delete-domain - echo ' done' >> /usr/bin/gnusocial-delete-domain - echo ' fi' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="delete from notice where profile_id=${id};"' >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="delete from profile where id=${id};"' >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo '' >> /usr/bin/gnusocial-delete-domain - echo ' database_query="delete from qvitternotification where to_profile_id=${id} or from_profile_id=${id};"' >> /usr/bin/gnusocial-delete-domain - echo ' mysql -u root --password="$MARIADB_PASSWORD" -e "$database_query" $database_name' >> /usr/bin/gnusocial-delete-domain - echo ' fi' >> /usr/bin/gnusocial-delete-domain - echo ' ctr=$((ctr + 1))' >> /usr/bin/gnusocial-delete-domain - echo 'done' >> /usr/bin/gnusocial-delete-domain + { echo '#!/bin/bash'; + echo ''; + echo "database_name=\$1"; + echo "remove_domain=\$2"; + echo "domain_name=\$3"; + echo "MARIADB_PASSWORD=\$(${PROJECT_NAME}-pass -u root -a mariadb)"; + echo ''; + echo "if [ \${#remove_domain} -lt 2 ]; then"; + echo ' echo $"No domain was specified"'; + echo ' exit 1'; + echo 'fi'; + echo ''; + echo "if [[ \"\$remove_domain\" != *\".\"* ]]; then"; + echo ' echo $"This doesnt look like a domain"'; + echo ' exit 2'; + echo 'fi'; + echo ''; + echo "if [ \${#database_name} -lt 2 ]; then"; + echo ' echo $"No database was specified"'; + echo ' exit 3'; + echo 'fi'; + echo ''; + echo "database_query=\"select profile.id from profile where profileurl like '%\${remove_domain}%';\""; + echo "declare -a ids=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF"; + echo "use \$database_name;"; + echo "\$database_query"; + echo 'EOF'; + echo ')'; + echo ''; + echo 'ctr=0'; + echo "for id in \$ids"; + echo 'do'; + echo " if [ \$ctr -gt 0 ]; then"; + echo " #echo \"Removing user ID \$id on \$remove_domain\""; + echo ''; + echo " database_query=\"delete from conversation where uri like '%\${remove_domain}%';\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " database_query=\"delete from reply where profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name"; + echo ''; + echo " database_query=\"delete from reply where replied_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " if [ \$domain_name ]; then"; + echo " database_query=\"select rendered from notice where profile_id=\${id} and rendered like '%/file/%';\""; + echo " declare -a stored_files=\$(mysql -u root --password=\"\$MARIADB_PASSWORD\" << EOF"; + echo "use \$database_name;"; + echo "\$database_query"; + echo 'EOF'; + echo ')'; + echo -n " files_to_delete=\$(echo \"\$stored_files\" | "; + echo "sed -n 's/.*href=\"\\([^\"]*\\).*/\\1/p' | awk -F 'file/' '{print \$2}')"; + echo ' filectr=0'; + echo " for f in \$files_to_delete"; + echo ' do'; + echo " if [ \$filectr -gt 0 ]; then"; + echo " if \$(ls /var/www/\${domain_name}/htdocs/file/*\${f}* 1> /dev/null 2>&1); then"; + echo " rm /var/www/\${domain_name}/htdocs/file/*\${f}*"; + echo ' fi'; + echo ' fi'; + echo " filectr=\$((filectr + 1))"; + echo ' done'; + echo ' fi'; + echo ''; + echo " database_query=\"delete from notice where profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" $database_name"; + echo ''; + echo " database_query=\"delete from profile where id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ''; + echo " database_query=\"delete from qvitternotification where to_profile_id=\${id} or from_profile_id=\${id};\""; + echo " mysql -u root --password=\"\$MARIADB_PASSWORD\" -e \"\$database_query\" \$database_name"; + echo ' fi'; + echo " ctr=\$((ctr + 1))"; + echo 'done'; } > /usr/bin/gnusocial-delete-domain chmod +x /usr/bin/gnusocial-delete-domain - echo '#!/bin/bash' > /usr/bin/${database_name}-firewall - echo '' >> /usr/bin/${database_name}-firewall - echo "PROJECT_NAME=$PROJECT_NAME" >> /usr/bin/${database_name}-firewall - echo "GNUSOCIAL_DOMAIN_NAME=$gnusoc_domain" >> /usr/bin/${database_name}-firewall - echo "database_name=$database_name" >> /usr/bin/${database_name}-firewall - echo 'FIREWALL_DOMAINS=$HOME/${PROJECT_NAME}-firewall-domains.cfg' >> /usr/bin/${database_name}-firewall - echo '' >> /usr/bin/${database_name}-firewall - echo 'while read block; do' >> /usr/bin/${database_name}-firewall - echo ' if [[ "$block" != *"@"* ]]; then' >> /usr/bin/${database_name}-firewall - echo ' /usr/bin/gnusocial-delete-domain "$database_name" "$block" "$GNUSOCIAL_DOMAIN_NAME"' >> /usr/bin/${database_name}-firewall - echo ' else' >> /usr/bin/${database_name}-firewall - echo ' /usr/bin/gnusocial-delete-user "$database_name" "$block" "$GNUSOCIAL_DOMAIN_NAME"' >> /usr/bin/${database_name}-firewall - echo ' fi' >> /usr/bin/${database_name}-firewall - echo 'done <$FIREWALL_DOMAINS' >> /usr/bin/${database_name}-firewall - echo '' >> /usr/bin/${database_name}-firewall - echo '# remove any metadata from images uploaded in the last 2 minutes' >> /usr/bin/${database_name}-firewall - echo 'if [ -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then' >> /usr/bin/${database_name}-firewall - echo ' cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs' >> /usr/bin/${database_name}-firewall - echo ' declare -a recent_image=$(find file ! -name thumb-* -mmin -2 -type f -exec ls -l {} + | awk -F '"'"'file/'"'"' '"'"'{print $2}'"'"')' >> /usr/bin/${database_name}-firewall - echo ' for f in ${recent_image[@]}' >> /usr/bin/${database_name}-firewall - echo ' do' >> /usr/bin/${database_name}-firewall - echo ' if [ ${#f} -gt 1 ]; then' >> /usr/bin/${database_name}-firewall - echo ' exiftool -q -all= "file/${f}"' >> /usr/bin/${database_name}-firewall - echo ' fi' >> /usr/bin/${database_name}-firewall - echo ' done' >> /usr/bin/${database_name}-firewall - echo 'fi' >> /usr/bin/${database_name}-firewall - chmod +x /usr/bin/${database_name}-firewall + { echo '#!/bin/bash'; + echo ''; + echo "PROJECT_NAME=$PROJECT_NAME"; + echo "GNUSOCIAL_DOMAIN_NAME=$gnusoc_domain"; + echo "database_name=$database_name"; + echo "FIREWALL_DOMAINS=\$HOME/\${PROJECT_NAME}-firewall-domains.cfg"; + echo ''; + echo 'while read block; do'; + echo " if [[ \"\$block\" != *\"@\"* ]]; then"; + echo " /usr/bin/gnusocial-delete-domain \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\""; + echo ' else'; + echo " /usr/bin/gnusocial-delete-user \"\$database_name\" \"\$block\" \"\$GNUSOCIAL_DOMAIN_NAME\""; + echo ' fi'; + echo "done <\$FIREWALL_DOMAINS"; + echo ''; + echo '# remove any metadata from images uploaded in the last 2 minutes'; + echo "if [ -d /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then"; + echo " cd /var/www/\$GNUSOCIAL_DOMAIN_NAME/htdocs"; + echo " declare -a recent_image=\$(find file ! -name thumb-* -mmin -2 -type f -exec ls -l {} + | awk -F 'file/' '{print \$2}')"; + echo " for f in \${recent_image[@]}"; + echo ' do'; + echo " if [ \${#f} -gt 1 ]; then"; + echo " exiftool -q -all= \"file/\${f}\""; + echo ' fi'; + echo ' done'; + echo 'fi'; } > "/usr/bin/${database_name}-firewall" + chmod +x "/usr/bin/${database_name}-firewall" if ! grep -q "${database_name}-firewall" /etc/crontab; then cron_add_mins 1 "/usr/bin/${database_name}-firewall" @@ -659,81 +657,80 @@ function gnusocial_block_domain_script { } function expire_gnusocial_posts { - domain_name=$1 - gnusocial_type=$2 - expire_months=$3 + domain_name="$1" + gnusocial_type="$2" + expire_months="$3" - if [ ! $expire_months ]; then + if [ ! "$expire_months" ]; then expire_months=3 fi - expire_days=$((expire_months * 30)) + #expire_days=$((expire_months * 30)) # files are what take up most of the backup time, so don't keep them for very long expire_days_files=7 # To prevent the database size from growing endlessly this script expires posts # after a number of months - if [ ! -d /var/www/${domain_name}/htdocs ]; then + if [ ! -d "/var/www/${domain_name}/htdocs" ]; then return fi - gnusocial_expire_posts_script=/usr/bin/${gnusocial_type}-expire-posts + gnusocial_expire_posts_script="/usr/bin/${gnusocial_type}-expire-posts" - echo ' $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin" >> $gnusocial_expire_posts_script - echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));" >> $gnusocial_expire_posts_script - echo '$username="root";' >> $gnusocial_expire_posts_script - echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_posts_script - echo "\$database=\"${gnusocial_type}\";" >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo 'if (!$link = mysqli_connect("localhost", $username, $password)) {' >> $gnusocial_expire_posts_script - echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_posts_script - echo ' exit;' >> $gnusocial_expire_posts_script - echo '}' >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo 'if (!mysqli_select_db($link, $database)) {' >> $gnusocial_expire_posts_script - echo " echo \"Could not select ${gnusocial_type} database\";" >> $gnusocial_expire_posts_script - echo ' exit;' >> $gnusocial_expire_posts_script - echo '}' >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script - echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script - echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script - echo "\$notification_query=\"DELETE FROM qvitternotification WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo 'mysqli_query($link, $notice_query);' >> $gnusocial_expire_posts_script - echo '$rowaff1=mysqli_affected_rows($link);' >> $gnusocial_expire_posts_script - echo 'mysqli_query($link, $conversation_query);' >> $gnusocial_expire_posts_script - echo '$rowaff2=mysqli_affected_rows($link);' >> $gnusocial_expire_posts_script - echo 'mysqli_query($link, $reply_query);' >> $gnusocial_expire_posts_script - echo '$rowaff3=mysqli_affected_rows($link);' >> $gnusocial_expire_posts_script - echo 'mysqli_query($link, $notification_query);' >> $gnusocial_expire_posts_script - echo '$rowaff4=mysqli_affected_rows($link);' >> $gnusocial_expire_posts_script - echo 'mysqli_close($link);' >> $gnusocial_expire_posts_script - echo '' >> $gnusocial_expire_posts_script - echo -n "echo \"Expire ${gnusocial_type} posts: " >> $gnusocial_expire_posts_script - echo '$rowaff1 notices, $rowaff2 conversations, $rowaff3 replies, and $rowaff4 qvitter notifications deleted from database.\n";' >> $gnusocial_expire_posts_script - chmod +x $gnusocial_expire_posts_script + { echo ' "$gnusocial_expire_posts_script" + chmod +x "$gnusocial_expire_posts_script" - gnusocial_expire_script=/etc/cron.daily/${gnusocial_type}-expire - echo '#!/bin/bash' > $gnusocial_expire_script - echo "find /var/www/${domain_name}/htdocs/file/* -mtime +${expire_days_files} -exec rm {} +" >> $gnusocial_expire_script - echo "/usr/bin/php $gnusocial_expire_posts_script" >> $gnusocial_expire_script - chmod +x $gnusocial_expire_script + gnusocial_expire_script="/etc/cron.daily/${gnusocial_type}-expire" + { echo '#!/bin/bash'; + echo "find /var/www/${domain_name}/htdocs/file/* -mtime +${expire_days_files} -exec rm {} +"; + echo "/usr/bin/php $gnusocial_expire_posts_script"; } > "$gnusocial_expire_script" + chmod +x "$gnusocial_expire_script" # remove any old cron job if grep -q "${gnusocial_type}-expire" /etc/crontab; then sed -i "/${gnusocial_type}-expire/d" /etc/crontab - rm /usr/bin/${gnusocial_type}-expire + rm "/usr/bin/${gnusocial_type}-expire" fi # remove old expire script - if [ -f /etc/cron.weekly/clear-${gnusocial_type}-database ]; then - rm /etc/cron.weekly/clear-${gnusocial_type}-database + if [ -f "/etc/cron.weekly/clear-${gnusocial_type}-database" ]; then + rm "/etc/cron.weekly/clear-${gnusocial_type}-database" fi } @@ -742,20 +739,20 @@ function gnusocial_use_classic { domain_name=$(get_completion_param "$database_name domain") - if [ -f /var/www/$domain_name/htdocs/index_qvitter.php ]; then - mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php + if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then + mv "/var/www/$domain_name/htdocs/index_qvitter.php" "/var/www/$domain_name/htdocs/index.php" fi - if [ -f /etc/nginx/sites-available/$domain_name ]; then - sed -i 's|index_qvitter.php|index.php|g' /etc/nginx/sites-available/$domain_name - sed -i 's|index.html|index.php|g' /etc/nginx/sites-available/$domain_name + if [ -f "/etc/nginx/sites-available/$domain_name" ]; then + sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name" + sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name" fi - if ! grep -q "//addPlugin('Qvitter')" /var/www/$domain_name/htdocs/config.php; then - sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php - sed -i "s|addPlugin('Qvitter')|//addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php + if ! grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then + sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" + sed -i "s|addPlugin('Qvitter')|//addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" fi - chown -R www-data:www-data /var/www/${domain_name}/htdocs + chown -R www-data:www-data "/var/www/${domain_name}/htdocs" systemctl restart nginx } @@ -765,132 +762,132 @@ function gnusocial_use_qvitter { domain_name=$(get_completion_param "$database_name domain") - if [ -f /var/www/$domain_name/htdocs/index_qvitter.php ]; then - mv /var/www/$domain_name/htdocs/index_qvitter.php /var/www/$domain_name/htdocs/index.php + if [ -f "/var/www/$domain_name/htdocs/index_qvitter.php" ]; then + mv "/var/www/$domain_name/htdocs/index_qvitter.php" "/var/www/$domain_name/htdocs/index.php" fi - if [ -f /etc/nginx/sites-available/$domain_name ]; then - sed -i 's|index_qvitter.php|index.php|g' /etc/nginx/sites-available/$domain_name - sed -i 's|index.html|index.php|g' /etc/nginx/sites-available/$domain_name + if [ -f "/etc/nginx/sites-available/$domain_name" ]; then + sed -i 's|index_qvitter.php|index.php|g' "/etc/nginx/sites-available/$domain_name" + sed -i 's|index.html|index.php|g' "/etc/nginx/sites-available/$domain_name" fi - if grep -q "//addPlugin('Qvitter')" /var/www/$domain_name/htdocs/config.php; then - sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php + if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then + sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" fi - if grep -q "// addPlugin('Qvitter')" /var/www/$domain_name/htdocs/config.php; then - sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php + if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then + sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" fi - chown -R www-data:www-data /var/www/${domain_name}/htdocs + chown -R www-data:www-data "/var/www/${domain_name}/htdocs" systemctl restart nginx systemctl restart php7.0-fpm } function gnusocial_use_pleroma { - database_name=$1 + database_name="$1" domain_name=$(get_completion_param "$database_name domain") - if [ ! -d /var/www/$domain_name/htdocs/static ]; then + if [ ! -d "/var/www/$domain_name/htdocs/static" ]; then return fi - if [ -f /var/www/$domain_name/htdocs/index.php ]; then - mv /var/www/$domain_name/htdocs/index.php /var/www/$domain_name/htdocs/index_qvitter.php + if [ -f "/var/www/$domain_name/htdocs/index.php" ]; then + mv "/var/www/$domain_name/htdocs/index.php" "/var/www/$domain_name/htdocs/index_qvitter.php" fi - if [ -f /etc/nginx/sites-available/$domain_name ]; then - sed -i 's|index.php|index_qvitter.php|g' /etc/nginx/sites-available/$domain_name - sed -i 's|index index_qvitter.php|index index.html|g' /etc/nginx/sites-available/$domain_name + if [ -f "/etc/nginx/sites-available/$domain_name" ]; then + sed -i 's|index.php|index_qvitter.php|g' "/etc/nginx/sites-available/$domain_name" + sed -i 's|index index_qvitter.php|index index.html|g' "/etc/nginx/sites-available/$domain_name" fi - if grep -q "//addPlugin('Qvitter')" /var/www/$domain_name/htdocs/config.php; then - sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php + if grep -q "//addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then + sed -i "s|//addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" fi - if grep -q "// addPlugin('Qvitter')" /var/www/$domain_name/htdocs/config.php; then - sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" /var/www/$domain_name/htdocs/config.php + if grep -q "// addPlugin('Qvitter')" "/var/www/$domain_name/htdocs/config.php"; then + sed -i "s|// addPlugin('Qvitter')|addPlugin('Qvitter')|g" "/var/www/$domain_name/htdocs/config.php" fi - cp $INSTALL_DIR/pleroma/dist/index.html /var/www/${domain_name}/htdocs/index.html + cp "$INSTALL_DIR/pleroma/dist/index.html" "/var/www/${domain_name}/htdocs/index.html" chmod +x static/css chmod +x static/font chmod +x static/font/css chmod +x static/font/font chmod +x static/js chmod +x static - chown -R www-data:www-data /var/www/${domain_name}/htdocs + chown -R www-data:www-data "/var/www/${domain_name}/htdocs" systemctl restart nginx } function install_gnusocial_plugin_sharings { - domain_name=$1 - social_app_name=$2 + domain_name="$1" + social_app_name="$2" - if [ ! -d /var/www/$domain_name/htdocs/local/plugins ]; then - mkdir -p /var/www/$domain_name/htdocs/local/plugins + if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then + mkdir -p "/var/www/$domain_name/htdocs/local/plugins" fi apt-get -yq install liblocale-msgfmt-perl gettext # update to the next commit function_check set_repo_commit - set_repo_commit /var/www/$domain_name/htdocs/local/plugins/Sharings "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT" $SHARINGS_REPO + set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/Sharings" "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT" "$SHARINGS_REPO" - if [[ $(app_is_installed ${social_app_name}_plugin_sharings) == "1" ]]; then + if [[ $(app_is_installed "${social_app_name}_plugin_sharings") == "1" ]]; then return fi - cd /var/www/$domain_name/htdocs/local/plugins + cd "/var/www/$domain_name/htdocs/local/plugins" || exit 28746245 if [ -d /repos/sharings ]; then mkdir Sharings cp -r -p /repos/sharings/. Sharings - cd Sharings + cd Sharings || exit 25762454 git pull else function_check git_clone - git_clone $SHARINGS_REPO Sharings + git_clone "$SHARINGS_REPO" Sharings fi - if [ ! -d /var/www/$domain_name/htdocs/local/plugins/Sharings ]; then + if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/Sharings" ]; then echo $"Unable to clone $social_app_name sharings plugin" exit 36738 fi - cd /var/www/$domain_name/htdocs/local/plugins/Sharings + cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 2846244 git stash git checkout master - git branch -D $SHARINGS_COMMIT - git checkout $SHARINGS_COMMIT -b $SHARINGS_COMMIT + git branch -D "$SHARINGS_COMMIT" + git checkout "$SHARINGS_COMMIT" -b "$SHARINGS_COMMIT" # enable the plugin - if ! grep -q "addPlugin('Sharings');" /var/www/$domain_name/htdocs/config.php; then - echo "addPlugin('Sharings');" >> /var/www/$domain_name/htdocs/config.php + if ! grep -q "addPlugin('Sharings');" "/var/www/$domain_name/htdocs/config.php"; then + echo "addPlugin('Sharings');" >> "/var/www/$domain_name/htdocs/config.php" fi - cd /var/www/$domain_name/htdocs + cd "/var/www/$domain_name/htdocs" || exit 2684624874 php scripts/checkschema.php - cd /var/www/$domain_name/htdocs/local/plugins/Sharings + cd "/var/www/$domain_name/htdocs/local/plugins/Sharings" || exit 246824684 php scripts/seedsharings.php - cd /var/www/$domain_name/htdocs + cd "/var/www/$domain_name/htdocs" || exit 23524584 php scripts/upgrade.php php scripts/checkschema.php # Languages - cd /var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES + cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en/LC_MESSAGES" || exit 53825488 msgfmt -o Sharings.mo Sharings.po if [ ! -f Sharings.po ]; then echo $"English translations for $social_app_name sharings plugin were not created" exit 782923 fi - cd /var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES + cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_GB/LC_MESSAGES" || exit 268442845 msgfmt -o Sharings.mo Sharings.po if [ ! -f Sharings.po ]; then echo $"English (GB) translations for $social_app_name sharings plugin were not created" exit 23528 fi - cd /var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES + cd "/var/www/$domain_name/htdocs/local/plugins/Sharings/locale/en_US/LC_MESSAGES" || exit 264824628 msgfmt -o Sharings.mo Sharings.po if [ ! -f Sharings.po ]; then echo $"English (US) translations for $social_app_name sharings plugin were not created" @@ -898,107 +895,107 @@ function install_gnusocial_plugin_sharings { fi # Looks like this update function isn't supported by the current php version - sed -i 's|ActivityVerb::UPDATE, ||g' /var/www/$domain_name/htdocs/local/plugins/Sharings/SharingsPlugin.php + sed -i 's|ActivityVerb::UPDATE, ||g' "/var/www/$domain_name/htdocs/local/plugins/Sharings/SharingsPlugin.php" - chown -R www-data:www-data /var/www/$domain_name/htdocs + chown -R www-data:www-data "/var/www/$domain_name/htdocs" set_completion_param gnusocial "$social_app_name sharings plugin commit" "$SHARINGS_COMMIT" - install_completed ${social_app_name}_plugin_sharings + install_completed "${social_app_name}_plugin_sharings" } function install_gnusocial_plugin_sharings_theme { - domain_name=$1 - social_app_name=$2 + domain_name="$1" + social_app_name="$2" - if [ ! -d /var/www/$domain_name/htdocs/local/plugins ]; then - mkdir -p /var/www/$domain_name/htdocs/local/plugins + if [ ! -d "/var/www/$domain_name/htdocs/local/plugins" ]; then + mkdir -p "/var/www/$domain_name/htdocs/local/plugins" fi # update to the next commit function_check set_repo_commit - set_repo_commit /var/www/$domain_name/htdocs/local/plugins/SharingsTheme "$social_app_name sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" $SHARINGS_THEME_REPO + set_repo_commit "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" "$social_app_name sharings theme plugin commit" "$SHARINGS_THEME_COMMIT" "$SHARINGS_THEME_REPO" - if [[ $(app_is_installed ${social_app_name}_plugin_sharings_theme) == "1" ]]; then + if [[ $(app_is_installed "${social_app_name}_plugin_sharings_theme") == "1" ]]; then return fi - cd /var/www/$domain_name/htdocs/local/plugins + cd "/var/www/$domain_name/htdocs/local/plugins" || exit 682425642 function_check git_clone - git_clone $SHARINGS_THEME_REPO SharingsTheme - if [ ! -d /var/www/$domain_name/htdocs/local/plugins/SharingsTheme ]; then + git_clone "$SHARINGS_THEME_REPO" SharingsTheme + if [ ! -d "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" ]; then echo $"Unable to clone $social_app_name sharings plugin theme" exit 639253 fi - cd /var/www/$domain_name/htdocs/local/plugins/SharingsTheme + cd "/var/www/$domain_name/htdocs/local/plugins/SharingsTheme" || exit 2648724684 git stash git checkout master - git branch -D $SHARINGS_THEME_COMMIT - git checkout $SHARINGS_THEME_COMMIT -b $SHARINGS_THEME_COMMIT + git branch -D "$SHARINGS_THEME_COMMIT" + git checkout "$SHARINGS_THEME_COMMIT" -b "$SHARINGS_THEME_COMMIT" # enable the plugin - if ! grep -q "addPlugin('SharingsTheme');" /var/www/$domain_name/htdocs/config.php; then - echo "addPlugin('SharingsTheme');" >> /var/www/$domain_name/htdocs/config.php + if ! grep -q "addPlugin('SharingsTheme');" "/var/www/$domain_name/htdocs/config.php"; then + echo "addPlugin('SharingsTheme');" >> "/var/www/$domain_name/htdocs/config.php" fi - cd /var/www/$domain_name/htdocs + cd "/var/www/$domain_name/htdocs" || exit 246824624 php scripts/checkschema.php - chown -R www-data:www-data /var/www/$domain_name/htdocs + chown -R www-data:www-data "/var/www/$domain_name/htdocs" set_completion_param "$social_app_name sharings plugin theme commit" "$SHARINGS_THEME_COMMIT" - install_completed ${social_app_name}_plugin_sharings_theme + install_completed "${social_app_name}_plugin_sharings_theme" } function install_gnusocial_markdown { - domain_name=$1 - social_app_name=$2 + domain_name="$1" + social_app_name="$2" - GNUSOCIAL_PATH=/var/www/$domain_name/htdocs + GNUSOCIAL_PATH="/var/www/$domain_name/htdocs" # update to the next commit function_check set_repo_commit - set_repo_commit $GNUSOCIAL_PATH/local/plugins/Markdown "$social_app_name Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" $GNUSOCIAL_MARKDOWN_REPO + set_repo_commit "$GNUSOCIAL_PATH/local/plugins/Markdown" "$social_app_name Markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" "$GNUSOCIAL_MARKDOWN_REPO" - if [[ $(app_is_installed ${social_app_name}_markdown) == "1" ]]; then + if [[ $(app_is_installed "${social_app_name}_markdown") == "1" ]]; then return fi - if [ -d $GNUSOCIAL_PATH/local/plugins/Markdown ]; then - rm -rf $GNUSOCIAL_PATH/local/plugins/Markdown + if [ -d "$GNUSOCIAL_PATH/local/plugins/Markdown" ]; then + rm -rf "$GNUSOCIAL_PATH/local/plugins/Markdown" fi - if [ ! -d $GNUSOCIAL_PATH/local/plugins ]; then - mkdir -p $GNUSOCIAL_PATH/local/plugins + if [ ! -d "$GNUSOCIAL_PATH/local/plugins" ]; then + mkdir -p "$GNUSOCIAL_PATH/local/plugins" fi - cd $GNUSOCIAL_PATH/local/plugins + cd "$GNUSOCIAL_PATH/local/plugins" || exit 268476248 if [ -d /repos/gnusocial-markdown ]; then mkdir Markdown cp -r -p /repos/gnusocial-markdown/. Markdown - cd Markdown + cd Markdown || exit 62847524 git pull else function_check git_clone - git_clone $GNUSOCIAL_MARKDOWN_REPO Markdown + git_clone "$GNUSOCIAL_MARKDOWN_REPO" Markdown fi - cd $GNUSOCIAL_PATH/local/plugins/Markdown - git checkout $GNUSOCIAL_MARKDOWN_COMMIT -b $GNUSOCIAL_MARKDOWN_COMMIT + cd "$GNUSOCIAL_PATH/local/plugins/Markdown" || exit 26584526745 + git checkout "$GNUSOCIAL_MARKDOWN_COMMIT" -b "$GNUSOCIAL_MARKDOWN_COMMIT" - gnusocial_config_file=$GNUSOCIAL_PATH/config.php - if ! grep -q "addPlugin('Markdown'" $gnusocial_config_file; then - echo "" >> $gnusocial_config_file - echo "// Markdown settings" >> $gnusocial_config_file - echo "addPlugin('Markdown');" >> $gnusocial_config_file + gnusocial_config_file="$GNUSOCIAL_PATH/config.php" + if ! grep -q "addPlugin('Markdown'" "$gnusocial_config_file"; then + { echo ""; + echo "// Markdown settings"; + echo "addPlugin('Markdown');"; } >> "$gnusocial_config_file" fi set_completion_param "$social_app_name markdown commit" "$GNUSOCIAL_MARKDOWN_COMMIT" - chown -R www-data:www-data $GNUSOCIAL_PATH + chown -R www-data:www-data "$GNUSOCIAL_PATH" - install_completed ${social_app_name}_markdown + install_completed "${social_app_name}_markdown" } # NOTE: deliberately there is no "exit 0"