diff --git a/scripts/starter.sh b/scripts/starter.sh index 64e613c..e14a726 100755 --- a/scripts/starter.sh +++ b/scripts/starter.sh @@ -273,55 +273,6 @@ if [[ $MAKE_GLOBAL = true ]]; then echo "[+] specification '$SPECIFICATION_NAME.json' copied to '$SPECIFICATION_PATH'" fi -if [ $UNIT_FILE = true ]; then - cd $SCRIPT_FOLDER - read -p "[?] name for the unit file (default: ghost-node.service) " unit_name - if [ -z $unit_name ]; then - unit_name="ghost-node" - fi - unit_name=$(echo "$unit_name" | sed -e "s/.service//g") - unit_name="$unit_name.service" - - user_name="ghost" - if id $user_name > /dev/null 2>&1; then - echo "[+] user ghost found, continue for the user ghost" - else - echo "[!] user ghost not found" - if prompt "[?] do you want to create ghost user? (NOT RECOMMENDED: current $(whoami))"; then - sudo useradd --system --create-home $user_name - else - user_name=$(whoami) - fi - fi - - if [ ! -d $BASE_PATH ]; then - echo "[+] create folder for the node at '$BASE_PATH'" - sudo mkdir $BASE_PATH - fi - - if [ -z "$(stat -c "%U %G" $BASE_PATH | grep $user_name)" ]; then - echo "[+] make $user_name owner of $BASE_PATH" - sudo chown -R "$user_name:" $BASE_PATH - fi - - cp packaging/template.service /tmp/$unit_name - sed -i -e "s/User=ghost/User=$user_name/g" /tmp/$unit_name - sed -i -e "s#/ReadWritePaths=/var/lib/ghost#/ReadWritePaths=$BASE_PATH#g" /tmp/$unit_name - - echo "[+] prepare unit file for the $unit_name" - sudo cp packaging/template.service /etc/systemd/system/$unit_name - echo "[+] reloading systemd because of updated unit file" - sudo systemctl daemon-reload - - if prompt "[?] do you want to start the $unit_name?"; then - sudo systemctl restart $unit_name - fi - - if prompt "[?] do you want to enable the $unit_name?"; then - sudo systemctl enable $unit_name - fi -fi - if [[ $ARGUMENTS = true ]]; then echo "[+] setting-up default CLI arguments" CLI_ARGS=() @@ -412,3 +363,51 @@ if [ $CHECK_KEYS = true ]; then done fi +if [ $UNIT_FILE = true ]; then + cd $SCRIPT_FOLDER + read -p "[?] name for the unit file (default: ghost-node.service) " unit_name + if [ -z $unit_name ]; then + unit_name="ghost-node" + fi + unit_name=$(echo "$unit_name" | sed -e "s/.service//g") + unit_name="$unit_name.service" + + user_name="ghost" + if id $user_name > /dev/null 2>&1; then + echo "[+] user ghost found, continue for the user ghost" + else + echo "[!] user ghost not found" + if prompt "[?] do you want to create ghost user? (NOT RECOMMENDED: current $(whoami))"; then + sudo useradd --system --create-home $user_name + else + user_name=$(whoami) + fi + fi + + if [ ! -d $BASE_PATH ]; then + echo "[+] create folder for the node at '$BASE_PATH'" + sudo mkdir $BASE_PATH + fi + + if [ -z "$(stat -c "%U %G" $BASE_PATH | grep $user_name)" ]; then + echo "[+] make $user_name owner of $BASE_PATH" + sudo chown -R "$user_name:" $BASE_PATH + fi + + cp packaging/template.service /tmp/$unit_name + sed -i -e "s/User=ghost/User=$user_name/g" /tmp/$unit_name + sed -i -e "s#/ReadWritePaths=/var/lib/ghost#/ReadWritePaths=$BASE_PATH#g" /tmp/$unit_name + + echo "[+] prepare unit file for the $unit_name" + sudo cp packaging/template.service /etc/systemd/system/$unit_name + echo "[+] reloading systemd because of updated unit file" + sudo systemctl daemon-reload + + if prompt "[?] do you want to start the $unit_name?"; then + sudo systemctl restart $unit_name + fi + + if prompt "[?] do you want to enable the $unit_name?"; then + sudo systemctl enable $unit_name + fi +fi