|
|
@@ -19,78 +19,60 @@ then
|
|
|
exit -3
|
|
|
fi
|
|
|
|
|
|
-if [ "$(command -v node)" == "" ]
|
|
|
-then
|
|
|
- echo "NODE.js is not installed. Install it and try again."
|
|
|
- exit -4
|
|
|
-fi
|
|
|
-
|
|
|
-# TODO: FIX, not working for this module
|
|
|
-#if ! node -r requireg /dev/null 2> /dev/null
|
|
|
-#then
|
|
|
-# echo "NODE.js module requireg is not installed. Install it and try again."
|
|
|
-# exit -5
|
|
|
-#fi
|
|
|
-
|
|
|
-
|
|
|
-if ! node -r dateformat /dev/null 2> /dev/null
|
|
|
-then
|
|
|
- echo "NODE.js module dateformat is not installed. Install it and try again."
|
|
|
- exit -5
|
|
|
-fi
|
|
|
-
|
|
|
-if ! node -r request /dev/null 2> /dev/null
|
|
|
-then
|
|
|
- echo "NODE.js module request is not installed. Install it and try again."
|
|
|
- exit -6
|
|
|
-fi
|
|
|
-
|
|
|
-if ! node -r querystring /dev/null 2> /dev/null
|
|
|
-then
|
|
|
- echo "NODE.js module querystring is not installed. Install it and try again."
|
|
|
- exit -7
|
|
|
-fi
|
|
|
-
|
|
|
-if ! node -r http /dev/null 2> /dev/null
|
|
|
-then
|
|
|
- echo "NODE.js module http is not installed. Install it and try again."
|
|
|
- exit -8
|
|
|
-fi
|
|
|
-
|
|
|
-if ! node -r fs /dev/null 2> /dev/null
|
|
|
-then
|
|
|
- echo "NODE.js module fs is not installed. Install it and try again."
|
|
|
- exit -9
|
|
|
-fi
|
|
|
-
|
|
|
-clear_keys=0
|
|
|
-clear_data=0
|
|
|
+reinstall=0
|
|
|
for i in "$@"
|
|
|
do
|
|
|
- if [[ $i == "--clear-keys" ]] ; then
|
|
|
- clear_keys=1;
|
|
|
- elif [[ $i == "--clear-data" ]] ; then
|
|
|
- clear_data=1;
|
|
|
+ if [[ $i == "--reinstall" ]] ; then
|
|
|
+ reinstall=1;
|
|
|
fi
|
|
|
done
|
|
|
|
|
|
-
|
|
|
-if [ -f $SCRIPTPATH/application/sw.sqlite ] && [ $clear_keys == 0 ]
|
|
|
+if [ -f $SCRIPTPATH/data/sw.sqlite ] && [ $reinstall == 0 ]
|
|
|
then
|
|
|
- echo "Key database exist. It will not be overwritten. Use the --clear-keys argument to override."
|
|
|
-else
|
|
|
- echo "Setting up keys..."
|
|
|
- rm $SCRIPTPATH/application/sw.sqlite
|
|
|
- sqlite3 $SCRIPTPATH/application/sw.sqlite < $SCRIPTPATH/install_data/install_base.sql
|
|
|
-fi
|
|
|
-
|
|
|
-if [ -f $SCRIPTPATH/data/sw.sqlite ] && [ $clear_data == 0 ]
|
|
|
-then
|
|
|
- echo "User data database exist. It will not be overwritten. Use the --clear-data argument to override."
|
|
|
+ echo "User data database exist. It will not be overwritten. Use the --reinstall argument to override."
|
|
|
else
|
|
|
echo "Setting up user tables..."
|
|
|
rm $SCRIPTPATH/data/sw.sqlite
|
|
|
- sqlite3 $SCRIPTPATH/data/sw.sqlite < $SCRIPTPATH/install_data/install_data.sql
|
|
|
+ cp $SCRIPTPATH/installer/data_empty.sqlite $SCRIPTPATH/data/sw.sqlite
|
|
|
fi
|
|
|
|
|
|
+# Ask for admin user and password
|
|
|
+correct=0
|
|
|
+while [ $correct -eq 0 ]
|
|
|
+do
|
|
|
+ read -p "Enter admin username:" $user
|
|
|
+ if [[ $user =~ ^[a-zA-Z0-9]{4, 32}$ ]]
|
|
|
+ then
|
|
|
+ correct=1
|
|
|
+ else
|
|
|
+ echo "Invalid username. Use numbers or letters. Length must be between 4 and 32 characters."
|
|
|
+ fi
|
|
|
+done
|
|
|
+correct=0
|
|
|
+while [ $correct -eq 0]
|
|
|
+do
|
|
|
+ read -p "Enter admin email:" $mail
|
|
|
+ if [[ $mail =~ ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$ ]]
|
|
|
+ then
|
|
|
+ correct=1
|
|
|
+ else
|
|
|
+ echo "Invalid email."
|
|
|
+ fi
|
|
|
+match=0
|
|
|
+while [ $match -eq 0 ]
|
|
|
+do
|
|
|
+ read -s -p "Enter password:" $password
|
|
|
+ read -s -p "Enter password:" $passwordRepeat
|
|
|
+ if [ "$password" = "$passwordRepeat" ]
|
|
|
+ then
|
|
|
+ match=1
|
|
|
+ else
|
|
|
+ echo "Paswords do not match"
|
|
|
+ fi
|
|
|
+done
|
|
|
+hash=$(echo -n $password | sha256sum)
|
|
|
+api=$(head -1 <(fold -w 16 <(tr -dc 'a-zA-Z0-9' < /dev/urandom)))
|
|
|
+
|
|
|
+query="INSERT INTO USER VALUES (0, '$user', '$mail', '$hash', '$api', 1, 0);"
|
|
|
+
|
|
|
echo "All done. You can start the web server by typing ./start_server or edit the config file for the server options"
|