Skip to content

Commit

Permalink
feat!: add advanced configuration to run on first boot (#10)
Browse files Browse the repository at this point in the history
* build(deps): update dependencies to the latest version

configure prettier to trailingComma es5 to keep old behavior

- @commander-js/extra-typings             ~4mo   ^10.0.3  →   ^11.0.0  ~25d
- @inquirer/confirm                       ~2mo   ^1.0.11  →    ^2.0.4   ~9d
- commander                               ~3mo   ^10.0.1  →   ^11.0.0  ~26d
- @typescript-eslint/eslint-plugin  dev   ~2mo   ^5.59.7  →    ^6.0.0   ⩽1d
- @typescript-eslint/parser         dev   ~2mo   ^5.59.7  →    ^6.0.0   ⩽1d
- c8                                dev   ~5mo   ^7.13.0  →    ^8.0.0  ~28d
- prettier                          dev   ~3mo    ^2.8.8  →    ^3.0.0   ~6d
- @inquirer/input                         ~2mo    ^1.1.2  →    ^1.2.3   ~9d
- @inquirer/password                      ~2mo   ^1.0.11  →    ^1.1.3   ~9d
- chalk                                   ~7mo    ^5.2.0  →    ^5.3.0  ~12d
- strip-ansi                             ~1.8y    ^7.0.1  →    ^7.1.0  ~1mo
- @types/node                       dev   ~2mo   ^20.2.3  →   ^20.4.1   ~4d
- esbuild                           dev   ~2mo  ^0.17.19  →  ^0.18.11  ~10d
- eslint                            dev   ~2mo   ^8.41.0  →   ^8.44.0  ~11d
- rollup                            dev   ~2mo   ^3.23.0  →   ^3.26.2   ~5d
- rollup-plugin-node-externals      dev   ~2mo    ^6.0.1  →    ^6.1.1  ~1mo
- typescript                        dev   ~3mo    ^5.0.4  →    ^5.1.6  ~13d
- @rollup/plugin-typescript         dev   ~2mo   ^11.1.1  →   ^11.1.2  ~13d
- tap                               dev   ~6mo   ^16.3.4  →   ^16.3.7  ~19d

* chore: disable rule on no-explicit-any

* feat: export type

* feat: add timezones and timezone validation

* feat: add keyboard layouts

* feat: add prompt for advanced configuration

* style: fix prettier issues

* fix: remove testing code

* feat: add check for SSH key

* feat: add SSH key validation

* fix: shorter message

* feat: add configuration of the advanced settings files

* fix: remove username

* fix: remove unused functions and add comments

* style: fix style issues

* fix: remove hardcoded name and rely on firstrun varialbe

* test: add tests for async_error_to_msg

* feat: add hostname validation

* feat: add advanced command

* fix: move check on cmdline.txt and fix cmdline.txt update if rerunning the script

* fix: update flags and fix copy paste typo

* feat: add bash completion for the advanced command

* test: add test for validation function

* style: fix prettier issues

* fix: disallow disabling ssh password login if ssh key is not provided

* fix: update links

* fix: update instructions and bump version

* fix: README.md

* build(deps): update dependencies

- @inquirer/confirm        ~11d    ^2.0.4  →    ^2.0.5  ⩽1d
- @inquirer/input          ~11d    ^1.2.3  →    ^1.2.4  ⩽1d
- @inquirer/password       ~11d    ^1.1.3  →    ^1.1.4  ⩽1d
- esbuild             dev  ~13d  ^0.18.11  →  ^0.18.12  ⩽1d

rollback @types/node to v18.16.19
  • Loading branch information
matteosacchetto authored Jul 19, 2023
1 parent 40066f8 commit ea7d4e8
Show file tree
Hide file tree
Showing 27 changed files with 2,345 additions and 485 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// Temporary workaaround until they fix the behavior of @rollup typescript (issue #1010)
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/no-non-null-assertion": "off"
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-explicit-any": "off"
},
"plugins": [
"@typescript-eslint"
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"singleQuote": true
"singleQuote": true,
"trailingComma": "es5"
}
63 changes: 60 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ NodeJS CLI which simplifies the headless setup of a Raspberry Pi
Install it locally with

```bash
npm i https://github.com/matteosacchetto/rpi-headless-setup-helper/releases/download/v0.2.2/matteosacchetto-rpi-headless-setup-helper-0.2.2.tgz
npm i https://github.com/matteosacchetto/rpi-headless-setup-helper/releases/download/v0.3.0/matteosacchetto-rpi-headless-setup-helper-0.3.0.tgz
```

Or install it globally with

```bash
npm i --location=global https://github.com/matteosacchetto/rpi-headless-setup-helper/releases/download/v0.2.2/matteosacchetto-rpi-headless-setup-helper-0.2.2.tgz
npm i --location=global https://github.com/matteosacchetto/rpi-headless-setup-helper/releases/download/v0.3.0/matteosacchetto-rpi-headless-setup-helper-0.3.0.tgz
```

### Other version
Expand All @@ -38,7 +38,7 @@ Or install it globally with
npm i --location=global <link-to-rpi-headless-setup-helper-{version}.tgz>
```

where you have to replace `{version}` with the version number you downloaded (ex: 0.2.2)
where you have to replace `{version}` with the version number you downloaded (ex: 0.3.0)

### Bash completion

Expand Down Expand Up @@ -121,6 +121,7 @@ Commands:
ssh [options] create SSH headless setup file
user [options] create user headless setup file
wifi [options] create WiFi headless setup file
advanced [options] create advanced headless setup file
help [command] display help for command
```

Expand Down Expand Up @@ -243,6 +244,62 @@ In case the WiFi specific files for the headless setup already exist, overwrite

This CLI is being used in a script, so disable all interactive prompts. In case the WiFi specific files already exist and the `-y, --yes` option was not used, it will not ask if you want to overwrite the files and simply fail (default: `false`).

#### `advanced`

Allows you to configure additional settings, like SSH keys, disabling password authentication and so on. The way to configure these additional settings is based on the way the [rpi-imager]() tool does it, with some differences related to the configuration of SSH, user and WiFi. If you are interested in knowing more, please refer to [this discussion on how to run a script on first boot](https://github.com/RPi-Distro/raspberrypi-sys-mods/pull/40#issuecomment-849552711) and to [this file of the rpi-imager repo containing the details on how the configure those settings](https://github.com/raspberrypi/rpi-imager/blob/5fa3fbe8dcef4ab01c0a2fed5638759265c3f7f6/src/OptionsPopup.qml)

```
Usage: rpi-headless-setup-helper advanced [options]
create advanced headless setup file
Options:
-v, --version output the version number
-t, --timezone <timezone> set the timezone
-l, --kbd-layout <kbd_layout> set the keyboard layout
-k, --ssh-key <path_to_key> specify the path to the public SSH key
-d, --ssh-password-disable disable password authentication for SSH (default: false)
-h, --hostname <hostname> set the hostname (default: "raspberrypi")
-y, --yes overwrite file if exists (default: false)
-s, --script it will run it as a script and will disable every interactive prompt (default: false)
--help display help for command
```

##### Options

###### `-t, --timezone <timezone>`

Set the timezone by specifying the IANA timezone identifier (ex. `America/New_York`).

This options is `required`

###### `-l, --kbd-layout <kbd_layout>`

Set the specific keyboard layout based on the x11 list (on a Linux machine you can run `localectl list-x11-keymap-layouts` to see the whole list, or refer to [src/utils/keyboard-layouts.ts](src/utils/keyboard-layouts.ts)).

This options is `required`

###### `-k, --ssh-key <path_to_key>`

Specify the path to the public key to copy to the raspberry pi first user.

###### `-d, --ssh-password-disable`

Disable SSH password authentication. This can be done ONLY if you provide a public key with the `-k` option (default: `false`)


###### `-h, --hostname <hostname>`

Set a custom hostname (default: `raspberrypi`)

###### `-y, --yes`

In case the WiFi specific files for the headless setup already exist, overwrite them (default: `false`).

###### `-s, --script`

This CLI is being used in a script, so disable all interactive prompts. In case the WiFi specific files already exist and the `-y, --yes` option was not used, it will not ask if you want to overwrite the files and simply fail (default: `false`).

### Usage

Simply run this CLI without any parameter for the interactive CLI or run it providing the subcommand and all the necessary options.
29 changes: 28 additions & 1 deletion bash-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,39 @@ __rpi-headless-setup-helper_completion() {
;;
esac
;;
advanced)
case $prev in
-t|--timezone)
COMPREPLY=($(compgen -W " Africa/Abidjan Africa/Accra Africa/Addis_Ababa Africa/Algiers Africa/Asmara Africa/Bamako Africa/Bangui Africa/Banjul Africa/Bissau Africa/Blantyre Africa/Brazzaville Africa/Bujumbura Africa/Cairo Africa/Casablanca Africa/Ceuta Africa/Conakry Africa/Dakar Africa/Dar_es_Salaam Africa/Djibouti Africa/Douala Africa/El_Aaiun Africa/Freetown Africa/Gaborone Africa/Harare Africa/Johannesburg Africa/Juba Africa/Kampala Africa/Khartoum Africa/Kigali Africa/Kinshasa Africa/Lagos Africa/Libreville Africa/Lome Africa/Luanda Africa/Lubumbashi Africa/Lusaka Africa/Malabo Africa/Maputo Africa/Maseru Africa/Mbabane Africa/Mogadishu Africa/Monrovia Africa/Nairobi Africa/Ndjamena Africa/Niamey Africa/Nouakchott Africa/Ouagadougou Africa/Porto-Novo Africa/Sao_Tome Africa/Tripoli Africa/Tunis Africa/Windhoek America/Adak America/Anchorage America/Anguilla America/Antigua America/Araguaina America/Argentina/Buenos_Aires America/Argentina/Catamarca America/Argentina/Cordoba America/Argentina/Jujuy America/Argentina/La_Rioja America/Argentina/Mendoza America/Argentina/Rio_Gallegos America/Argentina/Salta America/Argentina/San_Juan America/Argentina/San_Luis America/Argentina/Tucuman America/Argentina/Ushuaia America/Aruba America/Asuncion America/Atikokan America/Bahia America/Bahia_Banderas America/Barbados America/Belem America/Belize America/Blanc-Sablon America/Boa_Vista America/Bogota America/Boise America/Cambridge_Bay America/Campo_Grande America/Cancun America/Caracas America/Cayenne America/Cayman America/Chicago America/Chihuahua America/Costa_Rica America/Creston America/Cuiaba America/Curacao America/Danmarkshavn America/Dawson America/Dawson_Creek America/Denver America/Detroit America/Dominica America/Edmonton America/Eirunepe America/El_Salvador America/Fort_Nelson America/Fortaleza America/Glace_Bay America/Godthab America/Goose_Bay America/Grand_Turk America/Grenada America/Guadeloupe America/Guatemala America/Guayaquil America/Guyana America/Halifax America/Havana America/Hermosillo America/Indiana/Indianapolis America/Indiana/Knox America/Indiana/Marengo America/Indiana/Petersburg America/Indiana/Tell_City America/Indiana/Vevay America/Indiana/Vincennes America/Indiana/Winamac America/Inuvik America/Iqaluit America/Jamaica America/Juneau America/Kentucky/Louisville America/Kentucky/Monticello America/Kralendijk America/La_Paz America/Lima America/Los_Angeles America/Lower_Princes America/Maceio America/Managua America/Manaus America/Marigot America/Martinique America/Matamoros America/Mazatlan America/Menominee America/Merida America/Metlakatla America/Mexico_City America/Miquelon America/Moncton America/Monterrey America/Montevideo America/Montserrat America/Nassau America/New_York America/Nipigon America/Nome America/Noronha America/North_Dakota/Beulah America/North_Dakota/Center America/North_Dakota/New_Salem America/Nuuk America/Ojinaga America/Panama America/Pangnirtung America/Paramaribo America/Phoenix America/Port-au-Prince America/Port_of_Spain America/Porto_Velho America/Puerto_Rico America/Punta_Arenas America/Rainy_River America/Rankin_Inlet America/Recife America/Regina America/Resolute America/Rio_Branco America/Santarem America/Santiago America/Santo_Domingo America/Sao_Paulo America/Scoresbysund America/Sitka America/St_Barthelemy America/St_Johns America/St_Kitts America/St_Lucia America/St_Thomas America/St_Vincent America/Swift_Current America/Tegucigalpa America/Thule America/Thunder_Bay America/Tijuana America/Toronto America/Tortola America/Vancouver America/Whitehorse America/Winnipeg America/Yakutat America/Yellowknife Antarctica/Casey Antarctica/Davis Antarctica/DumontDUrville Antarctica/Macquarie Antarctica/Mawson Antarctica/Palmer Antarctica/Rothera Antarctica/Syowa Antarctica/Troll Antarctica/Vostok Arctic/Longyearbyen Asia/Almaty Asia/Amman Asia/Anadyr Asia/Aqtau Asia/Aqtobe Asia/Ashgabat Asia/Atyrau Asia/Baghdad Asia/Baku Asia/Bangkok Asia/Barnaul Asia/Beirut Asia/Bishkek Asia/Brunei Asia/Chita Asia/Choibalsan Asia/Colombo Asia/Damascus Asia/Dhaka Asia/Dili Asia/Dubai Asia/Dushanbe Asia/Famagusta Asia/Gaza Asia/Hebron Asia/Ho_Chi_Minh Asia/Hong_Kong Asia/Hovd Asia/Irkutsk Asia/Jakarta Asia/Jayapura Asia/Jerusalem Asia/Kabul Asia/Kamchatka Asia/Karachi Asia/Kathmandu Asia/Khandyga Asia/Kolkata Asia/Krasnoyarsk Asia/Kuala_Lumpur Asia/Kuching Asia/Macau Asia/Magadan Asia/Makassar Asia/Manila Asia/Nicosia Asia/Novokuznetsk Asia/Novosibirsk Asia/Omsk Asia/Oral Asia/Phnom_Penh Asia/Pontianak Asia/Pyongyang Asia/Qatar Asia/Qostanay Asia/Qyzylorda Asia/Riyadh Asia/Sakhalin Asia/Samarkand Asia/Seoul Asia/Shanghai Asia/Singapore Asia/Srednekolymsk Asia/Taipei Asia/Tashkent Asia/Tbilisi Asia/Tehran Asia/Thimphu Asia/Tokyo Asia/Tomsk Asia/Ulaanbaatar Asia/Urumqi Asia/Ust-Nera Asia/Vientiane Asia/Vladivostok Asia/Yakutsk Asia/Yangon Asia/Yekaterinburg Asia/Yerevan Atlantic/Azores Atlantic/Bermuda Atlantic/Canary Atlantic/Cape_Verde Atlantic/Faroe Atlantic/Madeira Atlantic/Reykjavik Atlantic/South_Georgia Atlantic/St_Helena Atlantic/Stanley Australia/Adelaide Australia/Brisbane Australia/Broken_Hill Australia/Currie Australia/Darwin Australia/Eucla Australia/Hobart Australia/Lindeman Australia/Lord_Howe Australia/Melbourne Australia/Perth Australia/Sydney Europe/Amsterdam Europe/Andorra Europe/Astrakhan Europe/Athens Europe/Belgrade Europe/Berlin Europe/Bratislava Europe/Brussels Europe/Bucharest Europe/Budapest Europe/Busingen Europe/Chisinau Europe/Copenhagen Europe/Dublin Europe/Gibraltar Europe/Guernsey Europe/Helsinki Europe/Isle_of_Man Europe/Istanbul Europe/Jersey Europe/Kaliningrad Europe/Kiev Europe/Kirov Europe/Lisbon Europe/Ljubljana Europe/London Europe/Luxembourg Europe/Madrid Europe/Malta Europe/Mariehamn Europe/Minsk Europe/Monaco Europe/Moscow Europe/Oslo Europe/Paris Europe/Podgorica Europe/Prague Europe/Riga Europe/Rome Europe/Samara Europe/San_Marino Europe/Sarajevo Europe/Saratov Europe/Simferopol Europe/Skopje Europe/Sofia Europe/Stockholm Europe/Tallinn Europe/Tirane Europe/Ulyanovsk Europe/Uzhgorod Europe/Vaduz Europe/Vatican Europe/Vienna Europe/Vilnius Europe/Volgograd Europe/Warsaw Europe/Zagreb Europe/Zaporozhye Europe/Zurich Indian/Antananarivo Indian/Chagos Indian/Christmas Indian/Cocos Indian/Comoro Indian/Kerguelen Indian/Mahe Indian/Maldives Indian/Mauritius Indian/Mayotte Indian/Reunion Pacific/Apia Pacific/Auckland Pacific/Bougainville Pacific/Chatham Pacific/Chuuk Pacific/Easter Pacific/Efate Pacific/Enderbury Pacific/Fakaofo Pacific/Fiji Pacific/Funafuti Pacific/Galapagos Pacific/Gambier Pacific/Guadalcanal Pacific/Guam Pacific/Honolulu Pacific/Kiritimati Pacific/Kosrae Pacific/Kwajalein Pacific/Majuro Pacific/Marquesas Pacific/Midway Pacific/Nauru Pacific/Niue Pacific/Norfolk Pacific/Noumea Pacific/Pago_Pago Pacific/Palau Pacific/Pitcairn Pacific/Pohnpei Pacific/Port_Moresby Pacific/Rarotonga Pacific/Saipan Pacific/Tahiti Pacific/Tarawa Pacific/Tongatapu Pacific/Wake Pacific/Wallis" -- "$cur"))
return 0;
;;
-l|--kbd-layout)
COMPREPLY=($(compgen -W " af al am usa at au az ba bd be bg br brai bt bw by ca cd ch cm cn custom cz de dk dz ee epo es et fi fo fr gb ge gh gn gr hr hu id ie il in iq ir is it jp jv ke kg kh kr kz la latam lk lt lv ma mao md me mk ml mm mn mt mv my nec_vndr/jp ng nl no np ph pk pl pt ro rs ru se si sk sn sy tg th tj tm tr tw tz ua us uz vn za" -- "$cur"))
return 0;
;;
-k|--ssh-key)
_filedir;
return 0;
;;
-h|--hostname)
COMPREPLY=''
return 0;
;;
esac

case $last_opt in
*)
COMPREPLY=($(compgen -W "-v --version -t --timezone -l --kbd-layout -k --ssh-key -d --ssh-password-disable -h --hostname -y --yes -s --script -h --help" -- "$cur"))
return 0;
;;
esac
;;
help)
COMPREPLY=($(compgen -W "ssh user wifi" -- "$cur"))
return 0;
;;
*)
COMPREPLY=($(compgen -W "-h --help -v --version ssh user wifi help" -- "$cur"))
COMPREPLY=($(compgen -W "-h --help -v --version ssh user wifi advanced help" -- "$cur"))
return 0;
;;
esac
Expand Down
Loading

0 comments on commit ea7d4e8

Please sign in to comment.