Skip to content

Commit 57d7915

Browse files
committed
install: Add checks for files that may not exist.
The post-install phase modifies permissions and such for several files, but they may not always exist, so check first to avoid errors.
1 parent 90cf099 commit 57d7915

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

phreaknet.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -943,11 +943,12 @@ make_file_readable() { # $1 = file to make readable.
943943
bottomdir=`dirname "$1"`
944944
realfilename=`printf '%s' "$1" | xargs | cut -d' ' -f 1`
945945
if [ ! -f "$realfilename" ]; then
946-
echoerr "File $realfilename does not exist"
947-
# If the file doesn't exist, forget about it.
946+
# If the file doesn't exist, forget about it, and don't emit an error.
948947
return
949948
fi
950949

950+
printf "Processing key: %s\n" "$realfilename"
951+
951952
newfilename=`realpath $realfilename`
952953
if [ "${#newfilename}" -gt 0 ]; then
953954
# If we have realpath, follow symlinks too.
@@ -1002,7 +1003,6 @@ make_keys_readable() {
10021003

10031004
while read filename
10041005
do
1005-
printf "Processing potential key: %s\n" "$filename"
10061006
make_file_readable "$filename"
10071007
done < /tmp/astkeylist.txt # POSIX compliant
10081008
rm /tmp/astkeylist.txt
@@ -3977,8 +3977,10 @@ elif [ "$cmd" = "install" ]; then
39773977
adduser -c "Asterisk" $AST_USER --disabled-password --gecos "" # don't allow any password logins, e.g. su - asterisk. Use passwd asterisk to manually set.
39783978
fi
39793979
sed -i "s/ASTARGS=\"\"/ASTARGS=\"-U $AST_USER\"/g" /sbin/safe_asterisk
3980-
sed -i "s/#AST_USER=\"asterisk\"/AST_USER=\"$AST_USER\"/g" /etc/default/asterisk
3981-
sed -i "s/#AST_GROUP=\"asterisk\"/AST_GROUP=\"$AST_USER\"/g" /etc/default/asterisk
3980+
if [ -f /etc/default/asterisk ]; then
3981+
sed -i "s/#AST_USER=\"asterisk\"/AST_USER=\"$AST_USER\"/g" /etc/default/asterisk
3982+
sed -i "s/#AST_GROUP=\"asterisk\"/AST_GROUP=\"$AST_USER\"/g" /etc/default/asterisk
3983+
fi
39823984
chown -R $AST_USER $AST_CONFIG_DIR/ /usr/lib/asterisk /var/spool/asterisk/ $AST_VARLIB_DIR/ /var/run/asterisk/ /var/log/asterisk /var/cache/asterisk /usr/sbin/asterisk
39833985
sed -i "s/create 640 root root/create 640 $AST_USER $AST_USER/g" /etc/logrotate.d/asterisk # by default, logrotate will make the files owned by root, so Asterisk can't write to them if it runs as non-root user, so fix this! Not much else that can be done, as it's not a bug, since Asterisk itself doesn't necessarily know what user Asterisk will run as at compile/install time.
39843986
# by default, it has the asterisk user, so simply uncomment it:
@@ -3995,7 +3997,9 @@ elif [ "$cmd" = "install" ]; then
39953997
fi
39963998
rm tmpuserchanges.txt
39973999
fi
3998-
chgrp $AST_USER $AST_VARLIB_DIR/astdb.sqlite3
4000+
if [ -f $AST_VARLIB_DIR/astdb.sqlite3 ]; then
4001+
chgrp $AST_USER $AST_VARLIB_DIR/astdb.sqlite3
4002+
fi
39994003
if [ -d /etc/dahdi ]; then
40004004
# DAHDI related permissions: https://support.digium.com/s/article/Automatically-setting-dev-dahdi-file-permissions-when-running-Asterisk-as-non-root-user
40014005
chown -R $AST_USER:$AST_USER /dev/dahdi
@@ -4052,9 +4056,13 @@ elif [ "$cmd" = "install" ]; then
40524056
install_testsuite_itself
40534057
fi
40544058

4055-
/etc/init.d/asterisk status
4056-
/etc/init.d/asterisk start # service asterisk start
4057-
/etc/init.d/asterisk status
4059+
if [ -f /etc/init.d/asterisk ]; then
4060+
/etc/init.d/asterisk status
4061+
/etc/init.d/asterisk start # service asterisk start
4062+
/etc/init.d/asterisk status
4063+
else
4064+
asterisk -g # Start Asterisk manually if the service isn't installed
4065+
fi
40584066

40594067
asterisk -V
40604068
rasterisk -x "core show version"

0 commit comments

Comments
 (0)