Bob Mottram 7 年之前
父節點
當前提交
ec6e2e5851

+ 1
- 1
src/freedombone-utils-passwords 查看文件

@@ -51,7 +51,7 @@ function enforce_good_passwords {
51 51
 }
52 52
 
53 53
 function create_password {
54
-    openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c ${1} ; echo -n ''
54
+    openssl rand -base64 32 | tr -dc A-Za-z0-9 | head -c "${1}" ; echo -n ''
55 55
 }
56 56
 
57 57
 # NOTE: deliberately no exit 0

+ 33
- 30
src/freedombone-utils-postgresql 查看文件

@@ -35,14 +35,14 @@ POSTGRESQL_PACKAGES='postgresql-9.6 postgresql-contrib-9.6 postgresql-client'
35 35
 function store_original_postgresql_password {
36 36
     if [ ! -f /root/.postgresqloriginal ]; then
37 37
         echo $'Storing original postgresql password'
38
-        ORIGINAL_POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
38
+        ORIGINAL_POSTGRESQL_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a postgresql)
39 39
         # We can store this in plaintext because it will soon be of historical interest only
40 40
         echo -n "$ORIGINAL_POSTGRESQL_PASSWORD" > /root/.postgresqloriginal
41 41
     fi
42 42
 }
43 43
 
44 44
 function get_postgresql_password {
45
-    POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
45
+    POSTGRESQL_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a postgresql)
46 46
     if [[ "$POSTGRESQL_PASSWORD" == *'failed'* ]]; then
47 47
         echo $'Could not obtain postgresql password'
48 48
         exit 7835272
@@ -50,14 +50,15 @@ function get_postgresql_password {
50 50
 }
51 51
 
52 52
 function mesh_install_postgresql {
53
-    chroot "$rootdir" apt-get -yq install $POSTGRESQL_PACKAGES
53
+    # shellcheck disable=SC2154
54
+    chroot "$rootdir" apt-get -yq install "$POSTGRESQL_PACKAGES"
54 55
 
55
-    if [ ! -d $rootdir/etc/postgresql ]; then
56
+    if [ ! -d "$rootdir/etc/postgresql" ]; then
56 57
         echo $"ERROR: postgresql does not appear to have installed."
57 58
         exit 78352
58 59
     fi
59 60
 
60
-    if [ ! -f $rootdir/usr/bin/psql ]; then
61
+    if [ ! -f "$rootdir/usr/bin/psql" ]; then
61 62
         echo $"ERROR: psql command does not appear to have installed."
62 63
         exit 835290
63 64
     fi
@@ -75,16 +76,16 @@ function install_postgresql {
75 76
 
76 77
     function_check get_postgresql_password
77 78
     get_postgresql_password
78
-    if [ ! $POSTGRESQL_PASSWORD ]; then
79
-        if [ -f $IMAGE_PASSWORD_FILE ]; then
80
-            POSTGRESQL_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
79
+    if [ ! "$POSTGRESQL_PASSWORD" ]; then
80
+        if [ -f "$IMAGE_PASSWORD_FILE" ]; then
81
+            POSTGRESQL_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
81 82
         else
82
-            POSTGRESQL_PASSWORD="$(openssl rand -base64 32 | cut -c1-${MINIMUM_PASSWORD_LENGTH})"
83
+            POSTGRESQL_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
83 84
         fi
84 85
     fi
85
-    ${PROJECT_NAME}-pass -u root -a postgresql -p "$POSTGRESQL_PASSWORD"
86
+    "${PROJECT_NAME}-pass" -u root -a postgresql -p "$POSTGRESQL_PASSWORD"
86 87
 
87
-    apt-get -yq install $POSTGRESQL_PACKAGES
88
+    apt-get -yq install "$POSTGRESQL_PACKAGES"
88 89
     apt-get -yq remove --purge apache2-bin*
89 90
     if [ -d /etc/apache2 ]; then
90 91
         rm -rf /etc/apache2
@@ -107,7 +108,7 @@ function install_postgresql {
107 108
 function add_postgresql_user {
108 109
     postgresql_username=$1
109 110
     postgresql_password=$2
110
-    cd /etc/postgresql
111
+    cd /etc/postgresql || exit 2468246
111 112
     if [[ "$3" != 'encrypt'* ]]; then
112 113
         sudo -u postgres psql -c "create user $postgresql_username password '$postgresql_password';"
113 114
     else
@@ -118,14 +119,14 @@ function add_postgresql_user {
118 119
 
119 120
 function remove_postgresql_user {
120 121
     postgresql_username=$1
121
-    cd /etc/postgresql
122
+    cd /etc/postgresql || exit 24624624
122 123
     sudo -u postgres psql -c "drop user $postgresql_username"
123 124
 }
124 125
 
125 126
 function drop_database_postgresql {
126 127
     database_name="$1"
127 128
     database_owner_name="$2"
128
-    cd /etc/postgresql
129
+    cd /etc/postgresql || exit 2482468242
129 130
     sudo -u postgres psql -c "drop database $database_name"
130 131
     if [ ${#database_owner_name} -gt 0 ]; then
131 132
         sudo -u postgres psql -c "drop user $database_owner_name"
@@ -134,31 +135,31 @@ function drop_database_postgresql {
134 135
 
135 136
 function run_system_query_postgresql {
136 137
     query=$1
137
-    cd /etc/postgresql
138
+    cd /etc/postgresql || exit 24624649846
138 139
     sudo -u postgres psql -c "$query"
139 140
 }
140 141
 
141 142
 function run_query_postgresql {
142 143
     database_name=$1
143 144
     database_query=$2
144
-    cd /etc/postgresql
145
-    sudo -u postgres psql -d $database_name -c "$database_query"
145
+    cd /etc/postgresql || exit 2492464684
146
+    sudo -u postgres psql -d "$database_name" -c "$database_query"
146 147
 }
147 148
 
148 149
 function run_query_postgresql_with_output {
149 150
     database_name=$1
150 151
     database_query=$2
151
-    cd /etc/postgresql
152
-    output=$(sudo -u postgres psql -d $database_name -c "$database_query")
152
+    cd /etc/postgresql || exit 2482462846
153
+    output=$(sudo -u postgres psql -d "$database_name" -c "$database_query")
153 154
     echo "$output"
154 155
 }
155 156
 
156 157
 function initialise_database_postgresql {
157 158
     database_name=$1
158 159
     database_file=$2
159
-    cd /etc/postgresql
160
-    sudo -u postgres psql $database_name < $database_file
161
-    if [ ! "$?" = "0" ]; then
160
+    cd /etc/postgresql || exit 239246992469
161
+    # shellcheck disable=SC2024
162
+    if ! sudo -u postgres psql "$database_name" < "$database_file"; then
162 163
         exit 7238525
163 164
     fi
164 165
 }
@@ -167,10 +168,10 @@ function create_database_postgresql {
167 168
     app_name="$1"
168 169
     app_admin_password="$2"
169 170
     app_admin_username=$3
170
-    if [ ! -d $INSTALL_DIR ]; then
171
-        mkdir $INSTALL_DIR
171
+    if [ ! -d "$INSTALL_DIR" ]; then
172
+        mkdir "$INSTALL_DIR"
172 173
     fi
173
-    if [ ! $app_admin_username ]; then
174
+    if [ ! "$app_admin_username" ]; then
174 175
         app_admin_username=${app_name}admin
175 176
     fi
176 177
 
@@ -178,9 +179,11 @@ function create_database_postgresql {
178 179
 CREATE USER '$app_admin_username@localhost' IDENTIFIED BY '${app_admin_password}';
179 180
 GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
180 181
 flush privileges;
181
-quit" > $INSTALL_DIR/batch.sql
182
-    chmod 600 $INSTALL_DIR/batch.sql
183
-    cd /etc/postgresql
184
-    sudo -u postgres psql -d $database_name --file=$INSTALL_DIR/batch.sql
185
-    shred -zu $INSTALL_DIR/batch.sql
182
+quit" > "$INSTALL_DIR/batch.sql"
183
+    chmod 600 "$INSTALL_DIR/batch.sql"
184
+    cd /etc/postgresql || exit 247284684
185
+    sudo -u postgres psql -d "$database_name" --file="$INSTALL_DIR/batch.sql"
186
+    shred -zu "$INSTALL_DIR/batch.sql"
186 187
 }
188
+
189
+# NOTE: deliberately there is no "exit 0"

+ 33
- 33
src/freedombone-utils-repos 查看文件

@@ -38,17 +38,17 @@ function create_repo_sources {
38 38
     rm -rf /var/lib/apt/lists/*
39 39
     apt-get clean
40 40
 
41
-    echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" > /etc/apt/sources.list
42
-    echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main" >> /etc/apt/sources.list
43
-    echo '' >> /etc/apt/sources.list
44
-    echo "deb http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list
45
-    echo "deb-src http://security.debian.org/ ${DEBIAN_VERSION}/updates main" >> /etc/apt/sources.list
46
-    echo '' >> /etc/apt/sources.list
47
-    echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list
48
-    echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main" >> /etc/apt/sources.list
49
-    echo '' >> /etc/apt/sources.list
50
-    echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list
51
-    echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main" >> /etc/apt/sources.list
41
+    { echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main";
42
+      echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION} main";
43
+      echo '';
44
+      echo "deb http://security.debian.org/ ${DEBIAN_VERSION}/updates main";
45
+      echo "deb-src http://security.debian.org/ ${DEBIAN_VERSION}/updates main";
46
+      echo '';
47
+      echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main";
48
+      echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-updates main";
49
+      echo '';
50
+      echo "deb http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main";
51
+      echo "deb-src http://${DEBIAN_REPO}/debian/ ${DEBIAN_VERSION}-backports main"; } > /etc/apt/sources.list
52 52
 
53 53
     apt-get update
54 54
     apt-get -yq install apt-transport-https
@@ -63,28 +63,28 @@ function create_git_project {
63 63
     fi
64 64
     apt-get -yq install git
65 65
 
66
-    echo '#!/bin/bash' > /usr/bin/$CREATE_GIT_PROJECT_COMMAND
67
-    echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
68
-    echo 'GIT_PROJECT_NAME=$1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
69
-    echo 'if [ ! $GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
70
-    echo '  echo "Please specify a project name, without any spaces"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
71
-    echo '  exit 1' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
72
-    echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
73
-    echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
74
-    echo 'if [ ! -d /home/$USER/projects/$GIT_PROJECT_NAME ]; then' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
75
-    echo '  mkdir -p /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
76
-    echo 'fi' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
77
-    echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
78
-    echo 'cd /home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
79
-    echo 'git init --bare' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
80
-    echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
81
-    echo -n 'echo "Your project has been created, ' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
82
-    echo 'use the following command to clone the repository"' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
83
-    echo -n "  git clone ssh://$MY_USERNAME@$DEFAULT_DOMAIN_NAME:$SSH_PORT" >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
84
-    echo '/home/$USER/projects/$GIT_PROJECT_NAME' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
85
-    echo '' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
86
-    echo 'exit 0' >> /usr/bin/$CREATE_GIT_PROJECT_COMMAND
87
-    chmod +x /usr/bin/$CREATE_GIT_PROJECT_COMMAND
66
+    { echo '#!/bin/bash';
67
+      echo '';
68
+      echo "GIT_PROJECT_NAME=\$1";
69
+      echo "if [ ! \$GIT_PROJECT_NAME ]; then";
70
+      echo '  echo "Please specify a project name, without any spaces"';
71
+      echo '  exit 1';
72
+      echo 'fi';
73
+      echo '';
74
+      echo "if [ ! -d /home/\$USER/projects/\$GIT_PROJECT_NAME ]; then";
75
+      echo "  mkdir -p /home/\$USER/projects/\$GIT_PROJECT_NAME";
76
+      echo 'fi';
77
+      echo '';
78
+      echo "cd /home/\$USER/projects/\$GIT_PROJECT_NAME";
79
+      echo 'git init --bare';
80
+      echo '';
81
+      echo -n 'echo "Your project has been created, ';
82
+      echo 'use the following command to clone the repository"';
83
+      echo -n "  git clone ssh://$MY_USERNAME@$DEFAULT_DOMAIN_NAME:$SSH_PORT";
84
+      echo "/home/\$USER/projects/\$GIT_PROJECT_NAME";
85
+      echo '';
86
+      echo 'exit 0'; } > "/usr/bin/$CREATE_GIT_PROJECT_COMMAND"
87
+    chmod +x "/usr/bin/$CREATE_GIT_PROJECT_COMMAND"
88 88
 
89 89
     mark_completed "${FUNCNAME[0]}"
90 90
 }

+ 8
- 8
src/freedombone-utils-rng 查看文件

@@ -66,11 +66,11 @@ function check_onerng_verification {
66 66
         return
67 67
     fi
68 68
     echo $'Checking OneRNG firmware verification'
69
-    last_onerng_validation=$(cat /var/log/syslog.1 | grep "OneRNG: firmware verification" | awk '/./{line=$0} END{print line}')
69
+    last_onerng_validation=$(grep "OneRNG: firmware verification" /var/log/syslog.1 | awk '/./{line=$0} END{print line}')
70 70
     if [[ $last_onerng_validation != *"passed OK"* ]]; then
71
-        last_onerng_validation=$(cat /var/log/syslog | grep "OneRNG: firmware verification" | awk '/./{line=$0} END{print line}')
71
+        last_onerng_validation=$(grep "OneRNG: firmware verification" /var/log/syslog | awk '/./{line=$0} END{print line}')
72 72
         if [[ $last_onerng_validation != *"passed OK"* ]]; then
73
-            echo $last_onerng_validation
73
+            echo "$last_onerng_validation"
74 74
             echo $'OneRNG firmware verification failed'
75 75
             exit 735026
76 76
         fi
@@ -85,14 +85,14 @@ function install_onerng {
85 85
     apt-get -yq install rng-tools at python-gnupg
86 86
 
87 87
     # Move to the installation directory
88
-    if [ ! -d $INSTALL_DIR ]; then
89
-        mkdir $INSTALL_DIR
88
+    if [ ! -d "$INSTALL_DIR" ]; then
89
+        mkdir "$INSTALL_DIR"
90 90
     fi
91
-    cd $INSTALL_DIR
91
+    cd "$INSTALL_DIR" || exit 24762464
92 92
 
93 93
     # Download the package
94 94
     if [ ! -f $ONERNG_PACKAGE ]; then
95
-        wget $ONERNG_PACKAGE_DOWNLOAD
95
+        wget "$ONERNG_PACKAGE_DOWNLOAD"
96 96
         mv "$ONERNG_PACKAGE?raw=true" $ONERNG_PACKAGE
97 97
     fi
98 98
     if [ ! -f $ONERNG_PACKAGE ]; then
@@ -102,7 +102,7 @@ function install_onerng {
102 102
 
103 103
     # Check the hash
104 104
     hash=$(sha256sum $ONERNG_PACKAGE | awk -F ' ' '{print $1}')
105
-    if [[ $hash != $ONERNG_PACKAGE_HASH ]]; then
105
+    if [[ "$hash" != "$ONERNG_PACKAGE_HASH" ]]; then
106 106
         echo $"OneRNG package: $ONERNG_PACKAGE"
107 107
         echo $"Hash does not match. This could indicate that the package has been tampered with."
108 108
         echo $"OneRNG expected package hash: $ONERNG_PACKAGE_HASH"

+ 88
- 83
src/freedombone-utils-selector 查看文件

@@ -49,8 +49,8 @@ INSTALLED_APPS_LIST=/usr/share/${PROJECT_NAME}/installed.txt
49 49
 # so that when a new app is added existing users can be added
50 50
 APP_USERS_FILE=$HOME/app_users.txt
51 51
 
52
-if [ ! $COMPLETION_FILE ]; then
53
-    COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
52
+if [ ! "$COMPLETION_FILE" ]; then
53
+    COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
54 54
 fi
55 55
 
56 56
 # Loads variables defined at the beginning of an app script
@@ -58,16 +58,20 @@ function app_load_variables {
58 58
     app_name=$1
59 59
 
60 60
     config_var_name=${app_name}_variables
61
+    # shellcheck disable=SC2086
61 62
     if [ ! ${!config_var_name} ]; then
62 63
         echo $"${app_name}_variables was not found"
63 64
         return
64 65
     fi
65 66
 
67
+    #shellcheck disable=SC1087,SC2125,SC2178
66 68
     configvarname=$config_var_name[@]
69
+
70
+    #shellcheck disable=SC2206
67 71
     configvarname=( ${!configvarname} )
68 72
     for v in "${configvarname[@]}"
69 73
     do
70
-        read_config_param $v
74
+        read_config_param "$v"
71 75
     done
72 76
 }
73 77
 
@@ -76,22 +80,26 @@ function app_save_variables {
76 80
     app_name=$1
77 81
 
78 82
     config_var_name=${app_name}_variables
83
+    #shellcheck disable=SC2086
79 84
     if [ ! ${!config_var_name} ]; then
80 85
         return
81 86
     fi
82 87
 
88
+    #shellcheck disable=SC1087,SC2125,SC2178
83 89
     configvarname=$config_var_name[@]
90
+
91
+    #shellcheck disable=SC2206
84 92
     configvarname=( ${!configvarname} )
85 93
     for v in "${configvarname[@]}"
86 94
     do
87
-        write_config_param $v "${!v}"
95
+        write_config_param "$v" "${!v}"
88 96
     done
89 97
 }
90 98
 
91 99
 # gets the variants list from an app script
92 100
 function app_variants {
93 101
     filename=$1
94
-    variants_line=$(cat ${filename} | grep 'VARIANTS=')
102
+    variants_line=$(grep 'VARIANTS=' "${filename}")
95 103
     if [[ "$variants_line" == *"'"* ]]; then
96 104
         variants_list=$(echo "$variants_line" | awk -F '=' '{print $2}' | awk -F "'" '{print $2}')
97 105
     else
@@ -112,21 +120,22 @@ function item_in_array {
112 120
 function available_system_variants {
113 121
     function_check item_in_array
114 122
 
115
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
123
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
116 124
 
117 125
     new_available_variants_list=()
118 126
     for filename in $FILES
119 127
     do
120
-        system_variants_list=$(app_variants $filename)
128
+        system_variants_list=$(app_variants "$filename")
129
+        # shellcheck disable=SC2206
121 130
         variants_array=($system_variants_list)
122 131
         for variant_str in "${variants_array[@]}"
123 132
         do
124
-            item_in_array "${variant_str}" "${new_available_variants_list[@]}"
125
-            if [[ $? != 0 ]]; then
133
+            if ! item_in_array "${variant_str}" "${new_available_variants_list[@]}"; then
126 134
                 new_available_variants_list+=("$variant_str")
127 135
             fi
128 136
         done
129 137
     done
138
+    # shellcheck disable=SC2207
130 139
     available_variants_list=($(sort <<<"${new_available_variants_list[*]}"))
131 140
 }
132 141
 
@@ -167,11 +176,11 @@ function remove_app {
167 176
     if ! grep -Fxq "_${app_name}_" $REMOVED_APPS_FILE; then
168 177
         echo "_${app_name}_" >> $REMOVED_APPS_FILE
169 178
     fi
170
-    if grep -Fxq "install_${app_name}" $COMPLETION_FILE; then
171
-        sed -i "/install_${app_name}/d" $COMPLETION_FILE
179
+    if grep -Fxq "install_${app_name}" "$COMPLETION_FILE"; then
180
+        sed -i "/install_${app_name}/d" "$COMPLETION_FILE"
172 181
     fi
173
-    if grep -Fxq "install_${app_name}" $INSTALLED_APPS_LIST; then
174
-        sed -i "/install_${app_name}/d" $INSTALLED_APPS_LIST
182
+    if grep -Fxq "install_${app_name}" "$INSTALLED_APPS_LIST"; then
183
+        sed -i "/install_${app_name}/d" "$INSTALLED_APPS_LIST"
175 184
     fi
176 185
 }
177 186
 
@@ -196,7 +205,7 @@ function reinstall_app {
196 205
     if [ ! -f $REMOVED_APPS_FILE ]; then
197 206
         return
198 207
     fi
199
-    if [[ $(app_is_removed $app_name) == "1" ]]; then
208
+    if [[ $(app_is_removed "$app_name") == "1" ]]; then
200 209
         sed -i "/_${app_name}_/d" $REMOVED_APPS_FILE
201 210
     fi
202 211
 }
@@ -207,8 +216,8 @@ function app_is_installed {
207 216
 
208 217
     # Why does this secondary file exist, apart from COMPLETION_FILE ?
209 218
     # It's so that it is visible to unprivileged users from the user control panel
210
-    if [ -f $INSTALLED_APPS_LIST ]; then
211
-        if ! grep -Fxq "install_${app_name}" $INSTALLED_APPS_LIST; then
219
+    if [ -f "$INSTALLED_APPS_LIST" ]; then
220
+        if ! grep -Fxq "install_${app_name}" "$INSTALLED_APPS_LIST"; then
212 221
             echo "0"
213 222
         else
214 223
             echo "1"
@@ -217,12 +226,12 @@ function app_is_installed {
217 226
     fi
218 227
 
219 228
     # check the completion file to see if it was installed
220
-    if [ ! -f $COMPLETION_FILE ]; then
229
+    if [ ! -f "$COMPLETION_FILE" ]; then
221 230
         echo "0"
222 231
         return
223 232
     fi
224 233
 
225
-    if ! grep -Fxq "install_${app_name}" $COMPLETION_FILE; then
234
+    if ! grep -Fxq "install_${app_name}" "$COMPLETION_FILE"; then
226 235
         echo "0"
227 236
     else
228 237
         echo "1"
@@ -231,11 +240,11 @@ function app_is_installed {
231 240
 
232 241
 # called at the end of the install section of an app script
233 242
 function install_completed {
234
-    if [ ! ${1} ]; then
243
+    if [ ! "${1}" ]; then
235 244
         exit 673935
236 245
     fi
237
-    if ! grep -Fxq "install_${1}" $COMPLETION_FILE; then
238
-        echo "install_${1}" >> $COMPLETION_FILE
246
+    if ! grep -Fxq "install_${1}" "$COMPLETION_FILE"; then
247
+        echo "install_${1}" >> "$COMPLETION_FILE"
239 248
     fi
240 249
 }
241 250
 
@@ -243,7 +252,7 @@ function install_completed {
243 252
 function get_apps_installed {
244 253
     for a in "${APPS_AVAILABLE[@]}"
245 254
     do
246
-        APPS_INSTALLED+=("$(app_is_installed $a)")
255
+        APPS_INSTALLED+=("$(app_is_installed "$a")")
247 256
     done
248 257
 }
249 258
 
@@ -252,7 +261,7 @@ function get_apps_installed_names {
252 261
     APPS_INSTALLED_NAMES=()
253 262
     for a in "${APPS_AVAILABLE[@]}"
254 263
     do
255
-        if [[ $(app_is_installed $a) == "1" ]]; then
264
+        if [[ $(app_is_installed "$a") == "1" ]]; then
256 265
             APPS_INSTALLED_NAMES+=("$a")
257 266
         fi
258 267
     done
@@ -260,7 +269,7 @@ function get_apps_installed_names {
260 269
 
261 270
 # detects what apps are available
262 271
 function detect_apps {
263
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
272
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
264 273
 
265 274
     function_check item_in_array
266 275
 
@@ -272,8 +281,7 @@ function detect_apps {
272 281
     do
273 282
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
274 283
 
275
-        item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
276
-        if [[ $? != 0 ]]; then
284
+        if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then
277 285
             APPS_AVAILABLE+=("${app_name}")
278 286
             APPS_CHOSEN+=("0")
279 287
         fi
@@ -288,7 +296,7 @@ function detect_apps {
288 296
 # If the variants list within an app script is an empty string then
289 297
 # it is considered to be too experimental to be installable
290 298
 function detect_installable_apps {
291
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
299
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
292 300
 
293 301
     APPS_AVAILABLE=()
294 302
     APPS_CHOSEN=()
@@ -304,15 +312,14 @@ function detect_installable_apps {
304 312
     do
305 313
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
306 314
 
307
-        item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
308
-        if [[ $? != 0 ]]; then
309
-            variants_list=$(app_variants $filename)
315
+        if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then
316
+            variants_list=$(app_variants "$filename")
310 317
             # check for empty string
311 318
             if [ ${#variants_list} -gt 0 ]; then
312 319
                 APPS_AVAILABLE+=("${app_name}")
313 320
                 APPS_CHOSEN+=("0")
314
-                APPS_INSTALLED+=("$(app_is_installed $app_name)")
315
-                if [[ $(app_is_installed $app_name) == "1" ]]; then
321
+                APPS_INSTALLED+=("$(app_is_installed "$app_name")")
322
+                if [[ $(app_is_installed "$app_name") == "1" ]]; then
316 323
                     APPS_INSTALLED_NAMES+=("$app_name")
317 324
                 fi
318 325
             fi
@@ -321,7 +328,7 @@ function detect_installable_apps {
321 328
 }
322 329
 
323 330
 function detect_installed_apps {
324
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
331
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
325 332
 
326 333
     APPS_AVAILABLE=()
327 334
     APPS_INSTALLED=()
@@ -336,10 +343,9 @@ function detect_installed_apps {
336 343
     do
337 344
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
338 345
 
339
-        if [[ $(app_is_installed $app_name) == "1" ]]; then
340
-            item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
341
-            if [[ $? != 0 ]]; then
342
-                variants_list=$(app_variants $filename)
346
+        if [[ $(app_is_installed "$app_name") == "1" ]]; then
347
+            if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then
348
+                variants_list=$(app_variants "$filename")
343 349
                 if [ ${#variants_list} -gt 0 ]; then
344 350
                     APPS_AVAILABLE+=("${app_name}")
345 351
                     APPS_INSTALLED_NAMES+=("$app_name")
@@ -363,7 +369,7 @@ function choose_apps_for_variant {
363 369
         exit 237567
364 370
     fi
365 371
 
366
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
372
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
367 373
 
368 374
     APPS_CHOSEN=()
369 375
 
@@ -372,16 +378,15 @@ function choose_apps_for_variant {
372 378
     do
373 379
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
374 380
 
375
-        item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"
376
-        if [[ $? == 0 ]]; then
377
-            if grep -q "VARIANTS=" ${filename}; then
378
-                variants_list=$(app_variants $filename)
381
+        if item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then
382
+            if grep -q "VARIANTS=" "${filename}"; then
383
+                variants_list=$(app_variants "$filename")
379 384
                 if [[ "${variants_list}" == 'all'* || \
380 385
                       "${variants_list}" == "$variant_name" || \
381 386
                       "${variants_list}" == "$variant_name "* || \
382 387
                       "${variants_list}" == *" $variant_name "* || \
383 388
                       "${variants_list}" == *" $variant_name" ]]; then
384
-                    if [[ $(app_is_removed ${a}) == "0" ]]; then
389
+                    if [[ $(app_is_removed "${a}") == "0" ]]; then
385 390
                         #echo $"${app_name} chosen"
386 391
                         APPS_CHOSEN+=("1")
387 392
                     else
@@ -408,7 +413,7 @@ function list_chosen_apps {
408 413
         if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
409 414
             echo $"${a}"
410 415
         fi
411
-        app_index=$[app_index+1]
416
+        app_index=$((app_index+1))
412 417
     done
413 418
 }
414 419
 
@@ -421,23 +426,23 @@ function remove_apps {
421 426
                 echo $"Removing users for application: ${a}"
422 427
 
423 428
                 function_check remove_users_for_app
424
-                remove_users_for_app ${a}
429
+                remove_users_for_app "${a}"
425 430
 
426 431
                 echo $"Removing application: ${a}"
427 432
 
428 433
                 function_check app_load_variables
429
-                app_load_variables ${a}
434
+                app_load_variables "${a}"
430 435
 
431 436
                 function_check remove_app
432
-                remove_app ${a}
437
+                remove_app "${a}"
433 438
 
434
-                function_check remove_${a}
435
-                remove_${a}
439
+                function_check "remove_${a}"
440
+                "remove_${a}"
436 441
 
437 442
                 echo $"${a} was removed"
438 443
             fi
439 444
         fi
440
-        app_index=$[app_index+1]
445
+        app_index=$((app_index+1))
441 446
     done
442 447
     update_installed_apps_list
443 448
 }
@@ -450,13 +455,13 @@ function install_apps_interactive {
450 455
         if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then
451 456
             if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then
452 457
                 # interactively obtain settings for this app
453
-                if [[ $(function_exists install_interactive_${a}) == "1" ]]; then
454
-                    install_interactive_${a}
458
+                if [[ $(function_exists "install_interactive_${a}") == "1" ]]; then
459
+                    "install_interactive_${a}"
455 460
                 fi
456 461
             fi
457 462
         fi
458 463
 
459
-        app_index=$[app_index+1]
464
+        app_index=$((app_index+1))
460 465
     done
461 466
     echo $"Interactive settings complete"
462 467
 }
@@ -466,8 +471,8 @@ function user_added_to_app {
466 471
     app_name="$2"
467 472
 
468 473
     if [[ $(is_valid_user "$user_name") == "1" ]]; then
469
-        if [[ $(function_exists add_user_${app_name}) == "1" ]]; then
470
-            if grep -Fxq "${app_name}_${user_name}" $APP_USERS_FILE; then
474
+        if [[ $(function_exists "add_user_${app_name}") == "1" ]]; then
475
+            if grep -Fxq "${app_name}_${user_name}" "$APP_USERS_FILE"; then
471 476
                 echo "1"
472 477
                 return
473 478
             fi
@@ -482,7 +487,7 @@ function add_users_after_install {
482 487
     read_config_param MY_USERNAME
483 488
 
484 489
     # ensure a minimum password length
485
-    if [ ! $MINIMUM_PASSWORD_LENGTH ]; then
490
+    if [ ! "$MINIMUM_PASSWORD_LENGTH" ]; then
486 491
         MINIMUM_PASSWORD_LENGTH=20
487 492
     fi
488 493
     if [ ${#MINIMUM_PASSWORD_LENGTH} -lt 20 ]; then
@@ -490,7 +495,7 @@ function add_users_after_install {
490 495
     fi
491 496
 
492 497
     ADMIN_USERNAME=$(get_completion_param "Admin user")
493
-    if [ ! $ADMIN_USERNAME ]; then
498
+    if [ ! "$ADMIN_USERNAME" ]; then
494 499
         ADMIN_USERNAME=$MY_USERNAME
495 500
     fi
496 501
 
@@ -501,8 +506,8 @@ function add_users_after_install {
501 506
                 if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "0" ]]; then
502 507
                     valstr=$"Login for user ${USERNAME}="
503 508
                     app_password="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
504
-                    add_user_${app_name} "${USERNAME}" "${app_password}"
505
-                    echo "${app_name}_${USERNAME}" >> $APP_USERS_FILE
509
+                    "add_user_${app_name}" "${USERNAME}" "${app_password}"
510
+                    echo "${app_name}_${USERNAME}" >> "$APP_USERS_FILE"
506 511
                 fi
507 512
             fi
508 513
         fi
@@ -519,10 +524,10 @@ function remove_users_for_app {
519 524
         if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
520 525
             if [[ "$USERNAME" != "$MY_USERNAME" ]]; then
521 526
                 if [[ $(user_added_to_app "${USERNAME}" "${app_name}") == "1" ]]; then
522
-                    if [[ $(function_exists remove_user_${app_name}) == "1" ]]; then
523
-                        remove_user_${app_name} "${USERNAME}"
527
+                    if [[ $(function_exists "remove_user_${app_name}") == "1" ]]; then
528
+                        "remove_user_${app_name}" "${USERNAME}"
524 529
                     fi
525
-                    sed -i "/${app_name}_${USERNAME}/d" $APP_USERS_FILE
530
+                    sed -i "/${app_name}_${USERNAME}/d" "$APP_USERS_FILE"
526 531
                 fi
527 532
             fi
528 533
         fi
@@ -535,7 +540,7 @@ function install_apps {
535 540
     APP_INSTALLED_SUCCESS=1
536 541
 
537 542
     # interactive install configuration for each app
538
-    if [ ${is_interactive} ]; then
543
+    if [ "${is_interactive}" ]; then
539 544
         install_apps_interactive
540 545
     fi
541 546
 
@@ -549,69 +554,69 @@ function install_apps {
549 554
                 # remove any temp files
550 555
                 rm -rf /tmp/*
551 556
 
552
-                if [ ${is_interactive} ]; then
557
+                if [ "${is_interactive}" ]; then
553 558
                     # clears any removal indicator
554 559
                     function_check reinstall_app
555
-                    reinstall_app ${a}
560
+                    reinstall_app "${a}"
556 561
 
557 562
                     function_check app_load_variables
558
-                    app_load_variables ${a}
563
+                    app_load_variables "${a}"
559 564
 
560
-                    if [[ $(app_is_installed ${a}) == "1" ]]; then
565
+                    if [[ $(app_is_installed "${a}") == "1" ]]; then
561 566
                         echo $"Upgrading application from interactive: ${a}"
562
-                        upgrade_${a}
567
+                        "upgrade_${a}"
563 568
                         echo $"${a} was upgraded from interactive"
564 569
                     else
565 570
                         echo $"Installing application from interactive: ${a}"
566 571
                         APP_INSTALLED=
567
-                        install_${a}
572
+                        "install_${a}"
568 573
                         if [ $APP_INSTALLED ]; then
569 574
                             function_check app_save_variables
570
-                            app_save_variables ${a}
575
+                            app_save_variables "${a}"
571 576
 
572 577
                             function_check add_users_after_install
573
-                            add_users_after_install ${a}
578
+                            add_users_after_install "${a}"
574 579
 
575 580
                             function_check lockdown_permissions
576 581
                             lockdown_permissions
577 582
 
578 583
                             function_check install_completed
579
-                            install_completed ${a}
584
+                            install_completed "${a}"
580 585
                             echo $"${a} was installed from interactive"
581 586
                         else
582
-                            echo "Failed to install: ${a}" >> /var/log/${PROJECT_NAME}.log
587
+                            echo "Failed to install: ${a}" >> "/var/log/${PROJECT_NAME}.log"
583 588
                             APP_INSTALLED_SUCCESS=
584 589
                             echo $"${a} was not installed from interactive"
585 590
                         fi
586 591
                     fi
587 592
                 else
588 593
                     # check if the app was removed
589
-                    if [[ $(app_is_removed ${a}) == "0" ]]; then
594
+                    if [[ $(app_is_removed "${a}") == "0" ]]; then
590 595
                         function_check app_load_variables
591
-                        app_load_variables ${a}
592
-                        if [[ $(app_is_installed ${a}) == "1" ]]; then
596
+                        app_load_variables "${a}"
597
+                        if [[ $(app_is_installed "${a}") == "1" ]]; then
593 598
                             echo $"Upgrading application: ${a}"
594
-                            upgrade_${a}
599
+                            "upgrade_${a}"
595 600
                             echo $"${a} was upgraded"
596 601
                         else
597 602
                             echo $"Installing application: ${a}"
598 603
                             APP_INSTALLED=
599
-                            install_${a}
604
+                            "install_${a}"
600 605
                             if [ $APP_INSTALLED ]; then
601 606
                                 function_check app_save_variables
602
-                                app_save_variables ${a}
607
+                                app_save_variables "${a}"
603 608
 
604 609
                                 function_check add_users_after_install
605
-                                add_users_after_install ${a}
610
+                                add_users_after_install "${a}"
606 611
 
607 612
                                 function_check lockdown_permissions
608 613
                                 lockdown_permissions
609 614
 
610 615
                                 function_check install_completed
611
-                                install_completed ${a}
616
+                                install_completed "${a}"
612 617
                                 echo $"${a} was installed"
613 618
                             else
614
-                                echo "Failed to install: ${a}" >> /var/log/${PROJECT_NAME}.log
619
+                                echo "Failed to install: ${a}" >> "/var/log/${PROJECT_NAME}.log"
615 620
                                 APP_INSTALLED_SUCCESS=
616 621
                                 echo $"${a} was not installed"
617 622
                             fi
@@ -622,7 +627,7 @@ function install_apps {
622 627
                 fi
623 628
             fi
624 629
         fi
625
-        app_index=$[app_index+1]
630
+        app_index=$((app_index+1))
626 631
     done
627 632
 
628 633
     function_check update_installed_apps_list

+ 42
- 42
src/freedombone-utils-setup 查看文件

@@ -63,7 +63,7 @@ BACKUP_MAX_DAYS=30
63 63
 # file containing a list of remote locations to backup to
64 64
 # Format: [username@friendsdomain//home/username] [ssh_password]
65 65
 # With the only space character being between the server and the password
66
-FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
66
+FRIENDS_SERVERS_LIST="/home/$MY_USERNAME/backup.list"
67 67
 
68 68
 export DEBIAN_FRONTEND=noninteractive
69 69
 
@@ -103,9 +103,9 @@ function detect_usb_drive {
103 103
     # which is likely to be the last drive connected
104 104
     read_config_param USB_DRIVE
105 105
     partition_number='1'
106
-    if [[ "$1" == "nopath" ]]; then
107
-        partition_number=''
108
-    fi
106
+    #if [[ "$1" == "nopath" ]]; then
107
+    #    partition_number=''
108
+    #fi
109 109
     if [ -b /dev/sda${partition_number} ]; then
110 110
         USB_DRIVE=/dev/sda${partition_number}
111 111
     fi
@@ -139,7 +139,7 @@ function separate_tmp_filesystem {
139 139
         mkdir -p /tmp
140 140
     fi
141 141
     if ! grep -q '/tmp' /etc/fstab; then
142
-        mount -t tmpfs -o size=${tmp_filesystem_size_mb}m tmpfs /tmp
142
+        mount -t tmpfs -o size="${tmp_filesystem_size_mb}m" tmpfs /tmp
143 143
         echo "tmpfs       /tmp tmpfs   nodev,nosuid,noexec,nodiratime,size=${tmp_filesystem_size_mb}M   0 0" >> /etc/fstab
144 144
     fi
145 145
 }
@@ -183,7 +183,7 @@ function remove_bluetooth {
183 183
         bluetooth_changed=1
184 184
     fi
185 185
     if [ $bluetooth_changed ]; then
186
-        update-initramfs -u -k `uname -r` -v
186
+        update-initramfs -u -k "$(uname -r)" -v
187 187
         update-rc.d bluetooth remove
188 188
     fi
189 189
 }
@@ -199,7 +199,7 @@ function running_as_root {
199 199
 function reset_usb_devices {
200 200
     for xhci in /sys/bus/pci/drivers/?hci-pci ; do
201 201
 
202
-        if ! cd $xhci ; then
202
+        if ! cd "$xhci" ; then
203 203
             return
204 204
         fi
205 205
 
@@ -219,7 +219,7 @@ function install_backports_kernel {
219 219
 
220 220
     if [[ "$architecture_type" == *"amd64"* ]]; then
221 221
         package_installed=$(dpkg-query -W -f='${Package}\n' linux-image-amd64 2>/dev/null)
222
-        if [ ! $package_installed ]; then
222
+        if [ ! "$package_installed" ]; then
223 223
             apt-get -yq install linux-image-amd64
224 224
         fi
225 225
     fi
@@ -279,8 +279,8 @@ function initial_setup {
279 279
         apt-get -yq install grub2 lvm2
280 280
     fi
281 281
 
282
-    if [ ! -d $INSTALL_DIR ]; then
283
-        mkdir -p $INSTALL_DIR
282
+    if [ ! -d "$INSTALL_DIR" ]; then
283
+        mkdir -p "$INSTALL_DIR"
284 284
     fi
285 285
 
286 286
     mark_completed "${FUNCNAME[0]}"
@@ -308,8 +308,9 @@ function setup_grub {
308 308
 }
309 309
 
310 310
 function admin_user_sudo {
311
-    if ! grep -q "$MY_USERNAME  ALL=(ALL) ALL" $rootdir/etc/sudoers; then
312
-        echo "$MY_USERNAME  ALL=(ALL) ALL" >> $rootdir/etc/sudoers
311
+    # shellcheck disable=SC2154
312
+    if ! grep -q "$MY_USERNAME  ALL=(ALL) ALL" "$rootdir/etc/sudoers"; then
313
+        echo "$MY_USERNAME  ALL=(ALL) ALL" >> "$rootdir/etc/sudoers"
313 314
     fi
314 315
 }
315 316
 
@@ -338,11 +339,11 @@ function search_for_attached_usb_drive {
338 339
 
339 340
         if [ -f $USB_MOUNT/private_key.gpg ]; then
340 341
             echo $'GPG private key found on USB drive'
341
-            MY_GPG_PRIVATE_KEY=$USB_MOUNT/private_key.gpg
342
+            MY_GPG_PRIVATE_KEY="$USB_MOUNT/private_key.gpg"
342 343
         fi
343 344
         if [ -f $USB_MOUNT/public_key.gpg ]; then
344 345
             echo $'GPG public key found on USB drive'
345
-            MY_GPG_PUBLIC_KEY=$USB_MOUNT/public_key.gpg
346
+            MY_GPG_PUBLIC_KEY="$USB_MOUNT/public_key.gpg"
346 347
         fi
347 348
 
348 349
         if [ -f $USB_MOUNT/letsencrypt ]; then
@@ -431,8 +432,8 @@ function remove_default_user {
431 432
 }
432 433
 
433 434
 function create_completion_file {
434
-    if [ ! -f $COMPLETION_FILE ]; then
435
-        touch $COMPLETION_FILE
435
+    if [ ! -f "$COMPLETION_FILE" ]; then
436
+        touch "$COMPLETION_FILE"
436 437
     fi
437 438
 }
438 439
 
@@ -467,7 +468,7 @@ function remove_management_engine_interface {
467 468
 }
468 469
 
469 470
 function set_login_umask {
470
-    logindefs_umask=$(cat /etc/login.defs | grep UMASK | grep -v '#')
471
+    logindefs_umask=$(grep UMASK /etc/login.defs | grep -v '#')
471 472
     if [[ "$logindefs_umask" != *'077' ]]; then
472 473
         sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
473 474
     fi
@@ -489,7 +490,7 @@ function set_max_login_tries {
489 490
     max_tries=$1
490 491
 
491 492
     if ! grep -q ' deny=' /etc/pam.d/common-auth; then
492
-        sed -i "/pam_deny.so/a auth    required\t\t\tpam_tally.so    onerr=fail no_lock_time per_user deny=$max_tries" /etc/pam.d/common-auth
493
+        sed -i "/pam_deny.so/a auth    required\\t\\t\\tpam_tally.so    onerr=fail no_lock_time per_user deny=$max_tries" /etc/pam.d/common-auth
493 494
     else
494 495
         if ! grep -q " deny=$max_tries" /etc/pam.d/common-auth; then
495 496
             sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
@@ -503,19 +504,19 @@ function set_max_login_tries {
503 504
 
504 505
 function limit_user_logins {
505 506
     # overall max logins
506
-    if ! grep -q '* hard maxsyslogins' /etc/security/limits.conf; then
507
+    if ! grep -q '\* hard maxsyslogins' /etc/security/limits.conf; then
507 508
         echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
508 509
     else
509
-        if ! grep -q '* hard maxsyslogins 10' /etc/security/limits.conf; then
510
+        if ! grep -q '\* hard maxsyslogins 10' /etc/security/limits.conf; then
510 511
             sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
511 512
         fi
512 513
     fi
513 514
 
514 515
     # Max logins for each user
515
-    if ! grep -q '* hard maxlogins' /etc/security/limits.conf; then
516
+    if ! grep -q '\* hard maxlogins' /etc/security/limits.conf; then
516 517
         echo '* hard maxlogins 2' >> /etc/security/limits.conf
517 518
     else
518
-        if ! grep -q '* hard maxlogins 2' /etc/security/limits.conf; then
519
+        if ! grep -q '\* hard maxlogins 2' /etc/security/limits.conf; then
519 520
             sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
520 521
         fi
521 522
     fi
@@ -532,7 +533,7 @@ function set_sticky_bits {
532 533
     world_writable=$(find / -xdev -type d -perm -002 \! -perm -1000)
533 534
     for w in $world_writable; do
534 535
         echo "Setting sticky bit on $w"
535
-        chmod +t $w
536
+        chmod +t "$w"
536 537
     done
537 538
 }
538 539
 
@@ -655,10 +656,10 @@ function lockdown_permissions {
655 656
 }
656 657
 
657 658
 function disable_core_dumps {
658
-    if ! grep -q '* hard core' /etc/security/limits.conf; then
659
+    if ! grep -q '\* hard core' /etc/security/limits.conf; then
659 660
         echo '* hard core 0' >> /etc/security/limits.conf
660 661
     else
661
-        if ! grep -q '* hard core 0' /etc/security/limits.conf; then
662
+        if ! grep -q '\* hard core 0' /etc/security/limits.conf; then
662 663
             sed -i 's|hard core.*|hard core 0|g' /etc/security/limits.conf
663 664
         fi
664 665
     fi
@@ -1097,24 +1098,23 @@ function upgrade_apps {
1097 1098
     create_completion_file
1098 1099
 
1099 1100
     APPS_COMPLETED=()
1100
-    FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
1101
+    FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
1101 1102
 
1102 1103
     # for all the app scripts
1103 1104
     for filename in $FILES
1104 1105
     do
1105 1106
         app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
1106 1107
 
1107
-        item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
1108
-        if [[ $? != 0 ]]; then
1108
+        if ! item_in_array "${app_name}" "${APPS_COMPLETED[@]}"; then
1109 1109
             function_check app_is_installed
1110
-            if [[ "$(app_is_installed $app_name)" == "1" ]]; then
1110
+            if [[ "$(app_is_installed "$app_name")" == "1" ]]; then
1111 1111
                 echo ''
1112 1112
                 echo ''
1113 1113
                 echo $"Upgrading $app_name"
1114
-                app_load_variables ${app_name}
1114
+                app_load_variables "${app_name}"
1115 1115
                 APPS_COMPLETED+=("${app_name}")
1116
-                function_check upgrade_${app_name}
1117
-                upgrade_${app_name}
1116
+                function_check "upgrade_${app_name}"
1117
+                "upgrade_${app_name}"
1118 1118
             fi
1119 1119
         fi
1120 1120
     done
@@ -1145,7 +1145,7 @@ function setup_apps {
1145 1145
     if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
1146 1146
         function_check install_apps
1147 1147
         install_apps
1148
-        if [ ! $APP_INSTALLED_SUCCESS ]; then
1148
+        if [ ! "$APP_INSTALLED_SUCCESS" ]; then
1149 1149
             echo $'One or more apps failed to install'
1150 1150
         fi
1151 1151
     fi
@@ -1155,28 +1155,28 @@ function combine_all_scripts {
1155 1155
     combined_filename=$1
1156 1156
 
1157 1157
     # initial variables
1158
-    cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars $combined_filename
1158
+    cp "$PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars" "$combined_filename"
1159 1159
 
1160 1160
     # utilities
1161
-    UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
1161
+    UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
1162 1162
     for f in $UTILS_FILES
1163 1163
     do
1164 1164
         # this removes the first line, which is #!/bin/bash
1165
-        tail -n +2 "$f" >> $combined_filename
1165
+        tail -n +2 "$f" >> "$combined_filename"
1166 1166
     done
1167 1167
 
1168 1168
     # base system
1169
-    BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*
1169
+    BASE_SYSTEM_FILES="/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*"
1170 1170
     for f in $BASE_SYSTEM_FILES
1171 1171
     do
1172
-        tail -n +2 "$f" >> $combined_filename
1172
+        tail -n +2 "$f" >> "$combined_filename"
1173 1173
     done
1174 1174
 
1175 1175
     # apps
1176
-    APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
1176
+    APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
1177 1177
     for f in $APP_FILES
1178 1178
     do
1179
-        tail -n +2 "$f" >> $combined_filename
1179
+        tail -n +2 "$f" >> "$combined_filename"
1180 1180
     done
1181 1181
 }
1182 1182
 
@@ -1185,8 +1185,8 @@ function check_ram_availability {
1185 1185
     minimum_ram_bytes=$((minimum_ram_MB * 1024))
1186 1186
 
1187 1187
     ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
1188
-    if [ $ram_available -lt $minimum_ram_bytes ]; then
1189
-        echo $"Need at least ${minimum_ram_gb}MB RAM to install this app"
1188
+    if [ "$ram_available" -lt "$minimum_ram_bytes" ]; then
1189
+        echo $"Need at least ${minimum_ram_MB}MB RAM to install this app"
1190 1190
         exit 783524
1191 1191
     fi
1192 1192
 }

+ 34
- 33
src/freedombone-utils-tracker 查看文件

@@ -31,28 +31,29 @@
31 31
 TRACKER_PORT=6969
32 32
 
33 33
 function mesh_install_tracker {
34
+    # shellcheck disable=SC2154
34 35
     chroot "$rootdir" apt-get -yq install bittornado nginx
35 36
 
36 37
     TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
37
-    echo '[Unit]' > $TRACKER_DAEMON
38
-    echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
39
-    echo 'After=syslog.target' >> $TRACKER_DAEMON
40
-    echo 'After=network.target' >> $TRACKER_DAEMON
41
-    echo '[Service]' >> $TRACKER_DAEMON
42
-    echo 'Type=simple' >> $TRACKER_DAEMON
43
-    echo 'User=tracker' >> $TRACKER_DAEMON
44
-    echo 'Group=tracker' >> $TRACKER_DAEMON
45
-    echo "WorkingDirectory=/var/lib/tracker" >> $TRACKER_DAEMON
46
-    echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
47
-    echo '' >> $TRACKER_DAEMON
48
-    echo 'TimeoutSec=300' >> $TRACKER_DAEMON
49
-    echo '' >> $TRACKER_DAEMON
50
-    echo '[Install]' >> $TRACKER_DAEMON
51
-    echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
38
+    { echo '[Unit]'
39
+      echo 'Description=Torrent Tracker';
40
+      echo 'After=syslog.target';
41
+      echo 'After=network.target';
42
+      echo '[Service]';
43
+      echo 'Type=simple';
44
+      echo 'User=tracker';
45
+      echo 'Group=tracker';
46
+      echo "WorkingDirectory=/var/lib/tracker";
47
+      echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0";
48
+      echo '';
49
+      echo 'TimeoutSec=300';
50
+      echo '';
51
+      echo '[Install]';
52
+      echo 'WantedBy=multi-user.target'; } > "$TRACKER_DAEMON"
52 53
 
53 54
     chroot "$rootdir" useradd -d /var/lib/tracker/ -s /bin/false tracker
54
-    if [ ! -d $rootdir/var/lib/tracker ]; then
55
-        mkdir $rootdir/var/lib/tracker
55
+    if [ ! -d "$rootdir/var/lib/tracker" ]; then
56
+        mkdir "$rootdir/var/lib/tracker"
56 57
     fi
57 58
     chroot "$rootdir" chown -R tracker:tracker /var/lib/tracker
58 59
 
@@ -60,7 +61,7 @@ function mesh_install_tracker {
60 61
 }
61 62
 
62 63
 function install_tracker {
63
-    if [ $INSTALLING_MESH ]; then
64
+    if [ "$INSTALLING_MESH" ]; then
64 65
         mesh_install_tracker
65 66
         return
66 67
     fi
@@ -72,21 +73,21 @@ function install_tracker {
72 73
     apt-get -yq install bittornado nginx
73 74
 
74 75
     TRACKER_DAEMON=/etc/systemd/system/tracker.service
75
-    echo '[Unit]' > $TRACKER_DAEMON
76
-    echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON
77
-    echo 'After=syslog.target' >> $TRACKER_DAEMON
78
-    echo 'After=network.target' >> $TRACKER_DAEMON
79
-    echo '[Service]' >> $TRACKER_DAEMON
80
-    echo 'Type=simple' >> $TRACKER_DAEMON
81
-    echo 'User=tracker' >> $TRACKER_DAEMON
82
-    echo 'Group=tracker' >> $TRACKER_DAEMON
83
-    echo "WorkingDirectory=/var/lib/tracker" >> $TRACKER_DAEMON
84
-    echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON
85
-    echo '' >> $TRACKER_DAEMON
86
-    echo 'TimeoutSec=300' >> $TRACKER_DAEMON
87
-    echo '' >> $TRACKER_DAEMON
88
-    echo '[Install]' >> $TRACKER_DAEMON
89
-    echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON
76
+    { echo '[Unit]';
77
+      echo 'Description=Torrent Tracker';
78
+      echo 'After=syslog.target';
79
+      echo 'After=network.target';
80
+      echo '[Service]';
81
+      echo 'Type=simple';
82
+      echo 'User=tracker';
83
+      echo 'Group=tracker';
84
+      echo "WorkingDirectory=/var/lib/tracker";
85
+      echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0";
86
+      echo '';
87
+      echo 'TimeoutSec=300';
88
+      echo '';
89
+      echo '[Install]';
90
+      echo 'WantedBy=multi-user.target'; } > "$TRACKER_DAEMON"
90 91
 
91 92
     useradd -d /var/lib/tracker/ -s /bin/false tracker
92 93
     if [ ! -d /var/lib/tracker ]; then

+ 85
- 84
src/freedombone-utils-turn 查看文件

@@ -36,10 +36,10 @@ function generate_turn_key {
36 36
     local turnkey="${1}"
37 37
     local filepath="${2}"
38 38
 
39
-    echo "lt-cred-mech" > "${filepath}"
40
-    echo "use-auth-secret" >> "${filepath}"
41
-    echo "static-auth-secret=${turnkey}" >> "${filepath}"
42
-    echo "realm=turn.${DEFAULT_DOMAIN_NAME}" >> "${filepath}"
39
+    { echo "lt-cred-mech";
40
+      echo "use-auth-secret";
41
+      echo "static-auth-secret=${turnkey}";
42
+      echo "realm=turn.${DEFAULT_DOMAIN_NAME}"; } > "${filepath}"
43 43
     if [[ $ONION_ONLY == 'no' ]]; then
44 44
         echo "cert=$MATRIX_DATA_DIR/${DEFAULT_DOMAIN_NAME}.tls.crt" >> "${filepath}"
45 45
         echo "pkey=$MATRIX_DATA_DIR/${DEFAULT_DOMAIN_NAME}.tls.key" >> "${filepath}"
@@ -58,7 +58,7 @@ function remove_turn {
58 58
 
59 59
     apt-get -y remove coturn
60 60
     rm -rf /var/lib/turn
61
-    sed -i "/# TURN Server/,/# End of TURN Server/d" /etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}
61
+    sed -i "/# TURN Server/,/# End of TURN Server/d" "/etc/nginx/sites-available/${DEFAULT_DOMAIN_NAME}"
62 62
     remove_onion_service turn ${TURN_ONION_PORT}
63 63
     rm /etc/avahi/services/turn.service
64 64
     systemctl restart nginx
@@ -69,62 +69,62 @@ function install_turn {
69 69
 
70 70
     # append the matrix server to the web site config
71 71
     turn_nginx_site=/etc/nginx/sites-available/$DEFAULT_DOMAIN_NAME
72
-    if ! grep -q '# End of TURN Server' $turn_nginx_site; then
73
-        if [[ $ONION_ONLY == "no" ]]; then
74
-            echo '# TURN Server' >> $turn_nginx_site
75
-            echo 'server {' >> $turn_nginx_site
76
-            echo "  listen ${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
77
-            echo "  listen [::]:${TURN_HTTP_PORT} ssl;" >> $turn_nginx_site
78
-            echo "  server_name ${DEFAULT_DOMAIN_NAME};" >> $turn_nginx_site
79
-            echo '' >> $turn_nginx_site
80
-            echo '  # Security' >> $turn_nginx_site
72
+    if ! grep -q '# End of TURN Server' "$turn_nginx_site"; then
73
+        if [[ "$ONION_ONLY" == "no" ]]; then
74
+            { echo '# TURN Server';
75
+              echo 'server {';
76
+              echo "  listen ${TURN_HTTP_PORT} ssl;";
77
+              echo "  listen [::]:${TURN_HTTP_PORT} ssl;";
78
+              echo "  server_name ${DEFAULT_DOMAIN_NAME};";
79
+              echo '';
80
+              echo '  # Security'; } >> "$turn_nginx_site"
81 81
             function_check nginx_ssl
82
-            nginx_ssl ${DEFAULT_DOMAIN_NAME}
82
+            nginx_ssl "${DEFAULT_DOMAIN_NAME}"
83 83
 
84 84
             function_check nginx_disable_sniffing
85
-            nginx_disable_sniffing ${DEFAULT_DOMAIN_NAME}
86
-
87
-            echo '  add_header Strict-Transport-Security max-age=15768000;' >> $turn_nginx_site
88
-            echo '' >> $turn_nginx_site
89
-            echo '  # Logs' >> $turn_nginx_site
90
-            echo '  access_log /dev/null;' >> $turn_nginx_site
91
-            echo '  error_log /dev/null;' >> $turn_nginx_site
92
-            echo '' >> $turn_nginx_site
93
-            echo '  # Index' >> $turn_nginx_site
94
-            echo '  index index.html;' >> $turn_nginx_site
95
-            echo '' >> $turn_nginx_site
96
-            echo '  # Location' >> $turn_nginx_site
97
-            echo '  location / {' >> $turn_nginx_site
85
+            nginx_disable_sniffing "${DEFAULT_DOMAIN_NAME}"
86
+
87
+            { echo '  add_header Strict-Transport-Security max-age=15768000;';
88
+              echo '';
89
+              echo '  # Logs';
90
+              echo '  access_log /dev/null;';
91
+              echo '  error_log /dev/null;';
92
+              echo '';
93
+              echo '  # Index';
94
+              echo '  index index.html;';
95
+              echo '';
96
+              echo '  # Location';
97
+              echo '  location / {'; } >> "$turn_nginx_site"
98 98
             function_check nginx_limits
99
-            nginx_limits ${DEFAULT_DOMAIN_NAME} '15m'
100
-            echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
101
-            echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
102
-            echo '  }' >> $turn_nginx_site
103
-            echo '}' >> $turn_nginx_site
104
-            echo '' >> $turn_nginx_site
99
+            nginx_limits "${DEFAULT_DOMAIN_NAME}" '15m'
100
+            { echo "      proxy_pass http://localhost:${TURN_PORT};";
101
+              echo "      proxy_set_header X-Forwarded-For \$remote_addr;";
102
+              echo '  }';
103
+              echo '}';
104
+              echo ''; } >> "$turn_nginx_site"
105 105
         else
106
-            echo '# TURN Server' >> $turn_nginx_site
106
+            echo '# TURN Server' >> "$turn_nginx_site"
107 107
         fi
108
-        echo 'server {' >> $turn_nginx_site
109
-        echo "    listen 127.0.0.1:$TURN_ONION_PORT default_server;" >> $turn_nginx_site
110
-        echo "    server_name $DEFAULT_DOMAIN_NAME;" >> $turn_nginx_site
111
-        echo '' >> $turn_nginx_site
108
+        { echo 'server {';
109
+          echo "    listen 127.0.0.1:$TURN_ONION_PORT default_server;";
110
+          echo "    server_name $DEFAULT_DOMAIN_NAME;";
111
+          echo ''; } >> "$turn_nginx_site"
112 112
         function_check nginx_disable_sniffing
113
-        nginx_disable_sniffing $DEFAULT_DOMAIN_NAME
114
-        echo '' >> $turn_nginx_site
115
-        echo '  # Logs' >> $turn_nginx_site
116
-        echo '  access_log /dev/null;' >> $turn_nginx_site
117
-        echo '  error_log /dev/null;' >> $turn_nginx_site
118
-        echo '' >> $turn_nginx_site
119
-        echo '  # Location' >> $turn_nginx_site
120
-        echo '  location / {' >> $turn_nginx_site
113
+        nginx_disable_sniffing "$DEFAULT_DOMAIN_NAME"
114
+        { echo '';
115
+          echo '  # Logs';
116
+          echo '  access_log /dev/null;';
117
+          echo '  error_log /dev/null;';
118
+          echo '';
119
+          echo '  # Location';
120
+          echo '  location / {'; } >> "$turn_nginx_site"
121 121
         function_check nginx_limits
122
-        nginx_limits $DEFAULT_DOMAIN_NAME '15m'
123
-        echo "      proxy_pass http://localhost:${TURN_PORT};" >> $turn_nginx_site
124
-        echo '      proxy_set_header X-Forwarded-For $remote_addr;' >> $turn_nginx_site
125
-        echo '  }' >> $turn_nginx_site
126
-        echo '}' >> $turn_nginx_site
127
-        echo '# End of TURN Server' >> $turn_nginx_site
122
+        nginx_limits "$DEFAULT_DOMAIN_NAME" '15m'
123
+        { echo "      proxy_pass http://localhost:${TURN_PORT};";
124
+          echo "      proxy_set_header X-Forwarded-For \$remote_addr;";
125
+          echo '  }';
126
+          echo '}';
127
+          echo '# End of TURN Server'; } >> "$turn_nginx_site"
128 128
     fi
129 129
 
130 130
     export DEBIAN_FRONTEND=noninteractive
@@ -151,26 +151,26 @@ function install_turn {
151 151
     fi
152 152
 
153 153
     turnkey="$(create_password 30)"
154
-    generate_turn_key $turnkey /var/lib/turn/turnserver.conf
154
+    generate_turn_key "$turnkey" /var/lib/turn/turnserver.conf
155 155
 
156 156
     chmod -R 700 /var/lib/turn/turnserver.conf
157 157
     chown -R matrix:matrix /var/lib/turn
158 158
 
159
-    echo '[Unit]' > /etc/systemd/system/turn.service
160
-    echo 'Description=TURN server' >> /etc/systemd/system/turn.service
161
-    echo 'After=network.target nginx.target' >> /etc/systemd/system/turn.service
162
-    echo '' >> /etc/systemd/system/turn.service
163
-    echo '[Service]' >> /etc/systemd/system/turn.service
164
-    echo 'Type=simple' >> /etc/systemd/system/turn.service
165
-    echo 'User=matrix' >> /etc/systemd/system/turn.service
166
-    echo "WorkingDirectory=/var/lib/turn" >> /etc/systemd/system/turn.service
167
-    echo "ExecStart=/usr/bin/turnserver -c /var/lib/turn/turnserver.conf --pidfile /var/lib/matrix/homeserver.pid" >> /etc/systemd/system/turn.service
168
-    echo "Environment=REPORT_STATS=\"no\"" >> /etc/systemd/system/turn.service
169
-    echo 'Restart=always' >> /etc/systemd/system/turn.service
170
-    echo 'RestartSec=10' >> /etc/systemd/system/turn.service
171
-    echo '' >> /etc/systemd/system/turn.service
172
-    echo '[Install]' >> /etc/systemd/system/turn.service
173
-    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/turn.service
159
+    { echo '[Unit]';
160
+      echo 'Description=TURN server';
161
+      echo 'After=network.target nginx.target';
162
+      echo '';
163
+      echo '[Service]';
164
+      echo 'Type=simple';
165
+      echo 'User=matrix';
166
+      echo "WorkingDirectory=/var/lib/turn";
167
+      echo "ExecStart=/usr/bin/turnserver -c /var/lib/turn/turnserver.conf --pidfile /var/lib/matrix/homeserver.pid";
168
+      echo "Environment=REPORT_STATS=\"no\"";
169
+      echo 'Restart=always';
170
+      echo 'RestartSec=10';
171
+      echo '';
172
+      echo '[Install]';
173
+      echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/turn.service
174 174
     systemctl enable turn
175 175
     systemctl daemon-reload
176 176
     systemctl start turn
@@ -178,21 +178,22 @@ function install_turn {
178 178
     firewall_add turn ${TURN_PORT}
179 179
     firewall_add turn-http ${TURN_HTTP_PORT}
180 180
 
181
-    TURN_ONION_HOSTNAME=$(add_onion_service turn ${TURN_PORT} ${TURN_ONION_PORT})
182
-
183
-    echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->' > /etc/avahi/services/turn.service
184
-    echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">' >> /etc/avahi/services/turn.service
185
-    echo '<service-group>' >> /etc/avahi/services/turn.service
186
-    echo '  <name replace-wildcards="yes">%h TURN</name>' >> /etc/avahi/services/turn.service
187
-    echo '  <service>' >> /etc/avahi/services/turn.service
188
-    echo '    <type>_turn._tcp</type>' >> /etc/avahi/services/turn.service
189
-    echo "    <port>$TURN_PORT</port>" >> /etc/avahi/services/turn.service
190
-    echo '  </service>' >> /etc/avahi/services/turn.service
191
-    echo '  <service>' >> /etc/avahi/services/turn.service
192
-    echo '    <type>_turn._udp</type>' >> /etc/avahi/services/turn.service
193
-    echo "    <port>$TURN_PORT</port>" >> /etc/avahi/services/turn.service
194
-    echo '  </service>' >> /etc/avahi/services/turn.service
195
-    echo '</service-group>' >> /etc/avahi/services/turn.service
181
+    #TURN_ONION_HOSTNAME=$(add_onion_service turn ${TURN_PORT} ${TURN_ONION_PORT})
182
+    add_onion_service turn ${TURN_PORT} ${TURN_ONION_PORT}
183
+
184
+    { echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
185
+      echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
186
+      echo '<service-group>';
187
+      echo '  <name replace-wildcards="yes">%h TURN</name>';
188
+      echo '  <service>';
189
+      echo '    <type>_turn._tcp</type>';
190
+      echo "    <port>$TURN_PORT</port>";
191
+      echo '  </service>';
192
+      echo '  <service>';
193
+      echo '    <type>_turn._udp</type>';
194
+      echo "    <port>$TURN_PORT</port>";
195
+      echo '  </service>';
196
+      echo '</service-group>'; } > /etc/avahi/services/turn.service
196 197
 
197 198
     systemctl restart avahi-daemon
198 199
     systemctl restart nginx

+ 27
- 27
src/freedombone-utils-upgrade 查看文件

@@ -32,14 +32,14 @@
32 32
 UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
33 33
 
34 34
 function create_upgrade_script {
35
-    upgrade_command_file=$(which ${PROJECT_NAME}-upgrade)
36
-    if [ ! -f /etc/cron.weekly/$UPGRADE_SCRIPT_NAME ]; then
37
-        cp $upgrade_command_file /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
35
+    upgrade_command_file=$(which "${PROJECT_NAME}-upgrade")
36
+    if [ ! -f "/etc/cron.weekly/$UPGRADE_SCRIPT_NAME" ]; then
37
+        cp "$upgrade_command_file" "/etc/cron.weekly/$UPGRADE_SCRIPT_NAME"
38 38
     else
39
-        HASH1=$(sha256sum $upgrade_command_file | awk -F ' ' '{print $1}')
40
-        HASH2=$(sha256sum /etc/cron.weekly/$UPGRADE_SCRIPT_NAME | awk -F ' ' '{print $1}')
39
+        HASH1=$(sha256sum "$upgrade_command_file" | awk -F ' ' '{print $1}')
40
+        HASH2=$(sha256sum "/etc/cron.weekly/$UPGRADE_SCRIPT_NAME" | awk -F ' ' '{print $1}')
41 41
         if [[ "$HASH1" != "$HASH2" ]]; then
42
-            cp $upgrade_command_file /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
42
+            cp "$upgrade_command_file" "/etc/cron.weekly/$UPGRADE_SCRIPT_NAME"
43 43
         fi
44 44
     fi
45 45
 
@@ -53,7 +53,7 @@ function create_upgrade_script {
53 53
 }
54 54
 
55 55
 function upgrade_installation_from_previous_versions {
56
-    if [ ! -f $COMPLETION_FILE ]; then
56
+    if [ ! -f "$COMPLETION_FILE" ]; then
57 57
         return
58 58
     fi
59 59
     if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
@@ -61,27 +61,27 @@ function upgrade_installation_from_previous_versions {
61 61
     fi
62 62
 
63 63
     # upgrade from previous versions
64
-    sed -i 's|configure_email|install_email|g' $COMPLETION_FILE
65
-    sed -i 's|install_dlna_server|install_dlna|g' $COMPLETION_FILE
66
-    sed -i 's|install_gnu_social_theme|install_gnusocial_theme|g' $COMPLETION_FILE
67
-    sed -i 's|install_gnu_social|install_gnusocial|g' $COMPLETION_FILE
68
-    sed -i 's|install_irc_server|install_irc|g' $COMPLETION_FILE
69
-    sed -i 's|voip_turn|turn|g' $COMPLETION_FILE
70
-    sed -i 's|install_voip|install_mumble|g' $COMPLETION_FILE
71
-    sed -i 's|install_rss_reader|install_rss|g' $COMPLETION_FILE
72
-    sed -i 's|install_tox_node|install_tox|g' $COMPLETION_FILE
73
-    sed -i 's|intrusion_detection|install_tripwire|g' $COMPLETION_FILE
64
+    sed -i 's|configure_email|install_email|g' "$COMPLETION_FILE"
65
+    sed -i 's|install_dlna_server|install_dlna|g' "$COMPLETION_FILE"
66
+    sed -i 's|install_gnu_social_theme|install_gnusocial_theme|g' "$COMPLETION_FILE"
67
+    sed -i 's|install_gnu_social|install_gnusocial|g' "$COMPLETION_FILE"
68
+    sed -i 's|install_irc_server|install_irc|g' "$COMPLETION_FILE"
69
+    sed -i 's|voip_turn|turn|g' "$COMPLETION_FILE"
70
+    sed -i 's|install_voip|install_mumble|g' "$COMPLETION_FILE"
71
+    sed -i 's|install_rss_reader|install_rss|g' "$COMPLETION_FILE"
72
+    sed -i 's|install_tox_node|install_tox|g' "$COMPLETION_FILE"
73
+    sed -i 's|intrusion_detection|install_tripwire|g' "$COMPLETION_FILE"
74 74
 
75
-    sed -i 's|GNU Social|gnusocial|g' $COMPLETION_FILE
76
-    sed -i 's|XMPP|xmpp|g' $COMPLETION_FILE
77
-    sed -i 's|voip|mumble|g' $COMPLETION_FILE
78
-    sed -i 's|VoIP|mumble|g' $COMPLETION_FILE
79
-    sed -i 's|Blog|htmly|g' $COMPLETION_FILE
80
-    sed -i 's|Hubzilla|hubzilla|g' $COMPLETION_FILE
81
-    sed -i 's|Gogs|gogs|g' $COMPLETION_FILE
82
-    sed -i 's|Wiki|dokuwiki|g' $COMPLETION_FILE
83
-    sed -i 's|RSS|rss|g' $COMPLETION_FILE
84
-    sed -i 's|Zeronet|zeronet|g' $COMPLETION_FILE
75
+    sed -i 's|GNU Social|gnusocial|g' "$COMPLETION_FILE"
76
+    sed -i 's|XMPP|xmpp|g' "$COMPLETION_FILE"
77
+    sed -i 's|voip|mumble|g' "$COMPLETION_FILE"
78
+    sed -i 's|VoIP|mumble|g' "$COMPLETION_FILE"
79
+    sed -i 's|Blog|htmly|g' "$COMPLETION_FILE"
80
+    sed -i 's|Hubzilla|hubzilla|g' "$COMPLETION_FILE"
81
+    sed -i 's|Gogs|gogs|g' "$COMPLETION_FILE"
82
+    sed -i 's|Wiki|dokuwiki|g' "$COMPLETION_FILE"
83
+    sed -i 's|RSS|rss|g' "$COMPLETION_FILE"
84
+    sed -i 's|Zeronet|zeronet|g' "$COMPLETION_FILE"
85 85
 
86 86
     if [ -f /usr/local/bin/zeronetavahi ]; then
87 87
         rm /usr/local/bin/zeronetavahi

+ 17
- 17
src/freedombone-utils-watchdog 查看文件

@@ -37,9 +37,9 @@ function install_watchdog_script {
37 37
     if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
38 38
         return
39 39
     fi
40
-    echo '#!/bin/bash' > /usr/bin/$WATCHDOG_SCRIPT_NAME
41
-    echo 'LOGFILE=/var/log/keepon.log' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
42
-    echo 'CURRENT_DATE=$(date)' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
40
+    { echo '#!/bin/bash';
41
+      echo 'LOGFILE=/var/log/keepon.log';
42
+      echo "CURRENT_DATE=\$(date)"; } > "/usr/bin/$WATCHDOG_SCRIPT_NAME"
43 43
     # application specific stuff is added later
44 44
     chmod +x /usr/bin/$WATCHDOG_SCRIPT_NAME
45 45
 
@@ -50,28 +50,28 @@ function install_watchdog_script {
50 50
 }
51 51
 
52 52
 function daemon_is_running {
53
-    daemon_name=$1
54
-    systemctl is-active ${daemon_name} >/dev/null 2>&1 && echo Running
53
+    daemon_name="$1"
54
+    systemctl is-active "${daemon_name}" >/dev/null 2>&1 && echo Running
55 55
 }
56 56
 
57 57
 function add_watchdog_daemon {
58
-    daemon_name=$1
58
+    daemon_name="$1"
59 59
 
60
-    echo '' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
61
-    echo "# keep ${daemon_name} daemon running" >> /usr/bin/$WATCHDOG_SCRIPT_NAME
62
-    echo "RUNNING=\$(systemctl is-active ${daemon_name} >/dev/null 2>&1 && echo Running)" >> /usr/bin/$WATCHDOG_SCRIPT_NAME
63
-    echo 'if [ ! $RUNNING ]; then' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
64
-    echo "  systemctl start ${daemon_name}" >> /usr/bin/$WATCHDOG_SCRIPT_NAME
65
-    echo '  echo -n $CURRENT_DATE >> $LOGFILE' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
66
-    echo "  echo \"${daemon_name} daemon restarted\" >> \$LOGFILE" >> /usr/bin/$WATCHDOG_SCRIPT_NAME
67
-    echo 'fi' >> /usr/bin/$WATCHDOG_SCRIPT_NAME
68
-    echo "# End of ${daemon_name}" >> /usr/bin/$WATCHDOG_SCRIPT_NAME
60
+    { echo '';
61
+      echo "# keep ${daemon_name} daemon running";
62
+      echo "RUNNING=\$(systemctl is-active ${daemon_name} >/dev/null 2>&1 && echo Running)";
63
+      echo "if [ ! \$RUNNING ]; then";
64
+      echo "  systemctl start ${daemon_name}";
65
+      echo "  echo -n \$CURRENT_DATE >> \$LOGFILE";
66
+      echo "  echo \"${daemon_name} daemon restarted\" >> \$LOGFILE";
67
+      echo 'fi';
68
+      echo "# End of ${daemon_name}"; } >> "/usr/bin/$WATCHDOG_SCRIPT_NAME"
69 69
 }
70 70
 
71 71
 function remove_watchdog_daemon {
72
-    daemon_name=$1
72
+    daemon_name="$1"
73 73
 
74
-    sed -i "/# keep ${daemon_name} daemon running/,/# End of ${daemon_name}/d" /usr/bin/$WATCHDOG_SCRIPT_NAME
74
+    sed -i "/# keep ${daemon_name} daemon running/,/# End of ${daemon_name}/d" "/usr/bin/$WATCHDOG_SCRIPT_NAME"
75 75
 }
76 76
 
77 77
 # NOTE: deliberately no exit 0

+ 401
- 405
src/freedombone-utils-web
文件差異過大導致無法顯示
查看文件


+ 2
- 2
src/freedombone-utils-zram 查看文件

@@ -34,11 +34,11 @@ function enable_zram {
34 34
     fi
35 35
 
36 36
     if [[ $INSTALLED_WITHIN_DOCKER == "yes" || $INSTALLING_ON_BBB != "yes" ]]; then
37
-        ${PROJECT_NAME}-zram off
37
+        "${PROJECT_NAME}-zram" off
38 38
         return
39 39
     fi
40 40
 
41
-    ${PROJECT_NAME}-zram on
41
+    "${PROJECT_NAME}-zram" on
42 42
 
43 43
     mark_completed "${FUNCNAME[0]}"
44 44
 }